]> git.parisson.com Git - mezzo.git/commitdiff
[Person] : separate related objects
authorEmilie <zawadzki@ircam.fr>
Tue, 14 Feb 2017 17:12:57 +0000 (18:12 +0100)
committerEmilie <zawadzki@ircam.fr>
Tue, 14 Feb 2017 17:12:57 +0000 (18:12 +0100)
app/organization/network/views.py
app/templates/network/person_detail.html

index 4a77459d2c361d544ee24a31b4ce8d6879659af0..9e6ca5e6a4d530eab6eea3b745dff74919a4f794 100644 (file)
@@ -51,16 +51,15 @@ class PersonDetailView(SlugMixin, DetailView):
 
     def get_context_data(self, **kwargs):
         context = super(PersonDetailView, self).get_context_data(**kwargs)
-
+        context["related"] = {}
         # Person events : this type is separated from the other because
         # this is not managed by list of person by person in inlines directly
-        events = self.object.events.all()
-        events = (item.event for item in events)
-
+        person_events = self.object.events.all()
+        events = [item.event for item in person_events]
+        context["related"]["event"] = events
         # All other related models
         person_list_block_inlines = self.object.person_list_block_inlines.all()
         related_instances = []
-
         # for each person list to which the person belongs to...
         for person_list_block_inline in person_list_block_inlines:
             related_objects = person_list_block_inline.person_list_block._meta.get_all_related_objects()
@@ -77,15 +76,10 @@ class PersonDetailView(SlugMixin, DetailView):
                                     instance = getattr(related_inline, field.name)
                                     # get only article, custom page etc...
                                     if not isinstance(instance, person_list_block_inline.person_list_block.__class__) :  #and not isinstance(person_list_block_inline.person_list_block.__class__):
-                                        related_instances.append(instance)
-
-        # appends events
-        related_instances += events
-
-        # sort by date
-        related_instances.sort(key=lambda x: x.created)
+                                        if not instance._meta.model_name in context["related"]:
+                                            context["related"][instance._meta.model_name] = []
+                                        context["related"][instance._meta.model_name].append(instance)
 
-        context["related_content"] = related_instances
         context["person_email"] = self.object.email if self.object.email else self.object.slug.replace('-', '.')+" (at) ircam.fr"
         return context
 
index 13f0ba3ce3960f92af4b2decb6d238672b9cfe99..77b7ceb9f65861cab8c6ebcc7f8eada91c8982ac 100644 (file)
         </ul>
       {% endif %}
     {% endwith %}
+
+    <h2>{% trans 'Related Events' %}</h2>
+    {% for event in related.event %}
+        {{ event }}<br>
+    {% endfor %}
+
+    <h2>{% trans 'Related Articles' %}</h2>
+    {% for article in related.article %}
+        {{ article }}<br>
+    {% endfor %}
+
+    <h2>{% trans 'Related Pages' %}</h2>
+    {% for custompage in related.custompage %}
+        {{ custompage }}<br>
+    {% endfor %}
+
 {% endblock %}
 
 {% block page_sidebar %}
@@ -81,7 +97,3 @@
         {% endif %}
     {% endwith %}
 {% endblock %}
-
-{% block page_related_content %}
-    {% include "core/inc/related_content_dynamic.html" with concrete_objects=related_content %}
-{% endblock %}