Skip to content

Commit

Permalink
Process e-mail layout remarks
Browse files Browse the repository at this point in the history
  • Loading branch information
sergei-maertens committed Sep 18, 2016
1 parent 479e0f8 commit d5b32fa
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 53 deletions.
3 changes: 2 additions & 1 deletion src/langerak_gkv/liturgies/admin/__init__.py
Expand Up @@ -79,7 +79,7 @@ def response_change(self, request, obj):

def _send_mail(self, obj, recipients):
subject = 'Liturgie kerkdienst'
body = render_to_string('liturgies/mail.html', {'liturgies': [obj]})
body = render_to_string('liturgies/mail.html', {'liturgies': [obj], 'single': True})
template = MailTemplate.objects.filter(template_type=Templates.liturgy).first()
if template is not None:
extra_churches = ', '.join(list(obj.other_churches.values_list('name', flat=True)))
Expand All @@ -89,6 +89,7 @@ def _send_mail(self, obj, recipients):
'liturgy_details': mark_safe(body),
'extra_churches': '+ {}'.format(extra_churches) if extra_churches else '',
'datetime': '{}, {}'.format(date(obj.date, 'l j F'), time(obj.service.time, 'H.i')),
'part_of_day': obj.part_of_day,
})

initial = {
Expand Down
14 changes: 14 additions & 0 deletions src/langerak_gkv/liturgies/models.py
Expand Up @@ -66,6 +66,20 @@ def get_collections(self):
collections.append(self.collection_goal3)
return collections

@property
def part_of_day(self):
"""
Returns the string representation of the part of the day when the liturgy happens.
E.g. 'morning', 'afternoon', 'evening'
"""
service_time = self.service.time
if service_time.hour < 12:
return _('morning')
elif service_time.hour < 17:
return _('afternoon')
return _('evening')


class Service(models.Model):
name = models.CharField(_('service name'), max_length=50)
Expand Down
49 changes: 25 additions & 24 deletions src/langerak_gkv/liturgies/templates/liturgies/mail.html
Expand Up @@ -7,42 +7,43 @@
</head>

<body>

<h1>{% trans "Liturgies" %}</h1>
{% for liturgy in liturgies %}
<div style="padding-top: 10px;padding-bottom:10px; border-bottom: solid 2px grey;">
<h2>{% blocktrans with counter=forloop.counter %}Liturgy {{ counter }}{% endblocktrans %}</h2>
{% if not single %}
<h1>{% blocktrans with counter=forloop.counter %}Liturgy {{ counter }}{% endblocktrans %}</h1>
{% endif %}

<h3>{% trans "Date" %}</h3>
<p>{{ liturgy.date|date:"l j F" }}</p>
<h3 style="margin-bottom: 0;">{% trans "Date" %}</h3>
<p style="margin-top: 0;">{{ liturgy.date|date:"l j F" }}</p>

<h3>{% trans "Service" %}</h3>
<p>{{ liturgy.service.name }}, {{ liturgy.service.time|time:"H:i" }}</p>
<h3 style="margin-bottom: 0;">{% trans "Service" %}</h3>
<p style="margin-top: 0;">{{ liturgy.service.name }}</p>

<h3>{% trans "Preacher" %}</h3>
<p>{{ liturgy.preacher }} ({{ liturgy.preach_authorer|default:_('no author') }})</p>
<h3 style="margin-bottom: 0;">{% trans "Preacher" %}</h3>
<p style="margin-top: 0;">{{ liturgy.preacher }}</p>

<h3>{% trans "Liturgy" %}</h3>
<p>{{ liturgy.liturgy|default:_('(empty)')|linebreaksbr }}</p>
<h3 style="margin-bottom: 0;">{% trans "Liturgy" %}</h3>
<p style="margin-top: 0;">{{ liturgy.liturgy|default:_('(empty)')|linebreaksbr }}</p>

{% comment %}
<h3>{% trans "Collections" %}</h3>
<p>{{ liturgy.get_collections|join:', '|default:_('(none)') }}</p>
<h3 style="margin-bottom: 0;">{% trans "Service theme" %}</h3>
<p style="margin-top: 0;">{{ liturgy.service_theme|default:_('(empty)') }}</p>

<h3>{% trans "Main section" %}</h3>
<p>{{ liturgy.main_section|default:_('(empty)') }}</p>
{% comment %}
<h3 style="margin-bottom: 0;">{% trans "Collections" %}</h3>
<p style="margin-top: 0;">{{ liturgy.get_collections|join:', '|default:_('(none)') }}</p>

<h3>{% trans "Service theme" %}</h3>
<p>{{ liturgy.service_theme|default:_('(empty)') }}</p>
<h3 style="margin-bottom: 0;">{% trans "Main section" %}</h3>
<p style="margin-top: 0;">{{ liturgy.main_section|default:_('(empty)') }}</p>
{% endcomment %}
<h3>{% trans "Remarks" %}</h3>
<p>{{ liturgy.internal_remarks|default:_('(empty)')|linebreaksbr }}</p>

<h3>{% trans "Organist" %}</h3>
<p>{{ liturgy.organist|default:_('(empty)') }}</p>
<h3 style="margin-bottom: 0;">{% trans "Remarks" %}</h3>
<p style="margin-top: 0;">{{ liturgy.internal_remarks|default:_('(empty)')|linebreaksbr }}</p>

<h3 style="margin-bottom: 0;">{% trans "Organist" %}</h3>
<p style="margin-top: 0;">{{ liturgy.organist|default:_('(empty)') }}</p>

<h3>{% trans "Beamist" %}</h3>
<p>{{ liturgy.beamist|default:_('(empty)') }}</p>
<h3 style="margin-bottom: 0;">{% trans "Beamist" %}</h3>
<p style="margin-top: 0;">{{ liturgy.beamist|default:_('(empty)') }}</p>
</div>
{% endfor %}
</body>
Expand Down
20 changes: 20 additions & 0 deletions src/langerak_gkv/liturgies/tests/test_liturgy_model.py
@@ -0,0 +1,20 @@
from datetime import time

from django.test import TestCase
from django.utils.translation import ugettext as _

from .factories import LiturgyFactory


class LiturgyTests(TestCase):

def test_part_of_day(self):
liturgy1 = LiturgyFactory.build(service__time=time(9, 30))
liturgy2 = LiturgyFactory.build(service__time=time(11, 30))
liturgy3 = LiturgyFactory.build(service__time=time(16, 00))
liturgy4 = LiturgyFactory.build(service__time=time(17, 00))

self.assertEqual(liturgy1.part_of_day, _('morning'))
self.assertEqual(liturgy2.part_of_day, _('morning'))
self.assertEqual(liturgy3.part_of_day, _('afternoon'))
self.assertEqual(liturgy4.part_of_day, _('evening'))
Binary file modified src/langerak_gkv/locale/nl/LC_MESSAGES/django.mo
Binary file not shown.
65 changes: 38 additions & 27 deletions src/langerak_gkv/locale/nl/LC_MESSAGES/django.po
Expand Up @@ -8,8 +8,8 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-09-08 15:17+0200\n"
"PO-Revision-Date: 2016-09-08 15:18+0020\n"
"POT-Creation-Date: 2016-09-18 14:18+0200\n"
"PO-Revision-Date: 2016-09-18 14:18+0020\n"
"Last-Translator: Sergei Maertens <sergeimaertens@gmail.com>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
Expand Down Expand Up @@ -378,7 +378,7 @@ msgid "The email has been put on the queue and will be send shortly"
msgstr ""
"De e-mail werd op de wachtlijst geplaatst en zal binnenkort verstuurd worden"

#: liturgies/admin/__init__.py:107
#: liturgies/admin/__init__.py:108
msgid "view email recipients"
msgstr "bekijk e-mail ontvangers"

Expand All @@ -400,7 +400,6 @@ msgid "liturgies"
msgstr "kerkdiensten"

#: liturgies/cms_app.py:10 liturgies/templates/liturgies/mail.html:6
#: liturgies/templates/liturgies/mail.html:11
msgid "Liturgies"
msgstr "Kerkdiensten"

Expand Down Expand Up @@ -440,7 +439,7 @@ msgstr "hoofdvers"
msgid "service theme"
msgstr "theme dienst"

#: liturgies/models.py:27 liturgies/models.py:41 liturgies/models.py:87
#: liturgies/models.py:27 liturgies/models.py:41 liturgies/models.py:101
#: liturgies/signals.py:16
msgid "liturgy"
msgstr "kerkdienst"
Expand Down Expand Up @@ -481,35 +480,48 @@ msgstr "andere kerken"
msgid "remarks (internal)"
msgstr "opmerkingen (intern)"

#: liturgies/models.py:71
#: liturgies/models.py:78 liturgies/tests/test_liturgy_model.py:17
#: liturgies/tests/test_liturgy_model.py:18
msgid "morning"
msgstr "ochtend"

#: liturgies/models.py:80 liturgies/tests/test_liturgy_model.py:19
msgid "afternoon"
msgstr "namiddag"

#: liturgies/models.py:81 liturgies/tests/test_liturgy_model.py:20
msgid "evening"
msgstr "avond"

#: liturgies/models.py:85
msgid "service name"
msgstr "naam dienst"

#: liturgies/models.py:72
#: liturgies/models.py:86
msgid "service time"
msgstr "tijd dienst"

#: liturgies/models.py:81
#: liturgies/models.py:95
#, python-format
msgid "preacher (%s)"
msgstr "predikant (%s)"

#: liturgies/models.py:82
#: liturgies/models.py:96
#, python-format
msgid "organist (%s)"
msgstr "organist (%s)"

#: liturgies/models.py:83
#: liturgies/models.py:97
#, python-format
msgid "beamist (%s)"
msgstr "beamist (%s)"

#: liturgies/models.py:84
#: liturgies/models.py:98
#, python-format
msgid "koster (%s)"
msgstr "organist (%s)"

#: liturgies/models.py:85
#: liturgies/models.py:99
msgid "other"
msgstr "overige"

Expand Down Expand Up @@ -573,6 +585,7 @@ msgid "Main section"
msgstr "Hoofdgedeelte"

#: liturgies/templates/liturgies/detail.html:66
#: liturgies/templates/liturgies/mail.html:28
msgid "Service theme"
msgstr "Thema"

Expand Down Expand Up @@ -605,7 +618,7 @@ msgstr[1] ""
"\n"
"%(counter)s aankomend"

#: liturgies/templates/liturgies/mail.html:14
#: liturgies/templates/liturgies/mail.html:13
#, python-format
msgid "Liturgy %(counter)s"
msgstr "Kerkdienst %(counter)s"
Expand All @@ -618,33 +631,28 @@ msgstr "Datum"
msgid "Service"
msgstr "Dienst"

#: liturgies/templates/liturgies/mail.html:23
msgid "no author"
msgstr "geen auteur"

#: liturgies/templates/liturgies/mail.html:25 mailing/models.py:33
#: search/templates/search/liturgy_item.html:6
msgid "Liturgy"
msgstr "Kerkdienst"

#: liturgies/templates/liturgies/mail.html:26
#: liturgies/templates/liturgies/mail.html:40
#: liturgies/templates/liturgies/mail.html:43
#: liturgies/templates/liturgies/mail.html:46
#: liturgies/templates/liturgies/mail.html:29
#: liturgies/templates/liturgies/mail.html:41
#: liturgies/templates/liturgies/mail.html:44
#: liturgies/templates/liturgies/mail.html:47
msgid "(empty)"
msgstr "(leeg)"

#: liturgies/templates/liturgies/mail.html:39
#: liturgies/templates/liturgies/mail.html:40
msgid "Remarks"
msgstr "Opmerkingen"

#: liturgies/templates/liturgies/mail.html:42
#| msgid "organist"
#: liturgies/templates/liturgies/mail.html:43
msgid "Organist"
msgstr "Organist"

#: liturgies/templates/liturgies/mail.html:45
#| msgid "beamist"
#: liturgies/templates/liturgies/mail.html:46
msgid "Beamist"
msgstr "Beamist"

Expand Down Expand Up @@ -687,11 +695,11 @@ msgstr "inhoud"
msgid "Add the body with {{variable}} placeholders"
msgstr "Voeg de inhoudtekst toe met {{variable}} invulwaarden"

#: mailing/models.py:58
#: mailing/models.py:59
msgid "mail template"
msgstr "E-mail sjabloon"

#: mailing/models.py:59
#: mailing/models.py:60
msgid "mail templates"
msgstr "E-mail sjablonen"

Expand Down Expand Up @@ -1464,6 +1472,9 @@ msgstr "loglijn"
msgid "log entries"
msgstr "loglijnen"

#~ msgid "no author"
#~ msgstr "geen auteur"

#~ msgid "Collections"
#~ msgstr "Collectes"

Expand Down
3 changes: 2 additions & 1 deletion src/langerak_gkv/mailing/models.py
Expand Up @@ -44,11 +44,12 @@ class MailTemplate(models.Model):
Templates.liturgy: {
'subject': [
Variable('extra_churches'),
Variable('datetime')
Variable('datetime'),
],
'body': [
Variable('extra_churches'),
Variable('day'),
Variable('part_of_day'),
Variable('liturgy_details', required=True)
]
}
Expand Down

0 comments on commit d5b32fa

Please sign in to comment.