From cf2e2ba1db3011f686de7b8f11dfaa7d928c0d1e Mon Sep 17 00:00:00 2001 From: giles Date: Tue, 24 Feb 2026 17:28:09 +0000 Subject: [PATCH] Remove cross-domain template dependencies from shared infrastructure - macros/search.html: shared search input macros (mobile + desktop) - macros/cart_icon.html: shared cart icon/badge macro (count param, no DB) - macros/layout.html: inline hamburger icon, use shared search macro - _oob.html: use cart_mini_html fragment slot instead of cart template import - db/session.py: guard teardown rollback against committed/dead sessions Co-Authored-By: Claude Opus 4.6 --- .../templates/_types/root/header/_oob.html | 7 +- browser/templates/macros/cart_icon.html | 31 +++++++ browser/templates/macros/layout.html | 16 +++- browser/templates/macros/search.html | 83 +++++++++++++++++++ db/session.py | 12 ++- 5 files changed, 140 insertions(+), 9 deletions(-) create mode 100644 browser/templates/macros/cart_icon.html create mode 100644 browser/templates/macros/search.html diff --git a/browser/templates/_types/root/header/_oob.html b/browser/templates/_types/root/header/_oob.html index d0e50b2..45b7240 100644 --- a/browser/templates/_types/root/header/_oob.html +++ b/browser/templates/_types/root/header/_oob.html @@ -23,9 +23,10 @@ {% endif %}
- {# Cart mini #} - {% from '_types/cart/_mini.html' import mini with context %} - {{mini()}} + {# Cart mini — rendered via fragment #} + {% if cart_mini_html %} + {{ cart_mini_html | safe }} + {% endif %} {# Site title #}
diff --git a/browser/templates/macros/cart_icon.html b/browser/templates/macros/cart_icon.html new file mode 100644 index 0000000..7b8a958 --- /dev/null +++ b/browser/templates/macros/cart_icon.html @@ -0,0 +1,31 @@ +{# Cart icon/badge — shows logo when empty, cart icon with count when items present #} + +{% macro cart_icon(count=0, oob=False) %} +
+ {% if count == 0 %} +
+ + + +
+ {% else %} + + + + {{ count }} + + + {% endif %} +
+{% endmacro %} diff --git a/browser/templates/macros/layout.html b/browser/templates/macros/layout.html index 9fe3b57..fc648e8 100644 --- a/browser/templates/macros/layout.html +++ b/browser/templates/macros/layout.html @@ -26,7 +26,17 @@
- {% include '_types/blog/mobile/_filter/_hamburger.html' %} +
+ + + + + + +
- {% import '_types/browse/mobile/_filter/search.html' as s %} - {{ s.search(current_local_href, search, search_count, hx_select) }} + {% from 'macros/search.html' import search_mobile %} + {{ search_mobile(current_local_href, search, search_count, hx_select) }}
{%- endmacro %} diff --git a/browser/templates/macros/search.html b/browser/templates/macros/search.html new file mode 100644 index 0000000..98c0cde --- /dev/null +++ b/browser/templates/macros/search.html @@ -0,0 +1,83 @@ +{# Shared search input macros for filter UIs #} + +{% macro search_mobile(current_local_href, search, search_count, hx_select) -%} +
+ + +
+ {% if search %} + {{search_count}} + {% endif %} +
+
+{%- endmacro %} + +{% macro search_desktop(current_local_href, search, search_count, hx_select) -%} +
+ + +
+ {% if search %} + {{search_count}} + {% endif %} + {{zap_filter}} +
+
+{%- endmacro %} diff --git a/db/session.py b/db/session.py index 87fd776..bff449c 100644 --- a/db/session.py +++ b/db/session.py @@ -64,11 +64,17 @@ def register_db(app: Quart): # If an exception occurred OR we didn't commit (still in txn), roll back. if hasattr(g, "s"): if exc is not None or g.s.in_transaction(): - if hasattr(g, "tx"): - await g.tx.rollback() + if hasattr(g, "tx") and g.tx.is_active: + try: + await g.tx.rollback() + except Exception: + pass finally: if hasattr(g, "s"): - await g.s.close() + try: + await g.s.close() + except Exception: + pass @app.errorhandler(Exception) async def mark_error(e):