diff --git a/CHANGELOG b/CHANGELOG index 631e21553..e9e28f1c5 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -118,6 +118,9 @@ Core: - Removed unnecessary OPTIONS request in config [#3541]. - Added possibility to upload custom fonts for projector and pdf [#3568]. - 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: - Fixed reloading of PDF on page change [#3274]. diff --git a/openslides/__main__.py b/openslides/__main__.py index cf65e8480..d162cebb2 100644 --- a/openslides/__main__.py +++ b/openslides/__main__.py @@ -9,6 +9,7 @@ import django from django.core.management import call_command, execute_from_command_line import openslides +from openslides.utils.arguments import arguments from openslides.utils.main import ( ExceptionArgumentParser, UnknownCommand, @@ -45,7 +46,7 @@ def main(): parser.error('Unknown arguments {}'.format(' '.join(unknown_args))) # 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 # These are commands that can not rely on an existing settings @@ -115,6 +116,11 @@ def get_parser(): '--debug-email', action='store_true', 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( '--host', action='store', diff --git a/openslides/utils/arguments.py b/openslides/utils/arguments.py new file mode 100644 index 000000000..cfd0d99f3 --- /dev/null +++ b/openslides/utils/arguments.py @@ -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() diff --git a/openslides/utils/views.py b/openslides/utils/views.py index 6da9b231b..932162202 100644 --- a/openslides/utils/views.py +++ b/openslides/utils/views.py @@ -9,6 +9,8 @@ from django.views.generic.base import View from rest_framework.response import Response from rest_framework.views import APIView as _APIView +from .arguments import arguments + class CSRFMixin: """ @@ -67,7 +69,8 @@ class TemplateView(View): if self.template_name is None: 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() def load_template(self) -> str: