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
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
--- /dev/null
+{% 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 %}
+++ /dev/null
-{% 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 %}