Merge pull request #3804 from normanjaeckel/ChangeCollectStatic

Fixed collectstattic command so that it does not write into openslide…
This commit is contained in:
Emanuel Schütze 2018-08-23 17:38:26 +02:00 committed by GitHub
commit 96637e18c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 15 deletions

View File

@ -23,14 +23,15 @@ Motions:
- New table of contents with page numbers and categories in PDF [#3766]. - New table of contents with page numbers and categories in PDF [#3766].
- New teporal field "modified final version" where the final version can - New teporal field "modified final version" where the final version can
be edited [#3781]. be edited [#3781].
- New config to show amendments also in motions table [#3792] - New config to show amendments also in motions table [#3792].
- Support to change decimal places for polls with a plugin [#3803] - Support to change decimal places for polls with a plugin [#3803].
Core: Core:
- Python 3.4 is not supported anymore [#3777]. - Python 3.4 is not supported anymore [#3777].
- Support Python 3.7 [#3786]. - Support Python 3.7 [#3786].
- Updated pdfMake to 0.1.37 [#3766]. - Updated pdfMake to 0.1.37 [#3766].
- Updated Django to 2.1 [#3777, #3786]. - Updated Django to 2.1 [#3777, #3786].
- Changed behavior of collectstatic management command [#3804].
Version 2.2 (2018-06-06) Version 2.2 (2018-06-06)

View File

@ -4,6 +4,7 @@ from typing import Any, Dict
from django.conf import settings from django.conf import settings
from django.contrib.staticfiles.management.commands.collectstatic import \ from django.contrib.staticfiles.management.commands.collectstatic import \
Command as CollectStatic Command as CollectStatic
from django.contrib.staticfiles.utils import matches_patterns
from django.core.management.base import CommandError from django.core.management.base import CommandError
from django.db.utils import OperationalError from django.db.utils import OperationalError
@ -18,6 +19,8 @@ class Command(CollectStatic):
js_filename = 'webclient-{}.js' js_filename = 'webclient-{}.js'
def handle(self, **options: Any) -> str: def handle(self, **options: Any) -> str:
if options['link']:
raise CommandError("Option 'link' is not supported.")
try: try:
self.view = WebclientJavaScriptView() self.view = WebclientJavaScriptView()
except OperationalError: except OperationalError:
@ -26,24 +29,37 @@ class Command(CollectStatic):
return super().handle(**options) return super().handle(**options)
def collect(self) -> Dict[str, Any]: def collect(self) -> Dict[str, Any]:
result = super().collect()
try: try:
destination_dir = os.path.join(settings.STATICFILES_DIRS[0], 'js') destination_dir = os.path.join(settings.STATIC_ROOT, 'js')
except IndexError: except IndexError:
# If the user does not want do have staticfiles, he should not get # If the user does not want do have staticfiles, he should not get
# the webclient files either. # the webclient files either.
pass pass
else: else:
if not os.path.exists(destination_dir): if self.dry_run:
os.makedirs(destination_dir) 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: for realm in self.realms:
filename = self.js_filename.format(realm) filename = self.js_filename.format(realm)
content = self.view.get(realm=realm).content # Matches only the basename.
path = os.path.join(destination_dir, filename) if matches_patterns(filename, self.ignore_patterns):
with open(path, 'wb+') as f: continue
f.write(content) path = os.path.join(destination_dir, filename)
self.stdout.write("Written WebclientJavaScriptView for realm {} to '{}'".format( if matches_patterns(path, self.ignore_patterns):
realm, continue
path))
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