mirror of
https://github.com/zulip/zulip.git
synced 2025-11-02 04:53:36 +00:00
storage: Remove AddHeaderMixin.
We should be doing this inside webpack, which would be a lot less hacky. Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
This commit is contained in:
committed by
Tim Abbott
parent
0cd6c75ab1
commit
f47f98e2f1
@@ -8,53 +8,6 @@ from django.conf import settings
|
||||
from django.contrib.staticfiles.storage import ManifestStaticFilesStorage
|
||||
from pipeline.storage import PipelineMixin
|
||||
|
||||
class AddHeaderMixin:
|
||||
def post_process(self, paths: Dict[str, Tuple['ZulipStorage', str]], dry_run: bool=False,
|
||||
**kwargs: Any) -> List[Tuple[str, str, bool]]:
|
||||
if dry_run:
|
||||
return []
|
||||
|
||||
with open(settings.STATIC_HEADER_FILE, 'rb') as header_file:
|
||||
header = header_file.read().decode(settings.FILE_CHARSET)
|
||||
|
||||
# A dictionary of path to tuples of (old_path, new_path,
|
||||
# processed). The return value of this method is the values
|
||||
# of this dictionary
|
||||
ret_dict = {}
|
||||
|
||||
for name in paths:
|
||||
storage, path = paths[name]
|
||||
|
||||
if not path.startswith('min/') or not path.endswith('.css'):
|
||||
ret_dict[path] = (path, path, False)
|
||||
continue
|
||||
|
||||
# Prepend the header
|
||||
with storage.open(path, 'rb') as orig_file:
|
||||
orig_contents = orig_file.read().decode(settings.FILE_CHARSET)
|
||||
|
||||
storage.delete(path)
|
||||
|
||||
with storage.open(path, 'w') as new_file:
|
||||
new_file.write(header + orig_contents)
|
||||
|
||||
ret_dict[path] = (path, path, True)
|
||||
|
||||
super_class = super()
|
||||
if hasattr(super_class, 'post_process'):
|
||||
super_ret = super_class.post_process(paths, dry_run, **kwargs) # type: ignore # https://github.com/python/mypy/issues/2956
|
||||
else:
|
||||
super_ret = []
|
||||
|
||||
# Merge super class's return value with ours
|
||||
for val in super_ret:
|
||||
old_path, new_path, processed = val
|
||||
if processed:
|
||||
ret_dict[old_path] = val
|
||||
|
||||
return list(ret_dict.values())
|
||||
|
||||
|
||||
class RemoveUnminifiedFilesMixin:
|
||||
def post_process(self, paths: Dict[str, Tuple['ZulipStorage', str]], dry_run: bool=False,
|
||||
**kwargs: Any) -> List[Tuple[str, str, bool]]:
|
||||
@@ -122,6 +75,6 @@ if settings.PRODUCTION:
|
||||
ManifestStaticFilesStorage.path = path
|
||||
|
||||
class ZulipStorage(PipelineMixin,
|
||||
AddHeaderMixin, RemoveUnminifiedFilesMixin,
|
||||
RemoveUnminifiedFilesMixin,
|
||||
IgnoreBundlesManifestStaticFilesStorage):
|
||||
pass
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
/** @preserve
|
||||
The software provided in this file is offered under a variety of free and open
|
||||
source licenses. Unless otherwise specified, software is provided under the
|
||||
Apache License, Version 2.0, for which the following text applies:
|
||||
|
||||
Copyright 2011-2016 Dropbox Inc. and contributors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
If some of the software in this file is offered under a different license,
|
||||
information about that license will appear in this file.
|
||||
*/
|
||||
@@ -895,7 +895,6 @@ LOCALE_PATHS = (os.path.join(DEPLOY_ROOT, 'locale'),)
|
||||
FILE_UPLOAD_MAX_MEMORY_SIZE = 0
|
||||
|
||||
STATICFILES_DIRS = ['static/']
|
||||
STATIC_HEADER_FILE = 'zerver/static_header.txt'
|
||||
|
||||
# To use minified files in dev, set PIPELINE_ENABLED = True. For the full
|
||||
# cache-busting behavior, you must also set DEBUG = False.
|
||||
|
||||
Reference in New Issue
Block a user