Skip to content

Commit

Permalink
loan: notifications #52
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
topless authored and zzacharo committed Aug 2, 2018
1 parent 1a4f126 commit 48306e8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
19 changes: 19 additions & 0 deletions invenio_circulation/signals.py
Original file line number Diff line number Diff line change
@@ -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.
"""
4 changes: 3 additions & 1 deletion invenio_circulation/transitions/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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)

0 comments on commit 48306e8

Please sign in to comment.