forked from rero/rero-ils
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
notifications: generalize notification resource
This refactoring purpose is to generalize the notification system in order to manage every kind of notification. The `Notification` resource structure is heavy linked to circulation operation (we need to link the notification with a loan). This commit implements a specific class implementation for each type of notification, with a subclass that provides relevant information to process and dispatch the notification. Closes rero#2373. Closes rero#2390. Closes rero#2410. Co-Authored-by: Renaud Michotte <renaud.michotte@gmail.com>
- Loading branch information
Showing
61 changed files
with
2,016 additions
and
944 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# RERO ILS | ||
# Copyright (C) 2021 RERO | ||
# Copyright (C) 2021 UCLouvain | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as published by | ||
# the Free Software Foundation, version 3 of the License. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
"""Documents dumpers.""" | ||
|
||
from invenio_records.dumpers import Dumper as InvenioRecordsDumper | ||
|
||
from rero_ils.modules.documents.utils import title_format_text_head | ||
|
||
|
||
class DocumentNotificationDumper(InvenioRecordsDumper): | ||
"""Document dumper class for notification.""" | ||
|
||
def dump(self, record, data): | ||
"""Dump a document instance for notification. | ||
:param record: The record to dump. | ||
:param data: The initial dump data passed in by ``record.dumps()``. | ||
""" | ||
title_text = title_format_text_head( | ||
record.get('title', []), | ||
responsabilities=record.get('responsibilityStatement') | ||
) | ||
data.update({ | ||
'pid': record.get('pid'), | ||
'title_text': title_text | ||
}) | ||
data = {k: v for k, v in data.items() if v} | ||
return data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# RERO ILS | ||
# Copyright (C) 2021 RERO | ||
# Copyright (C) 2021 UCLouvain | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as published by | ||
# the Free Software Foundation, version 3 of the License. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
"""Items dumpers.""" | ||
|
||
from invenio_records.dumpers import Dumper as InvenioRecordsDumper | ||
|
||
|
||
class ItemNotificationDumper(InvenioRecordsDumper): | ||
"""Item dumper class for notification.""" | ||
|
||
def dump(self, record, data): | ||
"""Dump an item instance for notification. | ||
:param record: The record to dump. | ||
:param data: The initial dump data passed in by ``record.dumps()``. | ||
:return a dict with dumped data. | ||
""" | ||
location = record.get_location() | ||
data = { | ||
'pid': record.pid, | ||
'barcode': record.get('barcode'), | ||
'call_numbers': record.call_numbers, | ||
'location_name': location.get('name'), | ||
'library_name': location.get_library().get('name') | ||
} | ||
data = {k: v for k, v in data.items() if v} | ||
return data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# RERO ILS | ||
# Copyright (C) 2021 RERO | ||
# Copyright (C) 2021 UCLouvain | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as published by | ||
# the Free Software Foundation, version 3 of the License. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
"""Libraries dumpers.""" | ||
|
||
from invenio_records.dumpers import Dumper as InvenioRecordsDumper | ||
|
||
|
||
class LibraryCirculationNotificationDumper(InvenioRecordsDumper): | ||
"""Library dumper class for circulation notification.""" | ||
|
||
def dump(self, record, data): | ||
"""Dump a library instance for circulation notification. | ||
:param record: The record to dump. | ||
:param data: The initial dump data passed in by ``record.dumps()``. | ||
:return a dict with dumped data. | ||
""" | ||
data.update({ | ||
'pid': record.pid, | ||
'name': record.get('name'), | ||
'address': record.get('address'), | ||
'email': record.get('email') | ||
}) | ||
return {k: v for k, v in data.items() if v} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.