From 48306e8c6372a0f1be85639a74914db01f6a2821 Mon Sep 17 00:00:00 2001 From: Chris Topaloudis Date: Thu, 2 Aug 2018 11:50:20 +0200 Subject: [PATCH] loan: notifications #52 Implements #52 and resolves user story #24. On after method of a transition we fire a signal with the class that was triggered and the loan that was affected. --- invenio_circulation/signals.py | 19 +++++++++++++++++++ invenio_circulation/transitions/base.py | 4 +++- 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 invenio_circulation/signals.py diff --git a/invenio_circulation/signals.py b/invenio_circulation/signals.py new file mode 100644 index 0000000000..0413bd6cdd --- /dev/null +++ b/invenio_circulation/signals.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2018 CERN. +# Copyright (C) 2018 RERO. +# +# Invenio-Circulation is free software; you can redistribute it and/or modify +# it under the terms of the MIT License; see LICENSE file for more details. + +"""Signals for Invenio-Circulation.""" + +from blinker import Namespace + +_signals = Namespace() + +loan_state_changed = _signals.signal('loan-state-changed') +"""Loan state changed signal. + +Its is broadcasted when a loan transitions to a different state. +""" diff --git a/invenio_circulation/transitions/base.py b/invenio_circulation/transitions/base.py index 467d0b9d24..2cd5c86eb6 100644 --- a/invenio_circulation/transitions/base.py +++ b/invenio_circulation/transitions/base.py @@ -15,6 +15,7 @@ from ..api import is_item_available from ..errors import InvalidState, ItemNotAvailable, \ TransitionConditionsFailed, TransitionConstraintsViolation +from ..signals import loan_state_changed from ..utils import parse_date @@ -124,4 +125,5 @@ def after(self, loan): """Commit record and index.""" loan['transaction_date'] = loan['transaction_date'].isoformat() loan.commit() - # TODO: save to db and index loan here??? + # TODO: save to db and index loan here, then broadcast the changes. + loan_state_changed.send(self, loan=loan)