From f8aafda1f453b82683894a545c05fdcdf72d3eca Mon Sep 17 00:00:00 2001 From: Oleg Lavrovsky Date: Tue, 14 Mar 2017 11:10:32 +0100 Subject: [PATCH] Added news to frontpage --- publichealth/home/models.py | 19 ++++++++--- publichealth/home/templates/news.html | 48 +++++++++++---------------- 2 files changed, 35 insertions(+), 32 deletions(-) diff --git a/publichealth/home/models.py b/publichealth/home/models.py index 6fea49b..1d0042a 100644 --- a/publichealth/home/models.py +++ b/publichealth/home/models.py @@ -13,6 +13,8 @@ from wagtail.wagtailimages.blocks import ImageChooserBlock from wagtail.wagtailimages.edit_handlers import ImageChooserPanel from wagtail.wagtailsearch import index +from puput.models import EntryPage + from .util import TranslatedField class ArticleIndexPage(Page): @@ -172,16 +174,25 @@ class HomePage(Page): @property def featured(self): # Get list of live pages that are descendants of this page - articles = ArticlePage.objects.live()[:4] #.descendant_of(self) + articles = ArticlePage.objects.live() #.descendant_of(self) # Order by most recent date first #articles = articles.order_by('-date') - return articles + return articles[:4] + + @property + def newsfeed(self): + # Get list of latest news + # TODO: fetch children of 'News (DE)' + entries = EntryPage.objects.live().descendant_of(self) + # Order by most recent date first + entries = entries.order_by('-date') + return entries[:4] def get_context(self, request): - featured = self.featured[:4] # Update template context context = super(HomePage, self).get_context(request) - context['featured'] = featured + context['featured'] = self.featured + context['newsfeed'] = self.newsfeed return context parent_page_types = [] diff --git a/publichealth/home/templates/news.html b/publichealth/home/templates/news.html index 440db3c..c6b1fa7 100644 --- a/publichealth/home/templates/news.html +++ b/publichealth/home/templates/news.html @@ -1,39 +1,31 @@ +{% load wagtailcore_tags wagtailimages_tags puput_tags %} +
+ {% for entry in newsfeed %}
- + {% if entry.header_image %} + {% image entry.header_image fill-360x270 %} + {% endif %}
-

Ehrenmitgliedschaften

-

Nicole Probst-Hensch, Professorin für Pharmakologie und Epidemiologie am Schweizerischen Tropen- und Public Health Institut der Universität Basel, wurde die Ehrenmitgliedschaft von Public Health Schweiz verliehen.

- Mehr erfahren +

{{ entry.title }}

+

+ {% if entry.excerpt %} + {{ entry.excerpt|richtext }} + {% else %} + {{ entry.body|richtext|truncatewords_html:70 }} + {% endif %} +

+ Mehr erfahren
- -
-
-
-
- -
- -

Parlamentarische Gruppe nichtübertragbare Krankheiten NCD gegründet

- - Mehr erfahren -
- -
-
-
-
-
-
-

Wirksamer Schutz der Kinder und Jugendlichen vor Tabakkonsum rückt in weite Ferne

- Mehr erfahren -
- +
+ {% empty %} + No news today + {% endfor %}
-
+