]> git.parisson.com Git - mezzo.git/commitdiff
Article : reverse related content
authorEmilie <zawadzki@ircam.fr>
Fri, 4 Nov 2016 16:28:31 +0000 (17:28 +0100)
committerEmilie <zawadzki@ircam.fr>
Fri, 4 Nov 2016 16:28:31 +0000 (17:28 +0100)
app/organization/magazine/views.py
app/templates/core/inc/related_content_dynamic.html [new file with mode: 0644]
app/templates/core/inc/related_content_media.html [deleted file]
app/templates/magazine/article/article_detail.html
app/templates/media/playlist_detail.html

index e19a622c51d2da03fd66d4055f615a89c12f8113..a1b892bfaadf23684a67c83c3bf4fcbd04962742 100644 (file)
@@ -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 (file)
index 0000000..a1236f5
--- /dev/null
@@ -0,0 +1,24 @@
+{% load i18n mezzanine_tags keyword_tags organization_tags pages_tags %}
+{% if concrete_objects %}
+    <hr class="mt0 mb0" />
+    <div class="white-bg pb2">
+        <div class="container">
+            <div class="row tac">
+                <div class="col-xs-12">
+                    <h2 class="dashed dashed--center mt2">{% if object.related_title.title %}{{ object.related_title.title }}{% else %}{% trans "Also discover" %}{% endif %}</h2>
+                </div>
+            </div>
+            <div class="row tac">
+                {% for concrete_object in concrete_objects %}
+                    <div class="col-lg-3 col-md-4 col-sm-4 col-xs-6">
+                        {% 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 %}
+                    </div>
+                {% endfor %}
+            </div>
+        </div>
+    </div>
+{% 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 (file)
index a1236f5..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-{% load i18n mezzanine_tags keyword_tags organization_tags pages_tags %}
-{% if concrete_objects %}
-    <hr class="mt0 mb0" />
-    <div class="white-bg pb2">
-        <div class="container">
-            <div class="row tac">
-                <div class="col-xs-12">
-                    <h2 class="dashed dashed--center mt2">{% if object.related_title.title %}{{ object.related_title.title }}{% else %}{% trans "Also discover" %}{% endif %}</h2>
-                </div>
-            </div>
-            <div class="row tac">
-                {% for concrete_object in concrete_objects %}
-                    <div class="col-lg-3 col-md-4 col-sm-4 col-xs-6">
-                        {% 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 %}
-                    </div>
-                {% endfor %}
-            </div>
-        </div>
-    </div>
-{% endif %}
index 2552b324f5a6f697089a077418001246685ed1aa..653a88803bf75e152f7d8e0decb3aeec787a092f 100644 (file)
@@ -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 %}
index d5cfffa3809afc9d1f7d91b366bddf5c03c22578..667cc692eb6b9c511e40bd7102eb88cfc64eba0c 100644 (file)
@@ -67,5 +67,5 @@
 {% endblock %}
 
 {% block page_related_content %}
-    {% include "core/inc/related_content_media.html" %}
+    {% include "core/inc/related_content_dynamic.html" %}
 {% endblock %}