]> git.parisson.com Git - mezzo.git/commitdiff
Fix no home content, fix slider and home images
authorGuillaume Pellerin <guillaume.pellerin@ircam.fr>
Tue, 23 Aug 2016 18:26:29 +0000 (20:26 +0200)
committerGuillaume Pellerin <guillaume.pellerin@ircam.fr>
Tue, 23 Aug 2016 18:26:29 +0000 (20:26 +0200)
app/organization/core/templatetags/organization_tags.py
app/organization/pages/views.py
app/templates/home/inc/generic_card.html
app/templates/home/inc/slider.html

index f5bdc7e581e5e4772eacac1ff7278fbd9952f5ce..ce12849c13e119c8ba0fe3427fea90aacf8cdd07 100644 (file)
@@ -89,3 +89,14 @@ def no_parents(events):
 def get_mezzanine_menu_name(menu_id):
     return settings.PAGE_MENU_TEMPLATES[int(menu_id)-1][1]
     #return getattr(settings, 'PAGE_MENU_TEMPLATES', menu_id)
+
+@register.filter
+def get_type(objects, type):
+    objs = objects.filter(type=type)
+    if objs:
+        return objs[0]
+    return None
+        
+@register.filter
+def in_category(objects, category):
+    return objects.filter(category=type)
index 60bd7bc37a85626c91c4b2d946b250eb2d32d27b..c36f2b17b387a894e2fbefecd13a5bea8fc463d7 100644 (file)
@@ -8,6 +8,7 @@ from organization.core.views import SlugMixin
 from organization.magazine.models import Article, Topic, Brief
 from organization.pages.models import Home
 
+
 class HomeView(SlugMixin, ListView):
 
     model = Home
@@ -16,7 +17,10 @@ class HomeView(SlugMixin, ListView):
     context_object_name = 'home'
 
     def get_queryset(self, **kwargs):
-        return self.model.objects.published().latest("publish_date")
+        homes = self.model.objects.published()
+        if homes:
+            return homes.latest("publish_date")
+        return None
 
     def get_context_data(self, **kwargs):
         context = super(HomeView, self).get_context_data(**kwargs)
index 311cd1b2155d32e35ead3cebf3b4297786804de2..662c26d7b15f8c6ecbaa3778e4951fb30d26c0f8 100644 (file)
@@ -1,7 +1,10 @@
+{% load organization_tags i18n %}
 <h2>{{ body.content_object.title }}<h2><br/>
 <p>{{ body.content_object.description|slice:":500" }}</p>
-{% if  body.content_object.featured_image %}
-<img src="{{ MEDIA_URL }}{{ body.content_object.featured_image }}" title="" /><br/>
-{% endif %}
+{% with body.content_object.images.all|get_type:'card' as image %}
+  {% if image %}
+    <img src="{{ MEDIA_URL }}{{ image.file }}" title="" /><br/>
+  {% endif %}
+{% endwith %}
 <a href="{{ body.content_object.get_absolute_url }}" title="{{ body.content_object.title }}">{{ body.content_object.title }}</a><br/>
 ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------<br/>
index 8ab5863db3782520afc5cac52fac686384054a68..b3ad988a079eaa882155d10eb9080884a4078724 100644 (file)
@@ -1,14 +1,17 @@
+{% load organization_tags i18n %}
 <hr/>
 <h1>Slider</h1>
 <br/>
 {% for slider in home.dynamiccontenthomeslider_set.all %}
-  {% if slider.content_object.photo_slider %}
-  <h2>{{ slider.content_object.title }}<h2><br/>
-  <img src="{{ MEDIA_URL }}{{ slider.content_object.photo_slider }}" title="{{ slider.content_object.photo_slider_credits }}" /><br/>
-  {{ slider.content_object.photo_slider_credits }}<br/>
-  <a href="{{ slider.content_object.get_absolute_url }}" title="{{ slider.content_object.title }}">{{ slider.content_object.title }}</a><br/>
-  ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------<br/>
-  {% endif %}
+  {% with slider.content_object.images.all|get_type:'slider' as image %}
+    {% if image %}
+          <h2>{{ slider.content_object.title }}<h2><br/>
+          <img src="{{ MEDIA_URL }}{{ image.file }}" title="{{ image.credits }}" /><br/>
+          {{ image.credits }}<br/>
+          <a href="{{ slider.content_object.get_absolute_url }}" title="{{ slider.content_object.title }}">{{ slider.content_object.title }}</a><br/>
+          ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------<br/>
+    {% endif %}
+  {% endwith %}
 {% endfor %}
 <br/>
 <hr/>