Merge remote-tracking branch 'origin/master' into pro-salute

This commit is contained in:
PCoder 2024-05-22 22:24:03 +05:30
commit d24fcd7d86
14 changed files with 210 additions and 7 deletions

View file

@ -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

View file

@ -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'),
),
]

View file

@ -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

View file

@ -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),
),
]

View file

@ -2,3 +2,4 @@ from .forms import *
from .models import *
from .snippets import *
from .admin import *
from .image_formats import *

View file

@ -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')
)

View file

@ -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']:

View file

@ -16,7 +16,18 @@
</section>
{% else %}
{% if page.header_image %}
{% image page.header_image fill-1908x400 as img %}
<div id="carousel-banner" class="slide">
<div class="carousel-inner slick slick-initialized slick-slider" role="listbox">
<div class="slick-list draggable" tabindex="0"><div class="slick-track" style="opacity: 1; width: 1908px;"><div class="item slick-slide slick-active" data-slick-index="0" style="width: 1908px; position: relative; left: 0px; top: 0px; z-index: 900; opacity: 1;">
<img style="background-image:url({{img.url}})">
</div></div></div>
</div>
</div>
{% endif %}
<section id="article-index" class="article-index-page">
<div class="container">
<h2>{{ page.trans_title }}</h2>
@ -34,6 +45,14 @@
</div>
{% endfor %}
</div>
<!-- Table content -->
<div class="article-table table-program" role="main">
{% for block in page.trans_table %}
{% if block.block_type == 'table_en' or block.block_type == 'table_fr' or block.block_type == 'table_de' %}
{% include_block block %}
{% endif %}
{% endfor %}
</div>
</div><!-- /container -->
</section>

View file

@ -0,0 +1,53 @@
<style>
.table-program td, th {
padding: 0 10px !important;
}
</style>
<table class="table-program">
{% if table_header %}
<thead>
<tr>
{% for column in table_header %}
<th>
{% if column.strip %}
{% if html_renderer %}
{{ column.strip|safe|linebreaksbr }}
{% else %}
{{ column.strip|linebreaksbr }}
{% endif %}
{% endif %}
</th>
{% endfor %}
</tr>
</thead>
{% endif %}
<tbody>
{% for row in data %}
<tr>
{% for column in row %}
{% if first_col_is_header and forloop.first %}
<th>
{% if column.strip %}
{% if html_renderer %}
{{ column.strip|safe|linebreaksbr }}
{% else %}
{{ column.strip|linebreaksbr }}
{% endif %}
{% endif %}
</th>
{% else %}
<td>
{% if column.strip %}
{% if html_renderer %}
{{ column.strip|safe|linebreaksbr }}
{% else %}
{{ column.strip|linebreaksbr }}
{% endif %}
{% endif %}
</td>
{% endif %}
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>

View file

@ -3,6 +3,6 @@
<ul class="dropdown-menu">
<!--<li><a href="{% pageurl parent %}">{{ parent.title }}</a></li>-->
{% for child in menuitems_children %}
<li><a href="{% pageurl child %}">{{ child.title|title }}</a></li>
<li><a href="{% pageurl child %}">{{ child.title }}</a></li>
{% endfor %}
</ul>

View file

@ -78,7 +78,7 @@ def menuitems_children(parent):
for menuitem in menuitems_children:
try:
if type(menuitem) == ContactForm:
menuitem.title = menuitem.title.title()
menuitem.title = menuitem.title
else:
menuitem.title = menuitem.trans_title
if 'devenez' in menuitem.title.lower() and remove_devenez:

View file

@ -44,6 +44,7 @@ INSTALLED_APPS = [
'wagtail.contrib.redirects',
'wagtail.contrib.search_promotions',
"wagtail.contrib.legacy.richtext",
'wagtail.contrib.table_block',
'wagtail.embeds',
'wagtail.sites',

View file

@ -10,7 +10,7 @@
// Language menu hack, until this is configurable
nav .language-nav a[lang='en'] { display: inline; }
#footer, .contact-nav .link { display: none; }
//#footer, .contact-nav .link { display: none; }
a.navbar-brand {
height: 60px;

View file

@ -32,7 +32,7 @@
<div class="copyright">
{% contact_name the_site=the_site %}
&copy; 2020
&copy; 2022
&bull; <a href="https://public-health.ch/privacy/">Privacy</a>
&bull; <a href="https://public-health.ch/impressum/">Impressum</a>
</div>