From d54d5ec15715fcc1db57a6f6f6a7d60f903a6cbd Mon Sep 17 00:00:00 2001 From: Francesco Siddi Date: Wed, 3 Apr 2019 16:43:48 +0200 Subject: [PATCH] Use poster file as preview for film projects --- cloud/routes.py | 22 +++++++++++++++++++++- src/templates/films.pug | 5 ++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/cloud/routes.py b/cloud/routes.py index 3e14fe0..2a2472d 100644 --- a/cloud/routes.py +++ b/cloud/routes.py @@ -198,7 +198,27 @@ def courses(): def open_projects(): @current_app.cache.cached(timeout=3600, unless=current_user_is_authenticated) def render_page(): - projects = get_projects('film') + api = system_util.pillar_api() + projects = Project.all({ + 'where': { + 'category': 'film', + 'is_private': False + }, + 'sort': '-_created', + }, api=api) + for project in projects._items: + # Attach poster file (ensure the extension_props.cloud.poster attributes exists) + if 'extension_props' not in project: + continue + if EXTENSION_NAME not in project['extension_props']: + continue + if 'poster' not in project['extension_props'][EXTENSION_NAME]: + continue + project.extension_props.cloud.poster = get_file( + project.extension_props.cloud.poster, api=api) + # Add convenience attribute that specifies the presence of the poster file + project.has_poster = True + return render_template( 'films.html', title='films', diff --git a/src/templates/films.pug b/src/templates/films.pug index 51d8794..2a46dc7 100644 --- a/src/templates/films.pug +++ b/src/templates/films.pug @@ -29,14 +29,13 @@ include mixins/components .films-item.col-md-4.col-sm-6.col-lg-3.my-5 .d-flex.flex-column.h-100 - - | {% if project.picture_header %} + | {% if project.has_poster %} {# Check convenience attribute set in open_projects() #} a.mx-auto( href="{{ project_url }}", tabindex='{{ loop.index }}') img.rounded.w-100( alt="{{ project.name }}", - src="{{ project.picture_header.thumbnail('l', api=api) }}") + src="{{ project.extension_props.cloud.poster.thumbnail('l', api=api) }}") | {% endif %} h4.pt-5.pb-3.text-center