Skip to content

Commit 20c406a

Browse files
committed
Add setting, initial version for template
1 parent d9677ce commit 20c406a

4 files changed

Lines changed: 51 additions & 12 deletions

File tree

src/onegov/org/forms/settings.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,6 +1387,15 @@ class NewsletterSettingsForm(Form):
13871387
default=False
13881388
)
13891389

1390+
show_news_as_tiles = BooleanField(
1391+
label=_('Show news as tiles'),
1392+
description=_(
1393+
'If checked, news are displayed as tiles. Otherwise, '
1394+
'news are listed in full length.'),
1395+
fieldset=_('Automatic newsletters'),
1396+
default=True
1397+
)
1398+
13901399
newsletter_times = TagsField(
13911400
label=_('Newsletter sending times (24h format)'),
13921401
fieldset=_('Automatic newsletters'),

src/onegov/org/models/organisation.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,8 @@ class Organisation(Base, TimestampMixin):
255255
notify_on_unsubscription: dict_property[list[str] | None] = meta_property()
256256
enable_automatic_newsletters: dict_property[bool] = meta_property(
257257
default=False)
258+
# News in automatic newsletters shall be shown as tiles
259+
show_news_as_tiles: dict_property[bool] = meta_property(default=True)
258260
newsletter_times: dict_property[list[str] | None] = meta_property()
259261

260262
# Chat Settings

src/onegov/org/templates/mail_newsletter.pt

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<tal:b condition="news">
1010
<h2 i18n:translate>Latest news</h2>
1111

12-
<tal:b repeat="item news">
12+
<tal:b repeat="item news" tal:condition="not: request.app.org.show_news_as_tiles|False">
1313
<strong><a href="${request.link(item)}">${item.title}</a></strong>
1414
<tal:b tal:switch="item.text_in_newsletter">
1515
<tal:b tal:case="False">
@@ -18,7 +18,25 @@
1818
<tal:b tal:case="True" tal:content="item.text">
1919
</tal:b>
2020
</tal:b>
21-
21+
</tal:b>
22+
<tal:b tal:condition="request.app.org.show_news_as_tiles|False and news">
23+
<div class="newslist" tal:condition="news">
24+
<div class="row">
25+
<div class="small-12 columns news-list-item" tal:repeat="item news">
26+
<hr>
27+
<div class="row">
28+
<div class="small-12 medium-6 columns">
29+
<div tal:condition="item.page_image and item.show_preview_image" style="width: 100%; padding-bottom: 50%; background-image: url(${item.page_image}); background-size: cover;"></div>
30+
</div>
31+
</div>
32+
<a tal:attributes="href request.link(item)">
33+
<h2 tal:condition="heading == 'h2'|True">${item.title}</h2>
34+
</a>
35+
<p class="news-date" tal:condition="not:hide_date|False">${layout.format_date(item.published_or_created, 'relative')}</p>
36+
<p class="news-lead">${item.lead}</p>
37+
</div>
38+
</div>
39+
</div>
2240
</tal:b>
2341
</tal:b>
2442

tests/onegov/org/test_cronjobs.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,7 @@ def test_send_daily_newsletter(es_org_app):
779779

780780
session = org_app.session()
781781
org_app.org.enable_automatic_newsletters = True
782+
org_app.org.show_news_as_tiles = False
782783
org_app.org.newsletter_times = '10', '11', '16'
783784

784785
news = PageCollection(session)
@@ -805,11 +806,15 @@ def test_send_daily_newsletter(es_org_app):
805806
with freeze_time(datetime(2018, 3, 5, 10, 0, tzinfo=tz)):
806807
# Created today at 10:00, published immediately
807808
news.add(
808-
parent=news_parent, title='News3', type='news', access='public')
809+
parent=news_parent, title='News3', type='news', access='public',
810+
lead='Lead of News 3',
811+
)
809812
# Created today at 10:00, published today 10:01
810813
news.add(
811814
parent=news_parent, title='News4', type='news', access='public',
812-
publication_start=utcnow() + timedelta(minutes=1))
815+
publication_start=utcnow() + timedelta(minutes=1),
816+
lead='Lead of News 4',
817+
)
813818

814819
transaction.commit()
815820

@@ -823,10 +828,13 @@ def test_send_daily_newsletter(es_org_app):
823828
assert newsletter.title == 'Täglicher Newsletter 05.03.2018, 10:00'
824829
assert len(os.listdir(client.app.maildir)) == 1
825830
mail = client.get_email(0)
826-
assert "News1" in mail['TextBody']
827-
assert "News2" in mail['TextBody']
828-
assert "News3" not in mail['TextBody']
829-
assert "News4" not in mail['TextBody']
831+
assert 'News1' in mail['TextBody']
832+
assert 'News2' in mail['TextBody']
833+
assert 'News3' not in mail['TextBody']
834+
assert 'News4' not in mail['TextBody']
835+
836+
org_app.org.show_news_as_tiles = True
837+
transaction.commit()
830838

831839
with freeze_time(datetime(2018, 3, 5, 11, 0, tzinfo=tz)):
832840
client.get(get_cronjob_url(job))
@@ -836,10 +844,12 @@ def test_send_daily_newsletter(es_org_app):
836844
assert 'Täglicher Newsletter 05.03.2018, 11:00' in newsletter.title
837845
assert len(os.listdir(client.app.maildir)) == 2
838846
mail = client.get_email(1)
839-
assert "News1" not in mail['TextBody']
840-
assert "News2" not in mail['TextBody']
841-
assert "News3" in mail['TextBody']
842-
assert "News4" in mail['TextBody']
847+
assert 'News1' not in mail['TextBody']
848+
assert 'News2' not in mail['TextBody']
849+
assert 'News3' in mail['TextBody']
850+
assert 'Lead of News 3' in mail['TextBody']
851+
assert 'News4' in mail['TextBody']
852+
assert 'Lead of News 4' in mail['TextBody']
843853

844854
with freeze_time(datetime(2018, 3, 5, 16, 0, tzinfo=tz)):
845855
client.get(get_cronjob_url(job))

0 commit comments

Comments
 (0)