From 3578d0e850ce77cdf00b6aa1440008fa5463a980 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Norman=20J=C3=A4ckel?= Date: Wed, 22 Aug 2018 21:33:33 +0200 Subject: [PATCH] Fixed collectstattic command so that it does not write into openslides app dir. --- CHANGELOG.rst | 5 ++- .../core/management/commands/collectstatic.py | 42 +++++++++++++------ 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 2819b99be..4a39b771c 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -23,14 +23,15 @@ Motions: - New table of contents with page numbers and categories in PDF [#3766]. - New teporal field "modified final version" where the final version can be edited [#3781]. - - New config to show amendments also in motions table [#3792] - - Support to change decimal places for polls with a plugin [#3803] + - New config to show amendments also in motions table [#3792]. + - Support to change decimal places for polls with a plugin [#3803]. Core: - Python 3.4 is not supported anymore [#3777]. - Support Python 3.7 [#3786]. - Updated pdfMake to 0.1.37 [#3766]. - Updated Django to 2.1 [#3777, #3786]. + - Changed behavior of collectstatic management command [#3804]. Version 2.2 (2018-06-06) diff --git a/openslides/core/management/commands/collectstatic.py b/openslides/core/management/commands/collectstatic.py index 314dfd204..330cc28fc 100644 --- a/openslides/core/management/commands/collectstatic.py +++ b/openslides/core/management/commands/collectstatic.py @@ -4,6 +4,7 @@ from typing import Any, Dict from django.conf import settings from django.contrib.staticfiles.management.commands.collectstatic import \ Command as CollectStatic +from django.contrib.staticfiles.utils import matches_patterns from django.core.management.base import CommandError from django.db.utils import OperationalError @@ -18,6 +19,8 @@ class Command(CollectStatic): js_filename = 'webclient-{}.js' def handle(self, **options: Any) -> str: + if options['link']: + raise CommandError("Option 'link' is not supported.") try: self.view = WebclientJavaScriptView() except OperationalError: @@ -26,24 +29,37 @@ class Command(CollectStatic): return super().handle(**options) def collect(self) -> Dict[str, Any]: + result = super().collect() + try: - destination_dir = os.path.join(settings.STATICFILES_DIRS[0], 'js') + destination_dir = os.path.join(settings.STATIC_ROOT, 'js') except IndexError: # If the user does not want do have staticfiles, he should not get # the webclient files either. pass else: - if not os.path.exists(destination_dir): - os.makedirs(destination_dir) + if self.dry_run: + self.log('Pretending to write WebclientJavaScriptView for all realms.', level=1) + else: + if not os.path.exists(destination_dir): + os.makedirs(destination_dir) - for realm in self.realms: - filename = self.js_filename.format(realm) - content = self.view.get(realm=realm).content - path = os.path.join(destination_dir, filename) - with open(path, 'wb+') as f: - f.write(content) - self.stdout.write("Written WebclientJavaScriptView for realm {} to '{}'".format( - realm, - path)) + for realm in self.realms: + filename = self.js_filename.format(realm) + # Matches only the basename. + if matches_patterns(filename, self.ignore_patterns): + continue + path = os.path.join(destination_dir, filename) + if matches_patterns(path, self.ignore_patterns): + continue - return super().collect() + content = self.view.get(realm=realm).content + with open(path, 'wb+') as f: + f.write(content) + message = "Written WebclientJavaScriptView for realm {} to '{}'".format( + realm, + path) + self.log(message, level=1) + result['modified'].append(path) + + return result