Skip to content

Commit 5b63510

Browse files
committed
Add type checks for demo ID and ensure string conversion in template data attributes
1 parent bbcdec2 commit 5b63510

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

flask_app/app.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,9 @@ def get_categories() -> dict[str, list[dict]]:
249249
@app.context_processor
250250
def utility_processor():
251251
def get_card_type(category, demo):
252-
if category == 'visualizations' or demo['id'].startswith('viz.'):
252+
# Add a check for the existence of 'id' and its type
253+
demo_id = demo.get('id')
254+
if category == 'visualizations' or (isinstance(demo_id, str) and demo_id.startswith('viz.')):
253255
return 'visualization-card'
254256
if 'leetcode' in category:
255257
return 'leetcode-card'

flask_app/templates/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ <h3>No demos discovered</h3>
8585
data-category="{{ category }}"
8686
data-id="{{ d.id }}"
8787
data-status="{{ get_demo_status(d) }}"
88-
data-search-text="{{ (d.title + ' ' + category + ' ' + d.id)|lower }}">
88+
data-search-text="{{ (d.title + ' ' + category + ' ' + d.id|string)|lower }}">
8989

9090
<!-- Card Header -->
9191
<header class="card-header">
@@ -136,7 +136,7 @@ <h3 class="card-title">{{ d.title }}</h3>
136136

137137
<!-- Card Actions -->
138138
<footer class="card-actions">
139-
{% if category == 'visualizations' or d.id.startswith('viz.') %}
139+
{% if category == 'visualizations' or (d.id|string).startswith('viz.') %}
140140
{% if d.id == 'viz.sorting' %}
141141
<a class="btn-primary" href="{{ url_for('viz_sorting') }}">Launch</a>
142142
{% elif d.id == 'viz.graph' %}

0 commit comments

Comments
 (0)