Skip to content

refactor(widgets): split route templates and views by widget family (#121) - #133

Merged
manish-wekan merged 1 commit into
nitrocloudofficial:developfrom
ROHIT-JR:refactor/121-split-widget-views
Nov 9, 2026
Merged

manish-wekan merged 1 commit into
nitrocloudofficial:developfrom
ROHIT-JR:refactor/121-split-widget-views

Conversation

@ROHIT-JR

@ROHIT-JR ROHIT-JR commented Nov 7, 2026

Copy link
Copy Markdown
Collaborator

Fixes #121.

What changed

route_templates.py (870 lines) and views.py (569 lines) are now small route dispatchers. The per-widget code moved, unchanged, into one module per widget family:

Module Lines Contents
views.py 78 BODY_BUILDERS + render_body (route → body dispatch), re-exports
views_common.py 131 _safe_int/_safe_float, generic, missing, calculator, card, table, chart bodies
views_pizza.py 155 pizza list, map and shop bodies
views_flight.py 273 flight search/details, airport, order, seat, cancellation bodies
route_templates.py 101 _ROUTE_BUILDERS + render_widget_html / get_builtin_route_html / build_widget_html_for_route, re-exports
route_templates_generic.py 206 _page wrapper, generic/missing/calculator/card/table/chart templates
route_templates_pizza.py 303 pizza CSS, render JS, Mapbox head and builders
route_templates_flight.py 357 flight/order CSS, render JS and builders

Dependencies (one-directional, no cycles)

  • views_common ← views_pizza; views_flight stands alone (both use html_util/ui)
  • views_* ← views (dispatch)
  • views ← route_templates_* (templates call render_body, never a body module directly)
  • route_templates_generic ← route_templates_pizza / _flight (for _page)
  • all of the above ← route_templates

Each module imports cleanly on its own in a fresh interpreter.

Behavior and imports preserved

  • Rendered output is byte-for-byte identical. Before the split, I hashed the output of render_widget_html, build_widget_html_for_route and render_body for every route (plus unknown and widget/...html routes) with 7 data shapes, and for build_missing_widget / build_generic_widget: 338 cases. All 338 match after the split.
  • Every name the two old modules defined or imported is still importable from them (checked by loading the old files and comparing namespaces), including private ones tests use (_safe_int, _safe_float, _ROUTE_BUILDERS).
  • The code was moved by a script that copies whole top-level definitions verbatim and generates each module's imports from the names it uses. Nothing inside a function or string changed.

Not done, on purpose

The issue allows moving static HTML/JS into non-Python asset files. Every module is already under 500 lines without that, and keeping the strings in Python avoids any packaging change (package_data) or output drift. Happy to do it as a follow-up if you prefer.

Checks

  • No test changes. Widget, pizza, flight, template and CLI tests pass unchanged.
  • Full suite locally: 1321 passed. The 3 failures and 2 errors are the same on unmodified develop on my machine (test_oauth_client on Python 3.14, code-mode / wheel-build template tests without setuptools). CI runs 3.10 to 3.12.
  • The file-length check from ci: enforce 500-line Python file-length ratchet (#111) #126 passes, and both files drop out of its baseline.

…itrocloudofficial#121)

route_templates.py (870 lines) and views.py (569 lines) are now small route
dispatchers. The per-widget code moved, unchanged, into:

- views_common / views_pizza / views_flight: widget bodies
- route_templates_generic / _pizza / _flight: CSS, render JS and page builders

Dependencies run one way (views_common <- views_pizza, views_* <- views <-
route_templates_* <- route_templates), with no import cycles. Every name the
two old modules defined or imported is still importable from them, and the
rendered HTML is byte-for-byte identical.
@ROHIT-JR
ROHIT-JR requested a review from AadarshM07 November 7, 2026 14:51

@AadarshM07 AadarshM07 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, Clean refactoring that meets the acceptance criteria. Splitting route templates and views by family keeps each module well below 500 lines while leaving compact dispatchers. All widget tests pass as well

@manish-wekan
manish-wekan merged commit c22877a into nitrocloudofficial:develop Nov 9, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants