mirror of https://github.com/zulip/zulip.git
template_loaders: Extract TwoFactorLoader to new module.
This breaks an import cycle that prevented django-stubs from inferring types for django.conf.settings. Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
02be415122
commit
9eefc290a9
|
@ -2,12 +2,9 @@ import os
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
from pathlib import Path
|
|
||||||
from typing import Any, Dict, List, Tuple, Union
|
from typing import Any, Dict, List, Tuple, Union
|
||||||
from urllib.parse import urljoin
|
from urllib.parse import urljoin
|
||||||
|
|
||||||
from django.template.loaders import app_directories
|
|
||||||
|
|
||||||
import zerver.lib.logging_util
|
import zerver.lib.logging_util
|
||||||
from scripts.lib.zulip_tools import get_tornado_ports
|
from scripts.lib.zulip_tools import get_tornado_ports
|
||||||
from zerver.lib.db import TimeTrackingConnection, TimeTrackingCursor
|
from 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.
|
# ... and with the hosts in REALM_HOSTS.
|
||||||
ALLOWED_HOSTS += REALM_HOSTS.values()
|
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 = (
|
MIDDLEWARE = (
|
||||||
"zerver.middleware.TagRequests",
|
"zerver.middleware.TagRequests",
|
||||||
"zerver.middleware.SetRemoteAddrFromRealIpHeader",
|
"zerver.middleware.SetRemoteAddrFromRealIpHeader",
|
||||||
|
@ -675,7 +658,7 @@ non_html_template_engine_settings["OPTIONS"].update(
|
||||||
two_factor_template_options = deepcopy(default_template_engine_settings["OPTIONS"])
|
two_factor_template_options = deepcopy(default_template_engine_settings["OPTIONS"])
|
||||||
del two_factor_template_options["environment"]
|
del two_factor_template_options["environment"]
|
||||||
del two_factor_template_options["extensions"]
|
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 = {
|
two_factor_template_engine_settings = {
|
||||||
"NAME": "Two_Factor",
|
"NAME": "Two_Factor",
|
||||||
|
|
|
@ -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
|
Loading…
Reference in New Issue