storage: Move the staticfiles.json hack to ZulipStorage.

There’s no reason to monkey-patch something that we were already
subclassing.

Removing the PRODUCTION conditional causes us to generate
staticfiles.json in the right place to begin with so we don’t need to
move it later.  It also allows Django to find staticfiles.json if
running the dev server with PIPELINE_ENABLED.

Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
This commit is contained in:
Anders Kaseorg 2019-07-18 01:08:09 -07:00 committed by Tim Abbott
parent 695b79c5d8
commit a7eb3faf96
2 changed files with 6 additions and 17 deletions

View File

@ -5,7 +5,6 @@
import os import os
import argparse import argparse
import shutil
import sys import sys
# We need settings so we can figure out where the prod-static directory is. # We need settings so we can figure out where the prod-static directory is.
@ -65,10 +64,6 @@ run(['./manage.py', 'collectstatic', '--no-default-ignore',
'--noinput', '-i', 'assets', '-i', 'js', '-i', 'styles', '-i', 'templates'], '--noinput', '-i', 'assets', '-i', 'js', '-i', 'styles', '-i', 'templates'],
stdout=fp, stderr=fp) stdout=fp, stderr=fp)
if not settings.PRODUCTION:
# When building a release tarball, we need to move staticfiles.json
shutil.move('prod-static/serve/staticfiles.json', 'staticfiles.json')
# Compile translation strings to generate `.mo` files. # Compile translation strings to generate `.mo` files.
run(['./manage.py', 'compilemessages'], stdout=fp, stderr=fp) run(['./manage.py', 'compilemessages'], stdout=fp, stderr=fp)

View File

@ -35,22 +35,16 @@ class IgnoreBundlesManifestStaticFilesStorage(ManifestStaticFilesStorage):
return name return name
return super().hashed_name(name, content, filename) return super().hashed_name(name, content, filename)
if settings.PRODUCTION: class ZulipStorage(PipelineMixin,
IgnoreBundlesManifestStaticFilesStorage):
# This is a hack to use staticfiles.json from within the # This is a hack to use staticfiles.json from within the
# deployment, rather than a directory under STATIC_ROOT. By doing # deployment, rather than a directory under STATIC_ROOT. By doing
# so, we can use a different copy of staticfiles.json for each # so, we can use a different copy of staticfiles.json for each
# deployment, which ensures that we always use the correct static # deployment, which ensures that we always use the correct static
# assets for each deployment. # assets for each deployment.
ManifestStaticFilesStorage.manifest_name = os.path.join(settings.DEPLOY_ROOT, manifest_name = os.path.join(settings.DEPLOY_ROOT, "staticfiles.json")
"staticfiles.json")
orig_path = ManifestStaticFilesStorage.path
def path(self: ManifestStaticFilesStorage, name: str) -> str: def path(self, name: str) -> str:
if name == ManifestStaticFilesStorage.manifest_name: if name == self.manifest_name:
return name return name
return orig_path(self, name) return super().path(name)
ManifestStaticFilesStorage.path = path
class ZulipStorage(PipelineMixin,
IgnoreBundlesManifestStaticFilesStorage):
pass