Browse Source

Fix crashes when some event doesn't have a poster

Signed-off-by: encrypt <encrypt@labr.xyz>
fadelkon 3 months ago
parent
commit
6a74d634de
2 changed files with 4 additions and 2 deletions
  1. 3 1
      app.py
  2. 1 1
      templates/flyers/asymmetric.html

+ 3 - 1
app.py

@@ -44,7 +44,9 @@ def fetch_events(api_endpoint):
             when += " alle "
             when += end_hour
         event['when'] = when
-        event['media'][0]['thumbnailPosition'] = f"{(event['media'][0]['focalpoint'][0] + 1) * 50}% {(event['media'][0]['focalpoint'][1] + 1) * 50}%"
+        print(event)
+        if event['media']:
+            event['media'][0]['thumbnailPosition'] = f"{(event['media'][0]['focalpoint'][0] + 1) * 50}% {(event['media'][0]['focalpoint'][1] + 1) * 50}%"
     return events
 
 @app.route("/")

+ 1 - 1
templates/flyers/asymmetric.html

@@ -30,7 +30,7 @@
 
       <div class="event">
        <div class="center flyer-container">
-        <img class="flyer" src="https://balotta.org/media/thumb/{{event.media[0].url}}" style="object-position: {{ event.media[0].thumbnailPosition }}"></img>
+         <img class="flyer" src="https://balotta.org/{{"media/thumb/" + event.media[0].url if event.media else "fallbackimage.png"}}" style="object-position: {{ event.media[0].thumbnailPosition if event.media else "50%"}}"></img>
        </div>
        <div class="event_info">
         <h3 class="title">{{ event.title }}</h3>