diff --git a/publichealth/home/models.py b/publichealth/home/models.py index b90d01b..03db4c3 100644 --- a/publichealth/home/models.py +++ b/publichealth/home/models.py @@ -21,8 +21,18 @@ class ArticleIndexPage(Page): 'title', 'title_fr', ) + + intro_de = RichTextField(default='', blank=True) + intro_fr = RichTextField(default='', blank=True) + trans_intro = TranslatedField( + 'intro_de', + 'intro_fr', + ) + content_panels = Page.content_panels + [ + FieldPanel('intro_de'), FieldPanel('title_fr'), + FieldPanel('intro_fr'), ] def get_context(self, request): context = super(ArticleIndexPage, self).get_context(request) @@ -39,8 +49,8 @@ class ArticlePage(Page): 'title_fr', ) - intro_de = RichTextField(default='') - intro_fr = RichTextField(default='') + intro_de = RichTextField(default='', blank=True) + intro_fr = RichTextField(default='', blank=True) trans_intro = TranslatedField( 'intro_de', 'intro_fr', @@ -61,7 +71,6 @@ class ArticlePage(Page): 'body_fr', ) - date = models.DateField("Date") feed_image = models.ForeignKey( 'wagtailimages.Image', null=True, @@ -91,7 +100,6 @@ class ArticlePage(Page): ], heading="Français"), ] promote_panels = [ - FieldPanel('date'), ImageChooserPanel('feed_image'), InlinePanel('related_links', label="Links"), MultiFieldPanel(Page.promote_panels, "Common page configuration"), @@ -125,8 +133,8 @@ class HomePage(Page): 'intro_fr', ) - body_de = RichTextField(default='') - body_fr = RichTextField(default='') + body_de = RichTextField(default='', blank=True) + body_fr = RichTextField(default='', blank=True) trans_body = TranslatedField( 'body_de', 'body_fr', @@ -143,14 +151,30 @@ class HomePage(Page): 'infos_fr', ) - def get_articles(self): - return ArticleIndexPage.objects.descendant_of(self).live().order_by('-date').select_related('owner') - content_panels = Page.content_panels + [ - FieldPanel('intro_de', classname="full"), - FieldPanel('intro_fr', classname="full"), - FieldPanel('body_de', classname="full"), - FieldPanel('body_fr', classname="full"), - StreamFieldPanel('infos_de'), - StreamFieldPanel('infos_fr'), + MultiFieldPanel([ + FieldPanel('intro_de', classname="full"), + FieldPanel('body_de', classname="full"), + StreamFieldPanel('infos_de'), + ], heading="Deutsch"), + MultiFieldPanel([ + FieldPanel('intro_fr', classname="full"), + FieldPanel('body_fr', classname="full"), + StreamFieldPanel('infos_fr'), + ], heading="Français"), ] + + @property + def featured(self): + # Get list of live pages that are descendants of this page + articles = ArticlePage.objects.live().descendant_of(self) + # Order by most recent date first + #articles = articles.order_by('-date') + return articles + + def get_context(self, request): + featured = self.featured[:4] + # Update template context + context = super(HomePage, self).get_context(request) + context['featured'] = featured + return context \ No newline at end of file diff --git a/publichealth/home/templates/banner.html b/publichealth/home/templates/banner.html index 7899f93..b40ae93 100644 --- a/publichealth/home/templates/banner.html +++ b/publichealth/home/templates/banner.html @@ -1,15 +1,19 @@ {% load wagtailcore_tags %} +{% load wagtailimages_tags %} diff --git a/publichealth/home/templates/home/article_index_page.html b/publichealth/home/templates/home/article_index_page.html index 247ca05..726836b 100644 --- a/publichealth/home/templates/home/article_index_page.html +++ b/publichealth/home/templates/home/article_index_page.html @@ -4,5 +4,15 @@ {% block body_class %}template-{{ self.get_verbose_name|slugify }}{% endblock %} {% block content %} -... +{% for entry in banner_articles %} +
+ + +
+{% empty %} + No articles found +{% endfor %} {% endblock %} diff --git a/publichealth/home/templates/home/home_page.html b/publichealth/home/templates/home/home_page.html index d5c78ec..6998d05 100644 --- a/publichealth/home/templates/home/home_page.html +++ b/publichealth/home/templates/home/home_page.html @@ -13,6 +13,7 @@ {% include 'news.html' %} +{% if page.trans_body %}
@@ -20,6 +21,7 @@
+{% endif %}