Skip to content

Commit

Permalink
notifications: group notifications for each patron
Browse files Browse the repository at this point in the history
* Groups notifications through a dispach process.
* Adds a CLI to display time stamp monitoring.
* Fixes different pickup locations for availability notifications.
* Closes #1236.

Co-Authored-by: Peter Weber <peter.weber@rero.ch>
  • Loading branch information
rerowep and rerowep committed May 10, 2021
1 parent d54c20f commit a5cfe91
Show file tree
Hide file tree
Showing 41 changed files with 693 additions and 391 deletions.
66 changes: 41 additions & 25 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ freezegun = "^1.1.0"
lazyreader = ">1.0.0"
jinja2 = ">2.11.2"
jsonmerge = "^1.8.0"
num2word = "^1.0.1"
num2words = "^0.5.10"

[tool.poetry.dev-dependencies]
## Python packages development dependencies (order matters)
Expand Down
34 changes: 34 additions & 0 deletions rero_ils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ def _(x):
SUPPORT_EMAIL = "software@rero.ch"
#: Disable email sending by default.
MAIL_SUPPRESS_SEND = True
#: Default sender email
DEFAULT_SENDER_EMAIL = "noreply@rero.ch"

# Assets
# ======
Expand Down Expand Up @@ -307,6 +309,38 @@ def _(x):
'enabled': False,
# TODO: in production set this up once a day
},
'notification-dispatch-due_soon': {
'task': 'rero_ils.modules.notifications.tasks.process_notifications',
'schedule': crontab(minute="*/15"),
'kwargs': {
'notification_type': Notification.DUE_SOON_NOTIFICATION_TYPE
},
'enabled': False,
},
'notification-dispatch-overdue': {
'task': 'rero_ils.modules.notifications.tasks.process_notifications',
'schedule': timedelta(minutes=15),
'kwargs': {
'notification_type': Notification.OVERDUE_NOTIFICATION_TYPE
},
'enabled': False,
},
'notification-dispatch-availability': {
'task': 'rero_ils.modules.notifications.tasks.process_notifications',
'schedule': timedelta(minutes=15),
'kwargs': {
'notification_type': Notification.AVAILABILITY_NOTIFICATION_TYPE
},
'enabled': False,
},
'notification-dispatch-recall': {
'task': 'rero_ils.modules.notifications.tasks.process_notifications',
'schedule': timedelta(minutes=15),
'kwargs': {
'notification_type': Notification.RECALL_NOTIFICATION_TYPE
},
'enabled': False,
},
'claims-creation': {
'task': ('rero_ils.modules.items.tasks'
'.process_late_claimed_issues'),
Expand Down
23 changes: 12 additions & 11 deletions rero_ils/modules/libraries/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,17 +333,6 @@ def get_timezone(self):
default = pytz.timezone('Europe/Zurich')
return default

def email_notification_type(self, notification_type):
"""Get the email corresponding to the given notification type.
:param notification_type: the notification type.
:return: the email corresponding to the notification type.
:rtype: string
"""
for setting in self['notification_settings']:
if setting['type'] == notification_type:
return setting['email']


class LibrariesIndexer(IlsRecordsIndexer):
"""Holdings indexing class."""
Expand All @@ -356,3 +345,15 @@ def bulk_index(self, record_id_iterator):
:param record_id_iterator: Iterator yielding record UUIDs.
"""
super().bulk_index(record_id_iterator, doc_type='lib')


def email_notification_type(libray, notification_type):
"""Get the email corresponding to the given notification type.
:param notification_type: the notification type.
:return: the email corresponding to the notification type.
:rtype: string
"""
for setting in libray['notification_settings']:
if setting['type'] == notification_type:
return setting['email']
9 changes: 2 additions & 7 deletions rero_ils/modules/loans/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def check_required_params(self, action, **kwargs):
required_params = self.action_required_params(action=action)
missing_params = set(required_params) - set(kwargs)
if missing_params:
message = 'Parameters {} are required'.format(missing_params)
message = f'Parameters {missing_params} are required'
raise MissingRequiredParameterError(description=message)

def update_pickup_location(self, pickup_location_pid):
Expand Down Expand Up @@ -574,12 +574,7 @@ def create_notification(self, notification_type=None, counter=0):
}
notification = Notification.create(
data=record, dbcommit=True, reindex=True)
enqueue = notification_type not in [
Notification.RECALL_NOTIFICATION_TYPE,
Notification.AVAILABILITY_NOTIFICATION_TYPE
]
# put into the queue only for batch notifications i.e. overdue
return notification.dispatch(enqueue=enqueue)
return notification

@classmethod
def concluded(cls, loan):
Expand Down
Loading

0 comments on commit a5cfe91

Please sign in to comment.