]> git.parisson.com Git - mezzo.git/commitdiff
randomize item index cards
authorGuillaume Pellerin <guillaume.pellerin@ircam.fr>
Tue, 10 May 2016 16:22:56 +0000 (18:22 +0200)
committerGuillaume Pellerin <guillaume.pellerin@ircam.fr>
Tue, 10 May 2016 16:22:56 +0000 (18:22 +0200)
app/festival/templatetags/festival_tags.py
app/templates/index.html

index 3b9fb5bc448bccde34461547931914ad1986fc1b..aaf3c4c6aee391d2f2aa4b78ce8b71599a7d6e06 100644 (file)
@@ -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):
index ffa8fd2d169913e874cfc825dade07eb33a3dd85..82771ce43ff372d63f2f09a2d4f8d865b2914191 100644 (file)
 <a href="{% url 'page' edito.slug %}" class="event__meta__btn">{% trans "Read the edito" %}</a>
 <br>
 
-{% featured as featured %}
+{% featured as featured_list %}
 
 <div class="last__media">
     <h2 class="section__title">{% trans "Featured" %}</h2>
-
     <div class="msry__container">
         <div class="msry__sizer"></div>
-
-        {% for post in featured.blogposts.all %}
-        <div class="last__media__entry  msry__item">
-             {# <span>{% trans "Article" %}</span>#}
-             {% include 'blog/includes/post_card.html' %}
-             <a href="{% url 'blog_post_list' %}" class="btn btn-full">{% trans "More" context "apos" %} {% trans "articles" %}</a>
-        </div>
-        {% endfor %}
-
-        {% for artist in featured.artists.all %}
+        {% for item in featured_list %}
         <div class="last__media__entry  msry__item">
-             {# <span>{% trans "Artist" %}</span>#}
-             {% include "festival/inc/artist_card.html" %}
-             <a href="{% url 'festival-artist-list' %}" class="btn btn-full">{% trans "More" context "apos" %} {% trans "artists" %}</a>
+            {% if item|get_class == 'BlogPost' %}
+                {% with item as post %}
+                    {% include 'blog/includes/post_card.html' %}
+                    <a href="{% url 'blog_post_list' %}" class="btn btn-full">{% trans "More" context "apos" %} {% trans "articles" %}</a>
+                {% endwith %}
+            {% elif item|get_class == 'Artist' %}
+                {% with item as artist %}
+                    {% include "festival/inc/artist_card.html" %}
+                    <a href="{% url 'festival-artist-list' %}" class="btn btn-full">{% trans "More" context "apos" %} {% trans "artists" %}</a>
+                {% endwith %}
+            {% elif item|get_class == 'Video' %}
+                {% with item as video %}
+                    {% include 'festival/inc/video_card.html' %}
+                    <a href="{% url 'festival-video-list' %}" class="btn btn-full">{% trans "More" %} {% trans "videos" %}</a>
+                {% endwith %}
+            {% endif %}
         </div>
         {% endfor %}
-
-        {% for video in featured.videos.all %}
-        <div class="last__media__entry  msry__item">
-            {# <span>{% trans "Video" %}</span>#}
-            {% include 'festival/inc/video_card.html' %}
-            <a href="{% url 'festival-video-list' %}" class="btn btn-full">{% trans "More" %} {% trans "videos" %}</a>
-        </div>
-        {% endfor %}
-
     </div>
 </div>