From b1251bc43d040261e915987cf2667b2980ffead0 Mon Sep 17 00:00:00 2001 From: Emilie Date: Fri, 4 Nov 2016 17:28:31 +0100 Subject: [PATCH] Article : reverse related content --- app/organization/magazine/views.py | 30 +++++++++++++++---- ...edia.html => related_content_dynamic.html} | 0 .../magazine/article/article_detail.html | 4 +-- app/templates/media/playlist_detail.html | 2 +- 4 files changed, 26 insertions(+), 10 deletions(-) rename app/templates/core/inc/{related_content_media.html => related_content_dynamic.html} (100%) diff --git a/app/organization/magazine/views.py b/app/organization/magazine/views.py index e19a622c..a1b892bf 100644 --- a/app/organization/magazine/views.py +++ b/app/organization/magazine/views.py @@ -12,9 +12,9 @@ from dal_select2_queryset_sequence.views import Select2QuerySetSequenceView from mezzanine_agenda.models import Event from mezzanine.utils.views import paginate from mezzanine.conf import settings -from organization.magazine.models import Article, Topic, Brief +from organization.magazine.models import * from organization.network.models import DepartmentPage -from organization.pages.models import CustomPage +from organization.pages.models import CustomPage, DynamicContentPage from organization.core.views import SlugMixin from django.template.defaultfilters import slugify @@ -26,11 +26,29 @@ class ArticleDetailView(SlugMixin, DetailView): context_object_name = 'article' def get_context_data(self, **kwargs): - article = self.get_object() context = super(ArticleDetailView, self).get_context_data(**kwargs) - if article.department: - context['department_weaving_css_class'] = article.department.pages.first().weaving_css_class - context['department_name'] = article.department.name + + # automatic relation : dynamic content page + pages = DynamicContentPage.objects.filter(object_id=self.object.id).all() + pages = [p.content_object for p in pages] + + # automatic relation : dynamic content article + articles = DynamicContentArticle.objects.filter(object_id=self.object.id).all() + articles = [a.content_object for a in articles] + + # manual relation : get dynamic contents of current article + dynamic_content = [dca.content_object for dca in self.object.dynamic_content_articles.all()] + + # gather all and order by creation date + related_content = pages + related_content = articles + related_content += dynamic_content + related_content.sort(key=lambda x: x.created, reverse=True) + context['related_content'] = related_content + + if self.object.department: + context['department_weaving_css_class'] = self.object.department.pages.first().weaving_css_class + context['department_name'] = self.object.department.name return context diff --git a/app/templates/core/inc/related_content_media.html b/app/templates/core/inc/related_content_dynamic.html similarity index 100% rename from app/templates/core/inc/related_content_media.html rename to app/templates/core/inc/related_content_dynamic.html diff --git a/app/templates/magazine/article/article_detail.html b/app/templates/magazine/article/article_detail.html index 2552b324..653a8880 100644 --- a/app/templates/magazine/article/article_detail.html +++ b/app/templates/magazine/article/article_detail.html @@ -93,9 +93,7 @@ {% endblock %} {% block page_related_content %} - {% with dynamic_content=article.dynamic_content_articles.all object=article %} - {% include "core/inc/related_content.html" %} - {% endwith %} + {% include "core/inc/related_content_dynamic.html" with concrete_objects=related_content object=article %} {% endblock %} {% block page_sidebar %} diff --git a/app/templates/media/playlist_detail.html b/app/templates/media/playlist_detail.html index d5cfffa3..667cc692 100644 --- a/app/templates/media/playlist_detail.html +++ b/app/templates/media/playlist_detail.html @@ -67,5 +67,5 @@ {% endblock %} {% block page_related_content %} - {% include "core/inc/related_content_media.html" %} + {% include "core/inc/related_content_dynamic.html" %} {% endblock %} -- 2.39.5