From: Guillaume Pellerin Date: Tue, 10 May 2016 16:22:56 +0000 (+0200) Subject: randomize item index cards X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=b1a64c5d155bb88783c8aa6b66ac676eadd06c6a;p=mezzo.git randomize item index cards --- diff --git a/app/festival/templatetags/festival_tags.py b/app/festival/templatetags/festival_tags.py index 3b9fb5bc..aaf3c4c6 100644 --- a/app/festival/templatetags/festival_tags.py +++ b/app/festival/templatetags/festival_tags.py @@ -5,6 +5,7 @@ from mezzanine.template import Library from mezzanine_agenda.models import Event from festival.models import * from mezzanine.conf import settings +from random import shuffle register = Library() @@ -27,8 +28,20 @@ def featured_events(*args): @register.as_tag def featured(*args): - return Featured.objects.get(id=settings.HOME_FEATURED_ID) + featured = Featured.objects.get(id=settings.HOME_FEATURED_ID) + featured_list = [] + for post in featured.blogposts.all(): + featured_list.append(post) + for video in featured.videos.all(): + featured_list.append(video) + for artist in featured.artists.all(): + featured_list.append(artist) + shuffle(featured_list) + return featured_list +@register.filter +def get_class(obj): + return obj.__class__.__name__ @register.as_tag def featured_breaking_news_content(*args): diff --git a/app/templates/index.html b/app/templates/index.html index ffa8fd2d..82771ce4 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -19,38 +19,32 @@ {% trans "Read the edito" %}
-{% featured as featured %} +{% featured as featured_list %}

{% trans "Featured" %}

-
- - {% for post in featured.blogposts.all %} -
- {# {% trans "Article" %}#} - {% include 'blog/includes/post_card.html' %} - {% trans "More" context "apos" %} {% trans "articles" %} -
- {% endfor %} - - {% for artist in featured.artists.all %} + {% for item in featured_list %}
- {# {% trans "Artist" %}#} - {% include "festival/inc/artist_card.html" %} - {% trans "More" context "apos" %} {% trans "artists" %} + {% if item|get_class == 'BlogPost' %} + {% with item as post %} + {% include 'blog/includes/post_card.html' %} + {% trans "More" context "apos" %} {% trans "articles" %} + {% endwith %} + {% elif item|get_class == 'Artist' %} + {% with item as artist %} + {% include "festival/inc/artist_card.html" %} + {% trans "More" context "apos" %} {% trans "artists" %} + {% endwith %} + {% elif item|get_class == 'Video' %} + {% with item as video %} + {% include 'festival/inc/video_card.html' %} + {% trans "More" %} {% trans "videos" %} + {% endwith %} + {% endif %}
{% endfor %} - - {% for video in featured.videos.all %} -
- {# {% trans "Video" %}#} - {% include 'festival/inc/video_card.html' %} - {% trans "More" %} {% trans "videos" %} -
- {% endfor %} -