From: Guillaume Pellerin Date: Wed, 11 May 2016 11:31:40 +0000 (+0200) Subject: fix multiple same posts X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=ef0ac953209df549522bf15651d3dcc7db167e07;p=mezzo.git fix multiple same posts --- diff --git a/app/festival/templates/festival/artist_detail.html b/app/festival/templates/festival/artist_detail.html index b0fa36f3..3e4fe4ef 100644 --- a/app/festival/templates/festival/artist_detail.html +++ b/app/festival/templates/festival/artist_detail.html @@ -1,6 +1,6 @@ {% extends "base.html" %} {% load i18n %} -{% load mezzanine_tags keyword_tags %} +{% load mezzanine_tags keyword_tags festival_tags %} {% block title %} {{ artist.name }} @@ -32,10 +32,12 @@ {% for video in event.videos.all %} {% include 'festival/inc/video_card.html' %} {% endfor %} - {% for post in event.blog_posts.all %} + {% endfor %} + {% with artist.events.all|unique_posts as posts %} + {% for post in posts %} {% include 'blog/includes/post_card.html' %} {% endfor %} - {% endfor %} + {% endwith %} {% endif %} {% endblock %} diff --git a/app/festival/templatetags/festival_tags.py b/app/festival/templatetags/festival_tags.py index 6507c6cf..ac7eeadb 100644 --- a/app/festival/templatetags/festival_tags.py +++ b/app/festival/templatetags/festival_tags.py @@ -41,13 +41,23 @@ def featured(*args): 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): news = Featured.objects.get(id=settings.BREAKING_NEWS_FEATURED_ID).pages.all() if news: return news[0].richtextpage.content return '' + +@register.filter +def get_class(obj): + return obj.__class__.__name__ + +@register.filter +def unique_posts(events): + post_list = [] + for event in events: + for post in event.blog_posts.all(): + print(post) + if not post in post_list: + post_list.append(post) + return post_list