diff --git a/CHANGELOG.md b/CHANGELOG.md index 41059b5..7bd6c67 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ # Change Log Please see [Pull Request history](https://github.com/datalets/public-health-ch/pulls?q=is%3Apr+is%3Aclosed) on GitHub. + +## 2.0.0 - 2022-07-12 + +- 10694: Introduce table block to show program details +- 10695: Add a header image to the article index template diff --git a/feedler/migrations/0009_entry_expire_at.py b/feedler/migrations/0009_entry_expire_at.py new file mode 100644 index 0000000..cb54fc0 --- /dev/null +++ b/feedler/migrations/0009_entry_expire_at.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.13 on 2022-05-03 10:09 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('feedler', '0008_auto_20171117_1647'), + ] + + operations = [ + migrations.AddField( + model_name='entry', + name='expire_at', + field=models.DateTimeField(blank=True, null=True, verbose_name='expiry date/time'), + ), + ] diff --git a/feedler/models/models.py b/feedler/models/models.py index 7eb7569..1444b93 100644 --- a/feedler/models/models.py +++ b/feedler/models/models.py @@ -1,9 +1,10 @@ # -*- coding: utf-8 -*- +import datetime from django.db import models from django.utils import translation from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger - +from django.utils.translation import gettext_lazy as _ from wagtail.core.models import Page, Orderable from wagtail.admin.edit_handlers import FieldPanel from wagtail.core.fields import RichTextField @@ -39,6 +40,11 @@ class Entry(models.Model): lang = models.CharField(max_length=2, blank=True, default='', choices=LANGUAGE_CHOICES) content = models.TextField() tags = models.TextField(blank=True) + expire_at = models.DateTimeField( + verbose_name=_("expiry date/time"), + blank=True, + null=True + ) stream = models.ForeignKey(Stream, blank=False, on_delete=models.CASCADE, @@ -68,7 +74,9 @@ class FeedPage(Page): @property def feedentries(self): if self.stream: - entries = Entry.objects.filter(stream=self.stream) + entries = Entry.objects.filter(stream=self.stream).filter( + models.Q(expire_at__isnull=True) | models.Q(expire_at__gt=datetime.datetime.now()) + ) else: entries = Entry.objects.all() # Filter out by chosen language diff --git a/publichealth/home/migrations/0034_auto_20220714_1145.py b/publichealth/home/migrations/0034_auto_20220714_1145.py new file mode 100644 index 0000000..38d68f8 --- /dev/null +++ b/publichealth/home/migrations/0034_auto_20220714_1145.py @@ -0,0 +1,37 @@ +# Generated by Django 3.2.13 on 2022-07-14 09:45 + +from django.db import migrations, models +import django.db.models.deletion +import wagtail.contrib.table_block.blocks +import wagtail.core.fields + + +class Migration(migrations.Migration): + + dependencies = [ + ('wagtailimages', '0023_add_choose_permissions'), + ('home', '0033_auto_20220207_0731'), + ] + + operations = [ + migrations.AddField( + model_name='articleindexpage', + name='header_image', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='wagtailimages.image'), + ), + migrations.AddField( + model_name='articleindexpage', + name='table_de', + field=wagtail.core.fields.StreamField([('table_de', wagtail.contrib.table_block.blocks.TableBlock(template='home/program_table.html'))], blank=True, null=True), + ), + migrations.AddField( + model_name='articleindexpage', + name='table_en', + field=wagtail.core.fields.StreamField([('table_en', wagtail.contrib.table_block.blocks.TableBlock(template='home/program_table.html'))], blank=True, null=True), + ), + migrations.AddField( + model_name='articleindexpage', + name='table_fr', + field=wagtail.core.fields.StreamField([('table_fr', wagtail.contrib.table_block.blocks.TableBlock(template='home/program_table.html'))], blank=True, null=True), + ), + ] diff --git a/publichealth/home/models/__init__.py b/publichealth/home/models/__init__.py index 52e04bb..bc6c174 100644 --- a/publichealth/home/models/__init__.py +++ b/publichealth/home/models/__init__.py @@ -2,3 +2,4 @@ from .forms import * from .models import * from .snippets import * from .admin import * +from .image_formats import * diff --git a/publichealth/home/models/image_formats.py b/publichealth/home/models/image_formats.py new file mode 100644 index 0000000..ebf4968 --- /dev/null +++ b/publichealth/home/models/image_formats.py @@ -0,0 +1,17 @@ +# image_formats.py +from django.utils.html import format_html +from wagtail.images.formats import Format, register_image_format + + +class OriginalImageFormat(Format): + + def image_to_html(self, image, alt_text, extra_attributes=None): + + default_html = super().image_to_html(image, alt_text, extra_attributes) + + return format_html("{}", default_html, alt_text) + + +register_image_format( + OriginalImageFormat('original_fullwidth', 'Original image', 'bodytext-image', 'original') +) diff --git a/publichealth/home/models/models.py b/publichealth/home/models/models.py index 7853dd2..1ad4c20 100644 --- a/publichealth/home/models/models.py +++ b/publichealth/home/models/models.py @@ -2,6 +2,8 @@ from __future__ import unicode_literals +import datetime + from django.db import models from django.utils import translation from django.conf import settings @@ -15,6 +17,7 @@ from wagtail.admin.edit_handlers import FieldPanel, StreamFieldPanel, InlinePane from wagtail.images.blocks import ImageChooserBlock from wagtail.images.edit_handlers import ImageChooserPanel from wagtail.search import index +from wagtail.contrib.table_block.blocks import TableBlock from puput.models import EntryPage, BlogPage from feedler.models import Entry, Stream @@ -38,6 +41,13 @@ class ArticleIndexPage(Page): 'title_en', ) + header_image = models.ForeignKey( + 'wagtailimages.Image', + null=True, blank=True, + on_delete=models.SET_NULL, + related_name='+' + ) + intro_de = RichTextField(default='', blank=True) intro_fr = RichTextField(default='', blank=True) intro_en = RichTextField(default='', blank=True) @@ -47,6 +57,34 @@ class ArticleIndexPage(Page): 'intro_en', ) + table_en = StreamField( + [ + ('table_en', TableBlock(template='home/program_table.html')) + ], + null=True, + blank=True, + ) + table_de = StreamField( + [ + ('table_de', TableBlock(template='home/program_table.html')) + ], + null=True, + blank=True, + ) + table_fr = StreamField( + [ + ('table_fr', TableBlock(template='home/program_table.html')) + ], + null=True, + blank=True, + ) + + trans_table = TranslatedField( + 'table_de', + 'table_fr', + 'table_en', + ) + subscribe_label_de = models.CharField("Button Label (de)", default='', blank=True, max_length=250) subscribe_label_fr = models.CharField("Button Label (fr)", default='', blank=True, max_length=250) subscribe_label_en = models.CharField("Button Label (en)", default='', blank=True, max_length=250) @@ -71,6 +109,10 @@ class ArticleIndexPage(Page): FieldPanel('intro_fr'), FieldPanel('title_en'), FieldPanel('intro_en'), + ImageChooserPanel('header_image'), + FieldPanel('table_en'), + FieldPanel('table_fr'), + FieldPanel('table_de'), ImageChooserPanel('feed_image'), MultiFieldPanel( [ @@ -320,7 +362,9 @@ class HomePage(Page): @property def newsentries(self): # Get the last few news entries for the home page - entries = Entry.objects.all().order_by('-published') + entries = Entry.objects.filter( + models.Q(expire_at__isnull=True) | models.Q(expire_at__gt=datetime.datetime.now()) + ).all().order_by('-published') # Filter out by current language curlang = translation.get_language() if curlang in ['de']: diff --git a/publichealth/home/templates/home/article_index_page.html b/publichealth/home/templates/home/article_index_page.html index 6cd4cca..7b878cb 100644 --- a/publichealth/home/templates/home/article_index_page.html +++ b/publichealth/home/templates/home/article_index_page.html @@ -16,7 +16,18 @@ {% else %} + {% if page.header_image %} + {% image page.header_image fill-1908x400 as img %} +
+ {% endif %}+ {% if column.strip %} + {% if html_renderer %} + {{ column.strip|safe|linebreaksbr }} + {% else %} + {{ column.strip|linebreaksbr }} + {% endif %} + {% endif %} + | + {% endfor %} +|
---|---|
+ {% if column.strip %} + {% if html_renderer %} + {{ column.strip|safe|linebreaksbr }} + {% else %} + {{ column.strip|linebreaksbr }} + {% endif %} + {% endif %} + | + {% else %} ++ {% if column.strip %} + {% if html_renderer %} + {{ column.strip|safe|linebreaksbr }} + {% else %} + {{ column.strip|linebreaksbr }} + {% endif %} + {% endif %} + | + {% endif %} + {% endfor %} +