]> git.parisson.com Git - mezzo.git/commitdiff
Breadcrumb for article, depends from where user is coming. Department or Topic.
authorEmilie <zawadzki@ircam.fr>
Thu, 11 Aug 2016 08:47:41 +0000 (10:47 +0200)
committerEmilie <zawadzki@ircam.fr>
Thu, 11 Aug 2016 08:47:41 +0000 (10:47 +0200)
app/organization/magazine/views.py
app/organization/team/models.py
app/templates/magazine/article/article_detail.html
app/templates/pages/department.html

index d1699098eca59b60f46a9a57effb17edc0a5e0b5..a039256c2023034bcadf19dd688ec2cd17eaf8a3 100644 (file)
@@ -1,3 +1,4 @@
+from urllib.parse import urlparse
 from django.shortcuts import render
 from django.utils import timezone
 #from django.views.generic import *
@@ -5,7 +6,9 @@ from django.views.generic import DetailView, ListView, TemplateView
 from django.views.generic.base import *
 from django.shortcuts import get_object_or_404
 
-from organization.magazine.models import Article, Topic ,Brief
+from organization.magazine.models import Article, Topic, Brief
+from organization.team.models import Department
+
 from organization.core.views import SlugMixin
 from django.template.defaultfilters import slugify
 
@@ -16,8 +19,22 @@ class ArticleDetailView(SlugMixin, DetailView):
     template_name='magazine/article/article_detail.html'
     context_object_name = 'article'
 
+    def get(self, request, *args, **kwargs):
+        previous_page_url = request.META['HTTP_REFERER']
+        previous_page_slug = request.META['HTTP_REFERER'].rsplit("/")[-2]
+        if previous_page_slug:
+            #find parents page
+            parsed_url = urlparse(previous_page_url)
+            self.department_parent = Department.objects.filter(slug=parsed_url.path[1:][:-1])
+            self.topic_parent = Topic.objects.filter(slug=previous_page_slug)
+        return super(ArticleDetailView, self).get(request, *args, **kwargs)
+
     def get_context_data(self, **kwargs):
         context = super(ArticleDetailView, self).get_context_data(**kwargs)
+        if self.topic_parent:
+            context['topic_parent'] = self.topic_parent.all()[0]
+        if self.department_parent:
+            context['department_parent'] =  self.department_parent.all()[0]
         return context
 
 
index 385b7e38f006048bb24d8f723438cf5fa9a57820..00bc198e06c4be1e8ce29a72d5914cc56d47382a 100644 (file)
@@ -23,6 +23,7 @@ from mezzanine.galleries.models import BaseGallery
 
 from organization.media.models import Photo
 from organization.core.models import *
+from organization.magazine.models import Article
 
 from django_countries.fields import CountryField
 # from .nationalities.fields import NationalityField
@@ -84,6 +85,7 @@ class Department(Page, SubTitle, RichText, Photo):
     organization = models.ForeignKey('Organization', verbose_name=_('organization'))
     url = models.URLField(_('URL'), max_length=512, blank=True)
     weaving_css_class = models.CharField(_('weaving CSS class'), max_length=64, blank=True)
+    articles_related = models.ManyToManyField(Article, verbose_name=_('Related articles'), blank=True)
 
     class Meta:
         verbose_name = _('department')
index d4d5e442fd4ad4e147ae66143255b9263ccf97e9..d3741c594317ebddd83b28e2a32e739e7990cc19 100644 (file)
 
 {% block breadcrumb_menu %}
     {{ block.super }}
-    <li class="active">{{ article.title }}</li>
+    {% if topic_parent %}
+    <li class="breadcrumb__item"><a href="{% url "topic-detail" parent_topic.slug %}" class="breadcrumb__link" title="{{ parent_topic.title }}">{{ parent_topic.title }}</a></li>
+    {% endif %}
+    {% if department_parent %}
+    <li class="breadcrumb__item"><a href="{% url "page" department_parent.slug %}" class="breadcrumb__link" title="{{ department_parent.title }}">{{ department_parent.title }}</a></li>
+    {% endif %}
+
+    <li class="breadcrumb__item active">{{ article.title }}</li>
 {% endblock %}
 
 {% block page_title %}
index fdf679ddff22e346be0b082b5b280eb659a91207..205df53e6a64774fabf9434004aff297f87f6eb2 100644 (file)
@@ -32,7 +32,6 @@
 {% endblock %}
 
 {% block page_content %}
-
     {% if page.department.sub_title %}
         {% editable page.department.sub_title %}
             <div class="chapo">
         {% endif %}
     {% endif %}
 
+    {% if page.department.articles_related.all %}
+      <h2 class="dashed dashed--center">{% trans "Also discover" %}</h2>
+      {% for article in page.department.articles_related.all %}
+          {% include 'magazine/article/includes/article_card.html' %}
+      {% endfor %}
+    {% endif %}
+
+
     {% if page.department.pageblock_set.all %}
         <div class="white-bg">
             <div class="container">