Skip to content

Commit

Permalink
notification templates: create templates by lang by type by channel
Browse files Browse the repository at this point in the history
* Adds templates for the four types of notifications to the communication channel email

Co-Authored-by: Peter Weber <[email protected]>
Co-Authored-by: Aly Badr <[email protected]>
  • Loading branch information
Aly Badr and rerowep committed Jul 1, 2019
1 parent 0d06cbf commit 0a2abc2
Show file tree
Hide file tree
Showing 28 changed files with 321 additions and 51 deletions.
20 changes: 10 additions & 10 deletions data/users.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"postal_code": "11100",
"street": "Via Croix Noire 3",
"communication_channel": "email",
"communication_language": "it"
"communication_language": "ita"
},
{
"$schema": "https://ils.rero.ch/schema/patrons/patron-v0.0.1.json",
Expand All @@ -93,7 +93,7 @@
"postal_code": "11100",
"street": "Panoramica Collinare, 47",
"communication_channel": "email",
"communication_language": "it"
"communication_language": "ita"
},
{
"$schema": "https://ils.rero.ch/schema/patrons/patron-v0.0.1.json",
Expand Down Expand Up @@ -131,7 +131,7 @@
"postal_code": "1950",
"street": "Rue du Nord 7",
"communication_channel": "email",
"communication_language": "fr"
"communication_language": "fre"
},
{
"$schema": "https://ils.rero.ch/schema/patrons/patron-v0.0.1.json",
Expand All @@ -152,7 +152,7 @@
"postal_code": "95054",
"street": "520 Scott Blvd",
"communication_channel": "email",
"communication_language": "en"
"communication_language": "eng"
},
{
"$schema": "https://ils.rero.ch/schema/patrons/patron-v0.0.1.json",
Expand All @@ -173,7 +173,7 @@
"postal_code": "1892",
"street": "Route du Village 6",
"communication_channel": "email",
"communication_language": "fr"
"communication_language": "fre"
},
{
"$schema": "https://ils.rero.ch/schema/patrons/patron-v0.0.1.json",
Expand All @@ -194,7 +194,7 @@
"postal_code": "6500",
"street": "Piazza Collegiata 12",
"communication_channel": "email",
"communication_language": "it"
"communication_language": "ita"
},
{
"$schema": "https://ils.rero.ch/schema/patrons/patron-v0.0.1.json",
Expand All @@ -215,7 +215,7 @@
"postal_code": "1920",
"street": "Gare 45",
"communication_channel": "email",
"communication_language": "en"
"communication_language": "eng"
},
{
"$schema": "https://ils.rero.ch/schema/patrons/patron-v0.0.1.json",
Expand All @@ -236,7 +236,7 @@
"postal_code": "1926",
"street": "Vignettes 25",
"communication_channel": "email",
"communication_language": "de"
"communication_language": "ger"
},
{
"$schema": "https://ils.rero.ch/schema/patrons/patron-v0.0.1.json",
Expand Down Expand Up @@ -275,7 +275,7 @@
"postal_code": "55555",
"street": "Magic Street 3",
"communication_channel": "email",
"communication_language": "en"
"communication_language": "eng"
},
{
"$schema": "https://ils.rero.ch/schema/patrons/patron-v0.0.1.json",
Expand All @@ -295,6 +295,6 @@
"postal_code": "55555",
"street": "Diagon Alley 72",
"communication_channel": "email",
"communication_language": "en"
"communication_language": "eng"
}
]
1 change: 0 additions & 1 deletion rero_ils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,6 @@ def _(x):
'notif': '/notifications/notification-v0.0.1.json',
}


# Login Configuration
# ===================
#: Allow password change by users.
Expand Down
2 changes: 1 addition & 1 deletion rero_ils/modules/items/api_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def decorated_view(*args, **kwargs):
except NotFound as e:
raise(e)
except Exception as e:
# raise(e)
raise(e)
return jsonify({'status': 'error: {error}'.format(error=e)}), 500
return decorated_view

Expand Down
11 changes: 10 additions & 1 deletion rero_ils/modules/notifications/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from __future__ import absolute_import, print_function

from copy import deepcopy
from datetime import datetime
from datetime import datetime, timedelta
from functools import partial

from invenio_search.api import RecordsSearch
Expand All @@ -37,6 +37,7 @@
from ..api import IlsRecord
from ..documents.api import Document
from ..fetchers import id_fetcher
from ..libraries.api import Library
from ..locations.api import Location
from ..minters import id_minter
from ..patrons.api import Patron
Expand Down Expand Up @@ -103,6 +104,14 @@ def replace_pids_and_refs(self):
data['loan']['pickup_location'] = \
pickup_location.replace_refs().dumps()
# del(data['loan']['pickup_location_pid'])
library_pid = data['loan']['pickup_location']['library']['pid']
library = Library.get_record_by_pid(library_pid)
data['loan']['pickup_location']['library'] = library
keep_until = datetime.now() + timedelta(days=10)
next_open = library.next_open(keep_until)
# language = data['loan']['patron']['communication_language']
next_open = next_open.strftime("%d-%b-%Y")
data['loan']['next_open'] = next_open
data['loan']['document'] = self.document.replace_refs().dumps()
# del(data['loan']['document_pid'])
return data
Expand Down
28 changes: 22 additions & 6 deletions rero_ils/modules/notifications/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

from __future__ import absolute_import, print_function

from flask import current_app
from flask_security.utils import config_value
from invenio_mail.api import TemplatedMessage
from invenio_mail.tasks import send_email
Expand All @@ -38,29 +39,44 @@ def dispatch_notification(self, notification=None):
"""Dispatch the notification."""
if notification:
data = notification.replace_pids_and_refs()
self.send_mail(data=data)
communication_channel = \
data['loan']['patron']['communication_channel']
if communication_channel == 'email':
self.send_mail(data=data)
if communication_channel == 'sms':
pass
if communication_channel == 'whatsapp':
pass
if communication_channel == 'letter':
pass
notification = notification.update_process_date()
return notification

def send_mail(self, data):
"""Send email."""
data['loan']['profile_url'] = \
'https://ils.test.rero.ch/patrons/profile'
notification_type = data.get('notification_type')
language = 'eng'
template = 'email/{type}_{lang}'.format(
language = data['loan']['patron']['communication_language']
template = 'email/{type}/{lang}'.format(
type=notification_type,
lang=language
)
recipient = data['loan']['patron']['email']
msg = TemplatedMessage(
# template_html='{template}.html'.format(template=template),
template_body='{template}.txt'.format(template=template),
subject=notification_type,
sender=config_value('EMAIL_SENDER'),
recipients=[recipient],
ctx=data['loan']
)

text = msg.body.split('\n')
msg.subject = text[0]
msg.body = '\n'.join(text[1:])
try:
send_email.delay(msg.__dict__)
send_email.run(msg.__dict__)
# TODO: investigate why delay does not work
# send_email.delay(msg.__dict__)
# current_app.extensions['mail'].send(msg)
except Exception as e:
raise(e)
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Invitation to pick up a document
Dear patron,

The document you requested is now available. You can pick it up at the loan desk of the library mentioned below.

Author: {{ document.authors[0].name }}
Title: {{ document.title }}
Pick up location: {{ pickup_location.name }}
To pick up until: {{ next_open }}

Should the document not be picked up within the given period, it will be made available for other people.
You can consult your account and extend the loan period of your documents at: {{ profile_url }}

Best regards

{{ pickup_location.library.name }}
{{ pickup_location.library.address }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Invitation à retirer un document
Chère lectrice, cher lecteur,

Le document que vous avez demandé est maintenant disponible. Vous pouvez venir le retirer au bureau de prêt de la bibliothèque mentionnée ci-dessous.

Auteur : {{ document.authors[0].name }}
Titre : {{ document.title }}
Lieu de retrait : {{ pickup_location.name }}
A retirer jusqu'au : {{ next_open }}

Si le document n'est pas retiré dans les délais, il sera remis en circulation pour d'autres personnes.
Vous pouvez consulter votre compte et prolonger la durée de prêt de vos documents à l'adresse : {{ profile_url }}

Avec nos compliments

{{ pickup_location.library.name }}
{{ pickup_location.library.address }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Abholeinladung
Sehr geehrte Leserin, sehr geehrter Leser,

Das von Ihnen bestellte Dokument ist nun verfügbar und kann an der Ausleihtheke der nachstehend genannten Bibliothek abgeholt werden.

Autor: {{ document.authors[0].name }}
Titel: {{ document.title }}
Abholort: {{ pickup_location.name }}
Abholen bis: {{ next_open }}

Wenn das Dokument innerhalb der gegebenen Frist nicht abgeholt wird, wird es anderen Personen zur Verfügung gestellt.
Unter folgender Adresse können Sie Ihr Konto einsehen und die Ausleihfrist Ihrer Dokumente verlängern: {{ profile_url }}

Freundliche Grüsse

{{ pickup_location.library.name }}
{{ pickup_location.library.address }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Invito a ritirare un documento
Cara lettrice, caro lettore,

Il documento che Lei ha domandato è ora disponibile. Lei può ritirarlo al servizio prestiti della biblioteca sotto indicata.

Autore: {{ document.authors[0].name }}
Titolo: {{ document.title }}
Punto di ritiro: {{ pickup_location.name }}
Ritirare entro: {{ next_open }}

Se il documento non è ritirato entro detto termine, esso sarà rimesso in circolazione per altre persone.
Lei può consultare il Suo conto et prorogare la durata di prestito dei Suoi documenti al seguente indirizzo: {{ profile_url }}

Cordiali saluti

{{ pickup_location.library.name }}
{{ pickup_location.library.address }}

This file was deleted.

16 changes: 16 additions & 0 deletions rero_ils/modules/notifications/templates/email/due_soon/eng.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Expiry notice
Dear patron,

The loan period of following documents is expiring:

Author: {{ document.authors[0].name }}
Title: {{ document.title }}
Due date: {{ end_date }}
Note: Non extendable

You can consult your account and extend the loan period of your documents at: {{ profile_url }}

Best regards

{{ pickup_location.library.name }}
{{ pickup_location.library.address }}
16 changes: 16 additions & 0 deletions rero_ils/modules/notifications/templates/email/due_soon/fre.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Avis d'échéance
Chère lectrice, cher lecteur,

Le délai de prêt des documents mentionnés ci-dessous arrive à échéance :

Auteur : {{ document.authors[0].name }}
Titre : {{ document.title }}
Echéance : {{ end_date }}
Note : Non extendable

Vous pouvez consulter votre compte et prolonger la durée de prêt de vos documents à l'adresse : {{ profile_url }}

Avec nos compliments

{{ pickup_location.library.name }}
{{ pickup_location.library.address }}
16 changes: 16 additions & 0 deletions rero_ils/modules/notifications/templates/email/due_soon/ger.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Ablauf der Ausleihfrist
Sehr geehrte Leserin, sehr geehrter Leser,

Die Ausleihfrist der folgenden Dokumente läuft ab:

Autor: {{ document.authors[0].name }}
Titel: {{ document.title }}
Rückgabedatum: {{ end_date }}
Anmerkung: Non extendable

Unter folgender Adresse können Sie Ihr Konto einsehen und die Ausleihfrist Ihrer Dokumente verlängern: {{ profile_url }}

Freundliche Grüsse

{{ pickup_location.library.name }}
{{ pickup_location.library.address }}
16 changes: 16 additions & 0 deletions rero_ils/modules/notifications/templates/email/due_soon/ita.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Avviso di scadenza
Cara lettrice, caro lettore,

La durata di prestito dei seguenti documenti sta per scadere:

Autore: {{ document.authors[0].name }}
Titolo: {{ document.title }}
Scadenza: {{ end_date }}
Nota: Non extendable

Lei può consultare il Suo conto et prorogare la durata di prestito dei Suoi documenti al seguente indirizzo: {{ profile_url }}

Cordiali saluti

{{ pickup_location.library.name }}
{{ pickup_location.library.address }}

This file was deleted.

16 changes: 16 additions & 0 deletions rero_ils/modules/notifications/templates/email/overdue/eng.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
1st reminder
Dear patron,

The loan period of following documents has expired:

Author: {{ document.authors[0].name }}
Title: {{ document.title }}
Due date: {{ end_date }}
Note: 1st reminder

You can consult your account and extend the loan period of your documents at: {{ profile_url }}

Best regards

{{ pickup_location.library.name }}
{{ pickup_location.library.address }}
16 changes: 16 additions & 0 deletions rero_ils/modules/notifications/templates/email/overdue/fre.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
1er rappel
Chère lectrice, cher lecteur,

La durée du prêt des documents mentionnés ci-dessous est échue :

Auteur : {{ document.authors[0].name }}
Titre : {{ document.title }}
Echéance : {{ end_date }}
Note : 1er rappel

Vous pouvez consulter votre compte et prolonger la durée de prêt de vos documents à l'adresse : {{ profile_url }}

Avec nos complimen

{{ pickup_location.library.name }}
{{ pickup_location.library.address }}
Loading

0 comments on commit 0a2abc2

Please sign in to comment.