From: Emilie Date: Fri, 4 Nov 2016 16:28:31 +0000 (+0100) Subject: Article : reverse related content X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=b1251bc43d040261e915987cf2667b2980ffead0;p=mezzo.git Article : reverse related content --- 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_dynamic.html b/app/templates/core/inc/related_content_dynamic.html new file mode 100644 index 00000000..a1236f58 --- /dev/null +++ b/app/templates/core/inc/related_content_dynamic.html @@ -0,0 +1,24 @@ +{% load i18n mezzanine_tags keyword_tags organization_tags pages_tags %} +{% if concrete_objects %} +
+
+
+
+
+

{% if object.related_title.title %}{{ object.related_title.title }}{% else %}{% trans "Also discover" %}{% endif %}

+
+
+
+ {% for concrete_object in concrete_objects %} +
+ {% with app_label=concrete_object|app_label_short classname=concrete_object|classname|lower object=concrete_object %} + {% with app_label|add:"/"|add:classname|add:"/includes/"|add:classname|add:"_card.html" as template %} + {% include template %} + {% endwith %} + {% endwith %} +
+ {% endfor %} +
+
+
+{% endif %} diff --git a/app/templates/core/inc/related_content_media.html b/app/templates/core/inc/related_content_media.html deleted file mode 100644 index a1236f58..00000000 --- a/app/templates/core/inc/related_content_media.html +++ /dev/null @@ -1,24 +0,0 @@ -{% load i18n mezzanine_tags keyword_tags organization_tags pages_tags %} -{% if concrete_objects %} -
-
-
-
-
-

{% if object.related_title.title %}{{ object.related_title.title }}{% else %}{% trans "Also discover" %}{% endif %}

-
-
-
- {% for concrete_object in concrete_objects %} -
- {% with app_label=concrete_object|app_label_short classname=concrete_object|classname|lower object=concrete_object %} - {% with app_label|add:"/"|add:classname|add:"/includes/"|add:classname|add:"_card.html" as template %} - {% include template %} - {% endwith %} - {% endwith %} -
- {% endfor %} -
-
-
-{% endif %} 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 %}