Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/onegov/org/forms/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -1387,6 +1387,15 @@ class NewsletterSettingsForm(Form):
default=False
)

show_news_as_tiles = BooleanField(
label=_('Show news as tiles'),
description=_(
'If checked, news are displayed as tiles. Otherwise, '
'news are listed in full length.'),
fieldset=_('Automatic newsletters'),
default=True
)

newsletter_times = TagsField(
label=_('Newsletter sending times (24h format)'),
fieldset=_('Automatic newsletters'),
Expand Down
2 changes: 2 additions & 0 deletions src/onegov/org/models/organisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ class Organisation(Base, TimestampMixin):
notify_on_unsubscription: dict_property[list[str] | None] = meta_property()
enable_automatic_newsletters: dict_property[bool] = meta_property(
default=False)
# News in automatic newsletters shall be shown as tiles
show_news_as_tiles: dict_property[bool] = meta_property(default=True)
newsletter_times: dict_property[list[str] | None] = meta_property()

# Chat Settings
Expand Down
22 changes: 20 additions & 2 deletions src/onegov/org/templates/mail_newsletter.pt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<tal:b condition="news">
<h2 i18n:translate>Latest news</h2>

<tal:b repeat="item news">
<tal:b repeat="item news" tal:condition="not: request.app.org.show_news_as_tiles|False">
<strong><a href="${request.link(item)}">${item.title}</a></strong>
<tal:b tal:switch="item.text_in_newsletter">
<tal:b tal:case="False">
Expand All @@ -18,7 +18,25 @@
<tal:b tal:case="True" tal:content="item.text">
</tal:b>
</tal:b>

</tal:b>
<tal:b tal:condition="request.app.org.show_news_as_tiles|False and news">
<div class="newslist" tal:condition="news">
<div class="row">
<div class="small-12 columns news-list-item" tal:repeat="item news">
<hr>
<div class="row">
<div class="small-12 medium-6 columns">
<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>
</div>
</div>
<a tal:attributes="href request.link(item)">
<h2 tal:condition="heading == 'h2'|True">${item.title}</h2>
</a>
<p class="news-date" tal:condition="not:hide_date|False">${layout.format_date(item.published_or_created, 'relative')}</p>
<p class="news-lead">${item.lead}</p>
</div>
</div>
</div>
</tal:b>
</tal:b>

Expand Down
30 changes: 20 additions & 10 deletions tests/onegov/org/test_cronjobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,7 @@ def test_send_daily_newsletter(es_org_app):

session = org_app.session()
org_app.org.enable_automatic_newsletters = True
org_app.org.show_news_as_tiles = False
org_app.org.newsletter_times = '10', '11', '16'

news = PageCollection(session)
Expand All @@ -805,11 +806,15 @@ def test_send_daily_newsletter(es_org_app):
with freeze_time(datetime(2018, 3, 5, 10, 0, tzinfo=tz)):
# Created today at 10:00, published immediately
news.add(
parent=news_parent, title='News3', type='news', access='public')
parent=news_parent, title='News3', type='news', access='public',
lead='Lead of News 3',
)
# Created today at 10:00, published today 10:01
news.add(
parent=news_parent, title='News4', type='news', access='public',
publication_start=utcnow() + timedelta(minutes=1))
publication_start=utcnow() + timedelta(minutes=1),
lead='Lead of News 4',
)

transaction.commit()

Expand All @@ -823,10 +828,13 @@ def test_send_daily_newsletter(es_org_app):
assert newsletter.title == 'Täglicher Newsletter 05.03.2018, 10:00'
assert len(os.listdir(client.app.maildir)) == 1
mail = client.get_email(0)
assert "News1" in mail['TextBody']
assert "News2" in mail['TextBody']
assert "News3" not in mail['TextBody']
assert "News4" not in mail['TextBody']
assert 'News1' in mail['TextBody']
assert 'News2' in mail['TextBody']
assert 'News3' not in mail['TextBody']
assert 'News4' not in mail['TextBody']

org_app.org.show_news_as_tiles = True
transaction.commit()

with freeze_time(datetime(2018, 3, 5, 11, 0, tzinfo=tz)):
client.get(get_cronjob_url(job))
Expand All @@ -836,10 +844,12 @@ def test_send_daily_newsletter(es_org_app):
assert 'Täglicher Newsletter 05.03.2018, 11:00' in newsletter.title
assert len(os.listdir(client.app.maildir)) == 2
mail = client.get_email(1)
assert "News1" not in mail['TextBody']
assert "News2" not in mail['TextBody']
assert "News3" in mail['TextBody']
assert "News4" in mail['TextBody']
assert 'News1' not in mail['TextBody']
assert 'News2' not in mail['TextBody']
assert 'News3' in mail['TextBody']
assert 'Lead of News 3' in mail['TextBody']
assert 'News4' in mail['TextBody']
assert 'Lead of News 4' in mail['TextBody']

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