Skip to content

Commit ec8fd76

Browse files
committed
Refactor demo module handling in app.py and update navigation link in base.html
1 parent c49a9a3 commit ec8fd76

File tree

2 files changed

+4
-16
lines changed

2 files changed

+4
-16
lines changed

flask_app/app.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -274,14 +274,6 @@ def index():
274274
# Build categories with additional top-level visualization entries for the dashboard
275275
categories = {k: v[:] for k, v in get_categories().items()}
276276

277-
# Add LeetCode problems to categories
278-
from src.interview_workbook.leetcode._registry import get_all as get_all_leetcode
279-
280-
leetcode_problems = get_all_leetcode()
281-
for problem in leetcode_problems:
282-
category_key = f"leetcode/{problem['category'].value}"
283-
categories.setdefault(category_key, []).append(problem)
284-
285277
# Add visualizations
286278
categories.setdefault("visualizations", [])
287279
visualizations = [
@@ -349,11 +341,6 @@ def index():
349341

350342

351343
def run_demo(module_name: str) -> str:
352-
"""Import the module and execute its demo() while capturing stdout."""
353-
# Defensive: ensure module_name is a valid dotted identifier, not a numeric string
354-
if not isinstance(module_name, str) or module_name.strip() == "" or module_name.isdigit():
355-
raise ValueError(f"Invalid module name: {module_name!r}")
356-
357344
try:
358345
mod = importlib.import_module(module_name)
359346
except ModuleNotFoundError as e:
@@ -402,6 +389,9 @@ def demo_page():
402389
@app.post("/demo")
403390
def demo_run():
404391
module = request.form.get("module")
392+
if not module and request.is_json:
393+
data = request.get_json(silent=True) or {}
394+
module = data.get("module")
405395
if not module:
406396
abort(400, description="Missing module")
407397

flask_app/templates/base.html

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ <h1 class="brand"><a href="{{ url_for('index') }}">Python DSA Demos</a></h1>
4444
class="{{ 'active' if ep == 'index' else '' }}"
4545
{% if ep == 'index' %}aria-current="page"{% endif %}>Dashboard</a>
4646
<a href="{{ url_for('index') }}?view=algorithms"
47-
class="{{ 'active' if request.args.get('view') == 'algorithms' else '' }}">Algorithms</a>
48-
<a href="{{ url_for('index') }}?view=leetcode"
49-
class="{{ 'active' if request.args.get('view') == 'leetcode' else '' }}">LeetCode</a>
47+
class="{{ 'active' if request.args.get('view') == 'algorithms' else '' }}">Algorithms & Leetcode</a>
5048
<a href="{{ url_for('index') }}?view=visualizations"
5149
class="{{ 'active' if request.args.get('view') == 'visualizations' else '' }}">Visualizations</a>
5250
<a href="{{ url_for('big_o_guide') }}"

0 commit comments

Comments
 (0)