Update web/core/context_processors.py
This commit is contained in:
parent
23d48f87bb
commit
66881bd6e3
@ -4,9 +4,6 @@ from .models_ann import Announcement, AnnouncementDismissal
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
def app_version(request):
|
def app_version(request):
|
||||||
"""
|
|
||||||
Expose APP_VERSION (read from <project>/version.txt). Used in base.html.
|
|
||||||
"""
|
|
||||||
version_file = Path(__file__).resolve().parent.parent / "version.txt"
|
version_file = Path(__file__).resolve().parent.parent / "version.txt"
|
||||||
try:
|
try:
|
||||||
return {"APP_VERSION": version_file.read_text(encoding="utf-8").strip()}
|
return {"APP_VERSION": version_file.read_text(encoding="utf-8").strip()}
|
||||||
@ -15,49 +12,33 @@ def app_version(request):
|
|||||||
|
|
||||||
def available_themes(request):
|
def available_themes(request):
|
||||||
"""
|
"""
|
||||||
Return clean theme names by scanning /static/themes/*.css.
|
Return clean theme names by scanning ONLY /static/themes/*.css.
|
||||||
Handles both 'themes/foo.css' and '/.../themes/foo.css' paths and
|
Ignore admin css and fingerprinted variants.
|
||||||
collapses fingerprinted files (e.g., 'midnight.400a2f.css' -> 'midnight').
|
|
||||||
"""
|
"""
|
||||||
bases = set()
|
bases = set()
|
||||||
|
|
||||||
# Try listing the 'themes' directory directly.
|
|
||||||
for finder in finders.get_finders():
|
for finder in finders.get_finders():
|
||||||
try:
|
try:
|
||||||
for path, storage in finder.list(['themes']):
|
for path, storage in finder.list(['themes']): # only look under themes/
|
||||||
if path.endswith('.css'):
|
if not path.startswith('themes/'):
|
||||||
filename = os.path.basename(path)[:-4] # drop .css
|
continue
|
||||||
base = filename.split('.', 1)[0] # drop fingerprint
|
if not path.endswith('.css'):
|
||||||
if base:
|
continue
|
||||||
bases.add(base)
|
filename = os.path.basename(path)[:-4] # drop .css
|
||||||
|
base = filename.split('.', 1)[0] # drop fingerprint
|
||||||
|
if base:
|
||||||
|
bases.add(base)
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Fallback: scan all and filter anything under themes/
|
|
||||||
try:
|
|
||||||
for path, storage in finder.list([]):
|
|
||||||
if path.endswith('.css') and ('/themes/' in path or path.startswith('themes/')):
|
|
||||||
filename = os.path.basename(path)[:-4]
|
|
||||||
base = filename.split('.', 1)[0]
|
|
||||||
if base:
|
|
||||||
bases.add(base)
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
# If nothing found, fall back to common names that actually exist.
|
|
||||||
if not bases:
|
|
||||||
for name in ["classic", "dawn", "forest", "midnight", "mint", "sandstone", "original"]:
|
|
||||||
if finders.find(f"themes/{name}.css"):
|
|
||||||
bases.add(name)
|
|
||||||
|
|
||||||
preferred = ["classic", "dawn", "forest", "midnight", "mint", "sandstone", "original"]
|
preferred = ["classic", "dawn", "forest", "midnight", "mint", "sandstone", "original"]
|
||||||
names = sorted(bases, key=lambda n: (preferred.index(n) if n in preferred else len(preferred) + 1, n))
|
names = sorted(
|
||||||
|
bases,
|
||||||
|
key=lambda n: (preferred.index(n) if n in preferred else len(preferred) + 1, n)
|
||||||
|
)
|
||||||
return {"available_themes": names}
|
return {"available_themes": names}
|
||||||
|
|
||||||
def pending_announcement(request):
|
def pending_announcement(request):
|
||||||
"""
|
|
||||||
Latest active announcement the user has not dismissed (for Search page).
|
|
||||||
"""
|
|
||||||
user = getattr(request, "user", None)
|
user = getattr(request, "user", None)
|
||||||
if not (user and user.is_authenticated):
|
if not (user and user.is_authenticated):
|
||||||
return {"pending_announcement": None}
|
return {"pending_announcement": None}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user