Fix JS crash: serialize saved_stations/featured_stations to proper JSON
All checks were successful
Build and push Docker image / build (push) Successful in 12s
Test / test (push) Successful in 15s

Python booleans (True/False) in saved_stations (is_favorite field) and
history (scrobbled field) were being rendered literally into JS via
|safe, causing 'True is not defined' ReferenceError that broke all JS
including book loading.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Marwin Schulz 2026-03-20 12:58:38 +01:00
parent b0ce463cca
commit a314643588
2 changed files with 5 additions and 3 deletions

View file

@ -84,10 +84,12 @@ def index(request):
context = { context = {
'saved_stations': saved_stations, 'saved_stations': saved_stations,
'saved_stations_json': json.dumps(saved_stations, cls=DjangoJSONEncoder),
'history': history, 'history': history,
'amazon_enabled': settings.AMAZON_AFFILIATE_ENABLED, 'amazon_enabled': settings.AMAZON_AFFILIATE_ENABLED,
'featured_stations': featured, 'featured_stations': featured,
'initial_podcast_feeds': initial_podcast_feeds, 'featured_stations_json': json.dumps(featured, cls=DjangoJSONEncoder),
'initial_podcast_feeds': json.dumps(initial_podcast_feeds, cls=DjangoJSONEncoder),
'focus_station': focus_station, 'focus_station': focus_station,
'focus_station_json': json.dumps(focus_station, cls=DjangoJSONEncoder), 'focus_station_json': json.dumps(focus_station, cls=DjangoJSONEncoder),
'encrypted_bg': encrypted_bg, 'encrypted_bg': encrypted_bg,

View file

@ -364,8 +364,8 @@
{% block extra_js %} {% block extra_js %}
<script> <script>
// Pass Django context into JS // Pass Django context into JS
const INITIAL_SAVED = {{ saved_stations|safe }}; const INITIAL_SAVED = {{ saved_stations_json|safe }};
const INITIAL_FEATURED = {{ featured_stations|safe }}; const INITIAL_FEATURED = {{ featured_stations_json|safe }};
const IS_AUTHENTICATED = {{ user.is_authenticated|yesno:"true,false" }}; const IS_AUTHENTICATED = {{ user.is_authenticated|yesno:"true,false" }};
const INITIAL_PODCAST_FEEDS = {{ initial_podcast_feeds|safe }}; const INITIAL_PODCAST_FEEDS = {{ initial_podcast_feeds|safe }};
window.USER_ID = {{ user.id|default:"null" }}; window.USER_ID = {{ user.id|default:"null" }};