Merge pull request #3566 from FinnStutzenstein/noCachingFlag

Added --no-template-caching
This commit is contained in:
Emanuel Schütze 2018-03-06 10:01:36 +01:00 committed by GitHub
commit d073cbbf6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 39 additions and 2 deletions

View File

@ -118,6 +118,9 @@ Core:
- Removed unnecessary OPTIONS request in config [#3541]. - Removed unnecessary OPTIONS request in config [#3541].
- Added possibility to upload custom fonts for projector and pdf [#3568]. - Added possibility to upload custom fonts for projector and pdf [#3568].
- Use custom format cleanup plugin for CKEditor [#3576]. - Use custom format cleanup plugin for CKEditor [#3576].
- Added --debug-email flag to print all emails to stdout [#3530].
- Added --no-template-caching flag to disable template caching for
easier development [#3566].
Mediafiles: Mediafiles:
- Fixed reloading of PDF on page change [#3274]. - Fixed reloading of PDF on page change [#3274].

View File

@ -9,6 +9,7 @@ import django
from django.core.management import call_command, execute_from_command_line from django.core.management import call_command, execute_from_command_line
import openslides import openslides
from openslides.utils.arguments import arguments
from openslides.utils.main import ( from openslides.utils.main import (
ExceptionArgumentParser, ExceptionArgumentParser,
UnknownCommand, UnknownCommand,
@ -45,7 +46,7 @@ def main():
parser.error('Unknown arguments {}'.format(' '.join(unknown_args))) parser.error('Unknown arguments {}'.format(' '.join(unknown_args)))
# Save arguments, if one wants to access them later. # Save arguments, if one wants to access them later.
openslides.args = known_args arguments.set_arguments(known_args)
# Run a command that is defined here # Run a command that is defined here
# These are commands that can not rely on an existing settings # These are commands that can not rely on an existing settings
@ -115,6 +116,11 @@ def get_parser():
'--debug-email', '--debug-email',
action='store_true', action='store_true',
help='Change the email backend to console output.') help='Change the email backend to console output.')
subcommand_start.add_argument(
'--no-template-caching',
action='store_true',
default=False,
help='Disables caching of templates.')
subcommand_start.add_argument( subcommand_start.add_argument(
'--host', '--host',
action='store', action='store',

View File

@ -0,0 +1,25 @@
from argparse import Namespace
from typing import Any, Union # noqa
class OpenSlidesArguments():
args = None # type: Union[None, Namespace]
def __getitem__(self, key: str) -> Any:
if not self.args:
raise KeyError("Arguments are not set.")
if not hasattr(self.args, key):
raise KeyError("Key '{}' is not in the OpenSlides arguments.".format(key))
return getattr(self.args, key)
def get(self, key: str, default: Any) -> Any:
if not self.args or not hasattr(self.args, key):
return default
else:
return getattr(self.args, key)
def set_arguments(self, args: Namespace) -> None:
self.args = args
arguments = OpenSlidesArguments()

View File

@ -9,6 +9,8 @@ from django.views.generic.base import View
from rest_framework.response import Response from rest_framework.response import Response
from rest_framework.views import APIView as _APIView from rest_framework.views import APIView as _APIView
from .arguments import arguments
class CSRFMixin: class CSRFMixin:
""" """
@ -67,7 +69,8 @@ class TemplateView(View):
if self.template_name is None: if self.template_name is None:
raise ImproperlyConfigured("'template_name' is not provided.") raise ImproperlyConfigured("'template_name' is not provided.")
if self.template_name not in self.state: no_caching = arguments.get('no_template_caching', False)
if self.template_name not in self.state or no_caching:
self.state[self.template_name] = self.load_template() self.state[self.template_name] = self.load_template()
def load_template(self) -> str: def load_template(self) -> str: