From bd3d937a82c55525b5047746162c14dc2c9535a5 Mon Sep 17 00:00:00 2001 From: serversdown Date: Wed, 25 Feb 2026 21:41:51 +0000 Subject: [PATCH] feat: enhance project data handling with new Jinja filters and update UI labels for clarity --- backend/routers/projects.py | 13 +++++--- backend/templates_config.py | 31 +++++++++++++++++++ .../partials/projects/unified_files.html | 20 ++++++++++-- templates/projects/detail.html | 6 ++-- 4 files changed, 59 insertions(+), 11 deletions(-) diff --git a/backend/routers/projects.py b/backend/routers/projects.py index 576d867..87fecfe 100644 --- a/backend/routers/projects.py +++ b/backend/routers/projects.py @@ -2851,17 +2851,20 @@ async def upload_all_project_data( Determine the grouping key for a file path. Files inside Auto_####/Auto_Leq/ or Auto_####/Auto_Lp_01/ are collapsed up to their Auto_#### parent so they all land in the same session. + Only folder components are examined (not the filename, which is parts[-1]). """ - # Find the deepest Auto_#### component (case-insensitive) + # Only look at folder components — exclude the filename (last part) + folder_parts = parts[:-1] auto_idx = None - for i, p in enumerate(parts): - if p.lower().startswith("auto_") and not p.lower().startswith("auto_leq") and not p.lower().startswith("auto_lp"): + for i, p in enumerate(folder_parts): + p_lower = p.lower() + if p_lower.startswith("auto_") and not p_lower.startswith("auto_leq") and not p_lower.startswith("auto_lp"): auto_idx = i if auto_idx is not None: # Group key = everything up to and including Auto_#### - return "/".join(parts[:auto_idx + 1]) + return "/".join(folder_parts[:auto_idx + 1]) # Fallback: use the immediate parent folder - return "/".join(parts[:-1]) if len(parts) > 1 else "" + return "/".join(folder_parts) if folder_parts else "" # --- Group files by session key --- groups: dict[str, list[tuple[str, bytes]]] = defaultdict(list) diff --git a/backend/templates_config.py b/backend/templates_config.py index c0e4212..453b284 100644 --- a/backend/templates_config.py +++ b/backend/templates_config.py @@ -5,6 +5,7 @@ All routers should import `templates` from this module to get consistent filter and global function registration. """ +import json as _json from fastapi.templating import Jinja2Templates # Import timezone utilities @@ -32,8 +33,38 @@ def jinja_timezone_abbr(): # Create templates instance templates = Jinja2Templates(directory="templates") +def jinja_local_date(dt, fmt="%m-%d-%y"): + """Jinja filter: format a UTC datetime as a local date string (e.g. 02-19-26).""" + return format_local_datetime(dt, fmt) + + +def jinja_fromjson(s): + """Jinja filter: parse a JSON string into a dict (returns {} on failure).""" + if not s: + return {} + try: + return _json.loads(s) + except Exception: + return {} + + +def jinja_same_date(dt1, dt2) -> bool: + """Jinja global: True if two datetimes fall on the same local date.""" + if not dt1 or not dt2: + return False + try: + d1 = format_local_datetime(dt1, "%Y-%m-%d") + d2 = format_local_datetime(dt2, "%Y-%m-%d") + return d1 == d2 + except Exception: + return False + + # Register Jinja filters and globals templates.env.filters["local_datetime"] = jinja_local_datetime templates.env.filters["local_time"] = jinja_local_time +templates.env.filters["local_date"] = jinja_local_date +templates.env.filters["fromjson"] = jinja_fromjson templates.env.globals["timezone_abbr"] = jinja_timezone_abbr templates.env.globals["get_user_timezone"] = get_user_timezone +templates.env.globals["same_date"] = jinja_same_date diff --git a/templates/partials/projects/unified_files.html b/templates/partials/projects/unified_files.html index 2d56854..118c217 100644 --- a/templates/partials/projects/unified_files.html +++ b/templates/partials/projects/unified_files.html @@ -23,12 +23,26 @@
+ {% set meta = session.session_metadata|fromjson if session.session_metadata else {} %} + {% set is_manual = meta.get('source') in ('manual_upload', 'bulk_upload') %}
- {{ session.started_at|local_datetime if session.started_at else 'Unknown Date' }} + {% if location %}{{ location.name }}{% else %}Unknown Location{% endif %} + {% if session.started_at %} + — + {% if session.stopped_at and not same_date(session.started_at, session.stopped_at) %} + {{ session.started_at|local_date }} to {{ session.stopped_at|local_date }} + {% else %} + {{ session.started_at|local_date }} + {% endif %} + {% endif %}
- {% if unit %}{{ unit.id }}{% else %}Unknown Unit{% endif %} - {% if location %} @ {{ location.name }}{% endif %} + {% if is_manual %} + {% set store = meta.get('store_name') %} + Manual upload{% if store %} — Store {{ store }}{% endif %} + {% elif unit %} + {{ unit.id }} + {% endif %} {{ files|length }} file{{ 's' if files|length != 1 else '' }}
diff --git a/templates/projects/detail.html b/templates/projects/detail.html index 49fe689..7c579d4 100644 --- a/templates/projects/detail.html +++ b/templates/projects/detail.html @@ -235,7 +235,7 @@ - Upload All + Upload Days
- +