Fixed collectstattic command so that it does not write into openslides app dir.

This commit is contained in:
Norman Jäckel 2018-08-22 21:33:33 +02:00
parent 123b7c702b
commit 3578d0e850
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 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)

View File

@ -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