From 0334be7053c09d002d0060661134245605cd2859 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Fri, 28 Jun 2019 21:45:21 -0700 Subject: [PATCH] zproject: Remove unused template tags minified_js, static. `minified_js` was obsoleted by the Webpack migration and `static` has never been used. Signed-off-by: Anders Kaseorg --- docs/overview/directory-structure.md | 5 ----- zerver/templatetags/minified_js.py | 29 ---------------------------- zproject/jinja2/__init__.py | 4 ---- zproject/jinja2/compressors.py | 16 --------------- 4 files changed, 54 deletions(-) delete mode 100644 zerver/templatetags/minified_js.py delete mode 100644 zproject/jinja2/compressors.py diff --git a/docs/overview/directory-structure.md b/docs/overview/directory-structure.md index 58780551c8..368e4035ff 100644 --- a/docs/overview/directory-structure.md +++ b/docs/overview/directory-structure.md @@ -160,11 +160,6 @@ This is used to deploy essentially all configuration in production. * `zproject/jinja2/__init__.py` Jinja2 environment. -* `zproject/jinja2/backends.py` Jinja2 backend. - -* `zproject/jinja2/compressors.py` Jinja2 compatible functions of - Django-Pipeline. - ----------------------------------------------------------------------- ### Translation files diff --git a/zerver/templatetags/minified_js.py b/zerver/templatetags/minified_js.py deleted file mode 100644 index b1b6667480..0000000000 --- a/zerver/templatetags/minified_js.py +++ /dev/null @@ -1,29 +0,0 @@ -from typing import Any, Dict - -from django.conf import settings -from django.contrib.staticfiles.storage import staticfiles_storage -from django.template import Library, Node - - -register = Library() - -class MinifiedJSNode(Node): - def __init__(self, sourcefile: str, csp_nonce: str) -> None: - self.sourcefile = sourcefile - self.csp_nonce = csp_nonce - - def render(self, context: Dict[str, Any]) -> str: - if settings.DEBUG: - source_files = settings.JS_SPECS[self.sourcefile] - normal_source = source_files['source_filenames'] - minified_source = source_files.get('minifed_source_filenames', []) - - # Minified source files (most likely libraries) should be loaded - # first to prevent any dependency errors. - scripts = minified_source + normal_source - else: - scripts = [settings.JS_SPECS[self.sourcefile]['output_filename']] - script_urls = [staticfiles_storage.url(script) for script in scripts] - script_tags = ['' % (self.csp_nonce, url) - for url in script_urls] - return '\n'.join(script_tags) diff --git a/zproject/jinja2/__init__.py b/zproject/jinja2/__init__.py index d84563a2c8..daba12f1e1 100644 --- a/zproject/jinja2/__init__.py +++ b/zproject/jinja2/__init__.py @@ -1,7 +1,6 @@ from typing import Any -from django.contrib.staticfiles.storage import staticfiles_storage from django.template.defaultfilters import slugify, pluralize from django.urls import reverse from django.utils import translation @@ -9,17 +8,14 @@ from django.utils.timesince import timesince from jinja2 import Environment from two_factor.templatetags.two_factor import device_action -from .compressors import minified_js from zerver.templatetags.app_filters import display_list, render_markdown_path def environment(**options: Any) -> Environment: env = Environment(**options) env.globals.update({ - 'static': staticfiles_storage.url, 'url': reverse, 'render_markdown_path': render_markdown_path, - 'minified_js': minified_js, }) env.install_gettext_translations(translation, True) diff --git a/zproject/jinja2/compressors.py b/zproject/jinja2/compressors.py deleted file mode 100644 index 70fb368820..0000000000 --- a/zproject/jinja2/compressors.py +++ /dev/null @@ -1,16 +0,0 @@ -""" -`minified_js` is taken from `zerver.templatetags.minified_js.py` -""" - -from django.conf import settings -from django.template import TemplateSyntaxError - -from zerver.templatetags.minified_js import MinifiedJSNode - - -def minified_js(sourcefile: str, csp_nonce: str) -> str: - if sourcefile not in settings.JS_SPECS: - raise TemplateSyntaxError( - "Invalid argument: no JS file %s".format(sourcefile)) - - return MinifiedJSNode(sourcefile, csp_nonce).render({})