Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
template_loaders: Extract TwoFactorLoader to new module.
Anders Kaseorg9eefc290a9e3
diff --git a/zproject/computed_settings.py b/zproject/computed_settings.pyindex ba38228e3f0..b11926ff2ac 100644--- a/zproject/computed_settings.py+++ b/zproject/computed_settings.py@@ -2,12 +2,9 @@ import osimport sysimport timefrom copy import deepcopy-from pathlib import Pathfrom typing import Any, Dict, List, Tuple, Unionfrom urllib.parse import urljoin-from django.template.loaders import app_directories-import zerver.lib.logging_utilfrom scripts.lib.zulip_tools import get_tornado_portsfrom zerver.lib.db import TimeTrackingConnection, TimeTrackingCursor@@ -161,20 +158,6 @@ ALLOWED_HOSTS += [EXTERNAL_HOST_WITHOUT_PORT, "." + EXTERNAL_HOST_WITHOUT_PORT]# ... and with the hosts in REALM_HOSTS.ALLOWED_HOSTS += REALM_HOSTS.values()--class TwoFactorLoader(app_directories.Loader):- def get_dirs(self) -> List[Union[str, Path]]:- dirs = super().get_dirs()- # app_directories.Loader returns only a list of- # Path objects by calling get_app_template_dirs- two_factor_dirs: List[Union[str, Path]] = []- for d in dirs:- assert isinstance(d, Path)- if d.match("two_factor/*"):- two_factor_dirs.append(d)- return two_factor_dirs--MIDDLEWARE = ("zerver.middleware.TagRequests","zerver.middleware.SetRemoteAddrFromRealIpHeader",@@ -675,7 +658,7 @@ non_html_template_engine_settings["OPTIONS"].update(two_factor_template_options = deepcopy(default_template_engine_settings["OPTIONS"])del two_factor_template_options["environment"]del two_factor_template_options["extensions"]-two_factor_template_options["loaders"] = ["zproject.settings.TwoFactorLoader"]+two_factor_template_options["loaders"] = ["zproject.template_loaders.TwoFactorLoader"]two_factor_template_engine_settings = {"NAME": "Two_Factor",diff --git a/zproject/template_loaders.py b/zproject/template_loaders.pynew file mode 100644index 00000000000..f67ae0a05ff--- /dev/null+++ b/zproject/template_loaders.py@@ -0,0 +1,17 @@+from pathlib import Path+from typing import List, Union++from django.template.loaders import app_directories+++class TwoFactorLoader(app_directories.Loader):+ def get_dirs(self) -> List[Union[str, Path]]:+ dirs = super().get_dirs()+ # app_directories.Loader returns only a list of+ # Path objects by calling get_app_template_dirs+ two_factor_dirs: List[Union[str, Path]] = []+ for d in dirs:+ assert isinstance(d, Path)+ if d.match("two_factor/*"):+ two_factor_dirs.append(d)+ return two_factor_dirs