From 94fdfec5953ad1e2e05b4e363931df230e80c8fe Mon Sep 17 00:00:00 2001 From: Guillaume Pellerin Date: Tue, 23 Aug 2016 20:26:29 +0200 Subject: [PATCH] Fix no home content, fix slider and home images --- .../core/templatetags/organization_tags.py | 11 +++++++++++ app/organization/pages/views.py | 6 +++++- app/templates/home/inc/generic_card.html | 9 ++++++--- app/templates/home/inc/slider.html | 17 ++++++++++------- 4 files changed, 32 insertions(+), 11 deletions(-) diff --git a/app/organization/core/templatetags/organization_tags.py b/app/organization/core/templatetags/organization_tags.py index f5bdc7e5..ce12849c 100644 --- a/app/organization/core/templatetags/organization_tags.py +++ b/app/organization/core/templatetags/organization_tags.py @@ -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) diff --git a/app/organization/pages/views.py b/app/organization/pages/views.py index 60bd7bc3..c36f2b17 100644 --- a/app/organization/pages/views.py +++ b/app/organization/pages/views.py @@ -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) diff --git a/app/templates/home/inc/generic_card.html b/app/templates/home/inc/generic_card.html index 311cd1b2..662c26d7 100644 --- a/app/templates/home/inc/generic_card.html +++ b/app/templates/home/inc/generic_card.html @@ -1,7 +1,10 @@ +{% load organization_tags i18n %}

{{ body.content_object.title }}


{{ body.content_object.description|slice:":500" }}

-{% if body.content_object.featured_image %} -
-{% endif %} +{% with body.content_object.images.all|get_type:'card' as image %} + {% if image %} +
+ {% endif %} +{% endwith %} {{ body.content_object.title }}
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
diff --git a/app/templates/home/inc/slider.html b/app/templates/home/inc/slider.html index 8ab5863d..b3ad988a 100644 --- a/app/templates/home/inc/slider.html +++ b/app/templates/home/inc/slider.html @@ -1,14 +1,17 @@ +{% load organization_tags i18n %}

Slider


{% for slider in home.dynamiccontenthomeslider_set.all %} - {% if slider.content_object.photo_slider %} -

{{ slider.content_object.title }}


-
- {{ slider.content_object.photo_slider_credits }}
- {{ slider.content_object.title }}
- ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
- {% endif %} + {% with slider.content_object.images.all|get_type:'slider' as image %} + {% if image %} +

{{ slider.content_object.title }}


+
+ {{ image.credits }}
+ {{ slider.content_object.title }}
+ ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ {% endif %} + {% endwith %} {% endfor %}

-- 2.39.5