invenio-banners 3.1.1__py2.py3-none-any.whl → 4.0.0__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of invenio-banners might be problematic. Click here for more details.

@@ -1,6 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  #
3
3
  # Copyright (C) 2020-2024 CERN.
4
+ # Copyright (C) 2024 Graz University of Technology.
4
5
  #
5
6
  # Invenio-Banners is free software; you can redistribute it and/or modify it
6
7
  # under the terms of the MIT License; see LICENSE file for more details.
@@ -9,6 +10,6 @@
9
10
 
10
11
  from .ext import InvenioBanners
11
12
 
12
- __version__ = "3.1.1"
13
+ __version__ = "4.0.0"
13
14
 
14
15
  __all__ = ("__version__", "InvenioBanners")
@@ -1,6 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  #
3
3
  # Copyright (C) 2020-2023 CERN.
4
+ # Copyright (C) 2024 Graz University of Technology.
4
5
  #
5
6
  # Invenio-Banners is free software; you can redistribute it and/or modify it
6
7
  # under the terms of the MIT License; see LICENSE file for more details.
@@ -13,7 +14,6 @@ import sqlalchemy as sa
13
14
  from flask import current_app
14
15
  from invenio_db import db
15
16
  from sqlalchemy import or_
16
- from sqlalchemy.orm.exc import NoResultFound
17
17
  from sqlalchemy.sql import text
18
18
  from sqlalchemy_utils.models import Timestamp
19
19
 
@@ -24,7 +24,6 @@ class BannerModel(db.Model, Timestamp):
24
24
  """Defines a message to show to users."""
25
25
 
26
26
  __tablename__ = "banners"
27
- __versioned__ = {"versioning": False}
28
27
 
29
28
  id = db.Column(db.Integer, primary_key=True)
30
29
 
@@ -51,6 +50,7 @@ class BannerModel(db.Model, Timestamp):
51
50
  """Create a new banner."""
52
51
  _categories = [t[0] for t in current_app.config["BANNERS_CATEGORIES"]]
53
52
  assert data.get("category") in _categories
53
+
54
54
  with db.session.begin_nested():
55
55
  obj = cls(
56
56
  message=data.get("message"),
@@ -62,24 +62,24 @@ class BannerModel(db.Model, Timestamp):
62
62
  )
63
63
  db.session.add(obj)
64
64
 
65
- db.session.commit()
66
65
  return obj
67
66
 
68
67
  @classmethod
69
68
  def update(cls, data, id):
70
69
  """Update an existing banner."""
71
70
  with db.session.begin_nested():
72
- cls.query.filter_by(id=id).update(data)
73
-
74
- db.session.commit()
71
+ # NOTE:
72
+ # with db.session.get(cls, id) the model itself would be
73
+ # returned and this classmethod would be called
74
+ db.session.query(cls).filter_by(id=id).update(data)
75
75
 
76
76
  @classmethod
77
77
  def get(cls, id):
78
78
  """Get banner by its id."""
79
- try:
80
- return cls.query.filter_by(id=id).one()
81
- except NoResultFound:
82
- raise BannerNotExistsError(id)
79
+ if banner := db.session.get(cls, id):
80
+ return banner
81
+
82
+ raise BannerNotExistsError(id)
83
83
 
84
84
  @classmethod
85
85
  def delete(cls, banner):
@@ -87,15 +87,14 @@ class BannerModel(db.Model, Timestamp):
87
87
  with db.session.begin_nested():
88
88
  db.session.delete(banner)
89
89
 
90
- db.session.commit()
91
-
92
90
  @classmethod
93
91
  def get_active(cls, url_path):
94
92
  """Return active banners."""
95
93
  now = datetime.utcnow()
96
94
 
97
95
  query = (
98
- cls.query.filter(cls.active.is_(True))
96
+ db.session.query(cls)
97
+ .filter(cls.active.is_(True))
99
98
  .filter(cls.start_datetime <= now)
100
99
  .filter((cls.end_datetime.is_(None)) | (now <= cls.end_datetime))
101
100
  )
@@ -113,16 +112,17 @@ class BannerModel(db.Model, Timestamp):
113
112
  @classmethod
114
113
  def search(cls, search_params, filters):
115
114
  """Filter banners accordingly to query params."""
116
- banners = (
117
- BannerModel.query.filter(or_(*filters))
118
- .order_by(
119
- search_params["sort_direction"](text(",".join(search_params["sort"])))
120
- )
121
- .paginate(
122
- page=search_params["page"],
123
- per_page=search_params["size"],
124
- error_out=False,
125
- )
115
+ if filters == []:
116
+ filtered = db.session.query(BannerModel).filter()
117
+ else:
118
+ filtered = db.session.query(BannerModel).filter(or_(*filters))
119
+
120
+ banners = filtered.order_by(
121
+ search_params["sort_direction"](text(",".join(search_params["sort"])))
122
+ ).paginate(
123
+ page=search_params["page"],
124
+ per_page=search_params["size"],
125
+ error_out=False,
126
126
  )
127
127
 
128
128
  return banners
@@ -133,12 +133,11 @@ class BannerModel(db.Model, Timestamp):
133
133
  now = datetime.utcnow()
134
134
 
135
135
  query = (
136
- cls.query.filter(cls.active.is_(True))
136
+ db.session.query(cls)
137
+ .filter(cls.active.is_(True))
137
138
  .filter(cls.end_datetime.isnot(None))
138
139
  .filter(cls.end_datetime < now)
139
140
  )
140
141
 
141
142
  for old in query.all():
142
143
  old.active = False
143
-
144
- db.session.commit()
@@ -1,19 +1,19 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  #
3
3
  # Copyright (C) 2023 CERN.
4
+ # Copyright (C) 2024 Graz University of Technology.
4
5
  #
5
6
  # Invenio-Banners is free software; you can redistribute it and/or modify it
6
7
  # under the terms of the MIT License; see LICENSE file for more details.
7
8
 
8
9
  """Errors."""
9
10
 
10
- from flask_resources import HTTPJSONException, create_error_handler
11
-
12
- from ..services.errors import BannerNotExistsError
13
11
  import marshmallow as ma
14
12
  from flask_resources import HTTPJSONException, create_error_handler
15
13
  from invenio_records_resources.errors import validation_error_to_list_errors
16
14
 
15
+ from ..services.errors import BannerNotExistsError
16
+
17
17
 
18
18
  class HTTPJSONValidationException(HTTPJSONException):
19
19
  """HTTP exception serializing to JSON and reflecting Marshmallow errors."""
@@ -25,7 +25,7 @@ class HTTPJSONValidationException(HTTPJSONException):
25
25
  super().__init__(code=400, errors=validation_error_to_list_errors(exception))
26
26
 
27
27
 
28
- class ErrorHandlersMixin():
28
+ class ErrorHandlersMixin:
29
29
  """Mixin to define error handlers."""
30
30
 
31
31
  error_handlers = {
@@ -1,14 +1,22 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  #
3
3
  # Copyright (C) 2022-2023 CERN.
4
+ # Copyright (C) 2024 Graz University of Technology.
4
5
  #
5
6
  # Invenio-Banners is free software; you can redistribute it and/or modify it
6
7
  # under the terms of the MIT License; see LICENSE file for more details.
7
8
 
8
9
  """Service results."""
9
- from flask_sqlalchemy import Pagination
10
+
10
11
  from invenio_records_resources.services.records.results import RecordItem, RecordList
11
12
 
13
+ try:
14
+ # flask_sqlalchemy<3.0.0
15
+ from flask_sqlalchemy import Pagination
16
+ except ImportError:
17
+ # flask_sqlalchemy>=3.0.0
18
+ from flask_sqlalchemy.pagination import Pagination
19
+
12
20
 
13
21
  class BannerItem(RecordItem):
14
22
  """Single banner result."""
@@ -11,13 +11,13 @@ from datetime import datetime, timezone
11
11
 
12
12
  from invenio_records_resources.services.records.schema import BaseRecordSchema
13
13
  from marshmallow import fields, pre_load
14
- from marshmallow_utils.fields import TZDateTime
14
+ from marshmallow_utils.fields import SanitizedHTML, TZDateTime
15
15
 
16
16
 
17
17
  class BannerSchema(BaseRecordSchema):
18
18
  """Schema for banners."""
19
19
 
20
- message = fields.String(required=True)
20
+ message = SanitizedHTML(required=True)
21
21
  url_path = fields.String(allow_none=True)
22
22
  category = fields.String(required=True, metadata={"default": "info"})
23
23
  start_datetime = fields.DateTime(
@@ -1,6 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  #
3
3
  # Copyright (C) 2022-2023 CERN.
4
+ # Copyright (C) 2024 Graz University of Technology.
4
5
  #
5
6
  # Invenio-Banners is free software; you can redistribute it and/or modify it
6
7
  # under the terms of the MIT License; see LICENSE file for more details.
@@ -10,6 +11,7 @@
10
11
  import distutils.util
11
12
 
12
13
  import arrow
14
+ from invenio_db.uow import unit_of_work
13
15
  from invenio_records_resources.services import RecordService
14
16
  from invenio_records_resources.services.base import LinksTemplate
15
17
  from invenio_records_resources.services.base.utils import map_search_params
@@ -81,7 +83,8 @@ class BannerService(RecordService):
81
83
  links_item_tpl=self.links_item_tpl,
82
84
  )
83
85
 
84
- def create(self, identity, data, raise_errors=True):
86
+ @unit_of_work()
87
+ def create(self, identity, data, raise_errors=True, uow=None):
85
88
  """Create a banner."""
86
89
  self.require_permission(identity, "create")
87
90
 
@@ -99,17 +102,18 @@ class BannerService(RecordService):
99
102
  self, identity, banner, links_tpl=self.links_item_tpl, errors=errors
100
103
  )
101
104
 
102
- def delete(self, identity, id):
105
+ @unit_of_work()
106
+ def delete(self, identity, id, uow=None):
103
107
  """Delete a banner from database."""
104
108
  self.require_permission(identity, "delete")
105
109
 
106
110
  banner = self.record_cls.get(id)
107
-
108
111
  self.record_cls.delete(banner)
109
112
 
110
113
  return self.result_item(self, identity, banner, links_tpl=self.links_item_tpl)
111
114
 
112
- def update(self, identity, id, data):
115
+ @unit_of_work()
116
+ def update(self, identity, id, data, uow=None):
113
117
  """Update a banner."""
114
118
  self.require_permission(identity, "update")
115
119
 
@@ -131,7 +135,8 @@ class BannerService(RecordService):
131
135
  links_tpl=self.links_item_tpl,
132
136
  )
133
137
 
134
- def disable_expired(self, identity):
138
+ @unit_of_work()
139
+ def disable_expired(self, identity, uow=None):
135
140
  """Disable expired banners."""
136
141
  self.require_permission(identity, "disable")
137
142
  self.record_cls.disable_expired()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: invenio-banners
3
- Version: 3.1.1
3
+ Version: 4.0.0
4
4
  Summary: Invenio-Banners is a module used to create and show banners with useful messages to users.
5
5
  Home-page: https://github.com/inveniosoftware/invenio-banners
6
6
  Author: CERN
@@ -10,17 +10,20 @@ Keywords: Invenio Banners
10
10
  Platform: any
11
11
  Classifier: Development Status :: 1 - Planning
12
12
  Requires-Python: >=3.7
13
- Requires-Dist: invenio-i18n <3.0.0,>=2.0.0
14
- Requires-Dist: invenio-administration <3.0.0,>=2.0.0
13
+ License-File: LICENSE
14
+ License-File: AUTHORS.rst
15
+ Requires-Dist: invenio-i18n<4.0.0,>=3.0.0
16
+ Requires-Dist: invenio-administration<4.0.0,>=3.0.0
17
+ Provides-Extra: tests
18
+ Requires-Dist: pytest-black-ng>=0.4.0; extra == "tests"
19
+ Requires-Dist: pytest-invenio<4.0.0,>=3.0.0; extra == "tests"
20
+ Requires-Dist: jsonresolver>=0.3.2; extra == "tests"
21
+ Requires-Dist: invenio-app<3.0.0,>=2.0.0; extra == "tests"
22
+ Requires-Dist: sphinx>=4.5; extra == "tests"
15
23
  Provides-Extra: opensearch1
16
- Requires-Dist: invenio-search[opensearch1] <3.0.0,>=2.1.0 ; extra == 'opensearch1'
24
+ Requires-Dist: invenio-search[opensearch1]<4.0.0,>=3.0.0; extra == "opensearch1"
17
25
  Provides-Extra: opensearch2
18
- Requires-Dist: invenio-search[opensearch2] <3.0.0,>=2.1.0 ; extra == 'opensearch2'
19
- Provides-Extra: tests
20
- Requires-Dist: pytest-invenio <3.0.0,>=2.1.0 ; extra == 'tests'
21
- Requires-Dist: invenio-app <2.0.0,>=1.3.4 ; extra == 'tests'
22
- Requires-Dist: pytest-black >=0.3.0 ; extra == 'tests'
23
- Requires-Dist: sphinx >=4.5 ; extra == 'tests'
26
+ Requires-Dist: invenio-search[opensearch2]<4.0.0,>=3.0.0; extra == "opensearch2"
24
27
 
25
28
  ..
26
29
  Copyright (C) 2020 CERN.
@@ -54,7 +57,7 @@ https://invenio-banners.readthedocs.io/
54
57
 
55
58
  ..
56
59
  Copyright (C) 2020-2024 CERN.
57
- Copyright (C) 2024 Northwestern University.
60
+ Copyright (C) 2024 Graz University of Technology.
58
61
 
59
62
  Invenio-Banners is free software; you can redistribute it and/or modify
60
63
  it under the terms of the MIT License; see LICENSE file for more details.
@@ -62,10 +65,16 @@ https://invenio-banners.readthedocs.io/
62
65
  Changes
63
66
  =======
64
67
 
65
- Version v3.1.1 (released 2024-09-18)
68
+ Version v4.0.0 (released 2024-12-10)
69
+
70
+ - setup: change to reusable workflows
71
+ - setup: bump major dependencies
66
72
 
67
- - admin: adjust + fix typos in descriptions of fields
68
- - i18n:push translations
73
+ Version v3.2.0 (released 2024-11-05)
74
+
75
+ - feat(administration): use html editor for message
76
+ - global: change the code to be compatible with sqlalchemy >= 2.0
77
+ - global: add compatibility layer to move to flask >= 3.0
69
78
 
70
79
  Version v3.1.0 (released 2024-08-07)
71
80
 
@@ -106,5 +115,3 @@ Version 1.0.0a1 (release 2020-10-25)
106
115
  ------------------------------------
107
116
 
108
117
  - Initial public release.
109
-
110
-
@@ -1,4 +1,4 @@
1
- invenio_banners/__init__.py,sha256=can8AwpDeSf3drqZX0cxmgfkYOLSLXliyHRFKmFW2rU,373
1
+ invenio_banners/__init__.py,sha256=x5l0XCEOf3v8LCTX-b5deFuWuCK2extpjhGlFHpa6W0,425
2
2
  invenio_banners/config.py,sha256=xGHNLvXoJyQsJo7yKeOh-lDySTaX0bVH1mk7BMrE1NA,1299
3
3
  invenio_banners/ext.py,sha256=rRIgDgZIyGhm2M8WHWApMPRcBVe3eHkaHzTOt-YH6aw,1836
4
4
  invenio_banners/proxies.py,sha256=nfACfpSgfCHiixSy2cO4G9y_lHFQj6onOeBLifYY6IQ,638
@@ -9,18 +9,18 @@ invenio_banners/administration/banners.py,sha256=ZlJgxiWxteQvhQa5_1_iq1FHWSG0bTm
9
9
  invenio_banners/alembic/5e02314da32e_create_invenio_banners_db_table.py,sha256=FZ5Z8RsrbrlN8vr43LW0ukVRFTj2DV7B7JgVjnk0zp8,1446
10
10
  invenio_banners/alembic/e40d93d99040_create_invenio_banners_branch.py,sha256=KoEbAzpNneVNBwegW3FfMIW_XTH6im0GXz2DvIF6DwA,562
11
11
  invenio_banners/records/__init__.py,sha256=-A_Q-oZyJuV2lcgLfqXWeMuTlmv6IrEbcMqs_58PHuE,298
12
- invenio_banners/records/models.py,sha256=MS_nyrvJ0LkQJPx5BEqAJo0_P-w0TekNGWsSkg1ijNw,4318
12
+ invenio_banners/records/models.py,sha256=iKlk4dOMRJKVmr5BT1TpgSjXY2D8V16L92Sj3ggnOKA,4427
13
13
  invenio_banners/resources/__init__.py,sha256=bQbqlVhQKjJXiiNmqsf_Z1R_4PqmmNTb-Kwj-2lEfQQ,402
14
14
  invenio_banners/resources/config.py,sha256=Ng0TowZk3GCG1tOv0TKtUpeDwY8RIK6adEUYCVVnKZg,1435
15
- invenio_banners/resources/errors.py,sha256=eweK5tYYlscBBpXvQd6xZxXsHhl3jzZzKblBf4uiB08,1249
15
+ invenio_banners/resources/errors.py,sha256=H-qs9L10KSFaGKq_yDLu7QEiD2WB4JCKV8Xp_jJ4yEM,1231
16
16
  invenio_banners/resources/resource.py,sha256=lHTqkX7coKG0gXkgCdL7MEcsutGZ5rYSOEidiXHOztE,2924
17
17
  invenio_banners/services/__init__.py,sha256=9URKgFgYq2yUgj-eTB6_jE_ifZNQR9_E9sLP-1UIB1s,484
18
18
  invenio_banners/services/config.py,sha256=uzKWmgPIGHAG00Zs5BHlp1Y6WzbNzfS_tkXA3l4OOhA,2197
19
19
  invenio_banners/services/errors.py,sha256=1suJcPwdLyK3hqK0gicgTMUX2OAk_Y8TaqancnkXyEA,542
20
20
  invenio_banners/services/permissions.py,sha256=EbC4oeFaBHCYTPnDMrtoS9Cgo4skhjz694qhGEnZYHs,830
21
- invenio_banners/services/results.py,sha256=1TTtq--8WQkoqkTzIrC0EFsXSRurQZWn5MNgKU5Viys,2885
22
- invenio_banners/services/schemas.py,sha256=vq8CuEDCyXSkCXSbcRBQDUe8dvvX_njBa9N6CMdE-5A,1427
23
- invenio_banners/services/service.py,sha256=DRg-GIyuvSD0w1jYC07u7nt2pybeE1Yi_7ugLW0bA4Q,4559
21
+ invenio_banners/services/results.py,sha256=sg2z1zPKD8mWgUigwqdFWJqdnA7wOtmf6yKfa3AeUek,3082
22
+ invenio_banners/services/schemas.py,sha256=rWh1WSQR4ps_Ii7RWd82FUMk4_aHbdwd5kYh5gCxlJU,1442
23
+ invenio_banners/services/service.py,sha256=7KdwwrmqvtBsmEschL-i_ydPsijH7RjzLzMFogrKYeQ,4770
24
24
  invenio_banners/templates/semantic-ui/invenio_banners/banner.html,sha256=RdEjT_ay7UYwYNQjIQ_2Q-qonprBhVzoQq9OzHPzSKk,642
25
25
  invenio_banners/translations/messages.pot,sha256=SQpSVoZDsRHTihUdvEkq7HoNRwffdwhYPm2qITPRPYk,5090
26
26
  invenio_banners/translations/af/LC_MESSAGES/messages.po,sha256=kS4YofCdd6b6NCX5QXXKBZ1tpnu8dFWEdgQWsYPrYAk,5070
@@ -69,10 +69,10 @@ invenio_banners/translations/uk/LC_MESSAGES/messages.po,sha256=Z1ZM6O0bb8if1a82K
69
69
  invenio_banners/translations/uk_UA/LC_MESSAGES/messages.po,sha256=4KNAaMpzBYXmTLcH4NtmLKWpCZKEI9CbjfEH9tfa52c,5308
70
70
  invenio_banners/translations/zh_CN/LC_MESSAGES/messages.po,sha256=rBoibkyrfoi5WwZwI-C67fk_Gce7aGVg2595rJrrDi0,5265
71
71
  invenio_banners/translations/zh_TW/LC_MESSAGES/messages.po,sha256=2rOl1mvYBlJhThTyyQphuCVPl2apcJMew-tGl6WBO8I,5199
72
- invenio_banners-3.1.1.dist-info/AUTHORS.rst,sha256=fQsy2e1bLnwt_a89-kO6CwBwN7o58Ix9F9195b2iTJo,295
73
- invenio_banners-3.1.1.dist-info/LICENSE,sha256=UvI8pR8jGWqe0sTkb_hRG6eIrozzWwWzyCGEpuXX4KE,1062
74
- invenio_banners-3.1.1.dist-info/METADATA,sha256=fWJL4VVTYSJab3ybAJqutb_Hw25NZrHm9-9QSYQA9Vw,3481
75
- invenio_banners-3.1.1.dist-info/WHEEL,sha256=-G_t0oGuE7UD0DrSpVZnq1hHMBV9DD2XkS5v7XpmTnk,110
76
- invenio_banners-3.1.1.dist-info/entry_points.txt,sha256=jnZLi-_SEWCfUnqlIcj0tJmOnD33Z1GvmQMEejfhD20,720
77
- invenio_banners-3.1.1.dist-info/top_level.txt,sha256=ENJP1dEZ93e4ImCi7AHaVooTUV-6fQnRJ106wHitg5g,16
78
- invenio_banners-3.1.1.dist-info/RECORD,,
72
+ invenio_banners-4.0.0.dist-info/AUTHORS.rst,sha256=fQsy2e1bLnwt_a89-kO6CwBwN7o58Ix9F9195b2iTJo,295
73
+ invenio_banners-4.0.0.dist-info/LICENSE,sha256=UvI8pR8jGWqe0sTkb_hRG6eIrozzWwWzyCGEpuXX4KE,1062
74
+ invenio_banners-4.0.0.dist-info/METADATA,sha256=ORbQF5YnaC5RUV38nBLusFKOa4RXzXgOEVG1HnH9hAg,3782
75
+ invenio_banners-4.0.0.dist-info/WHEEL,sha256=pxeNX5JdtCe58PUSYP9upmc7jdRPgvT0Gm9kb1SHlVw,109
76
+ invenio_banners-4.0.0.dist-info/entry_points.txt,sha256=3p4FMVuj9AZ1QGm6YdcdhzP9k4xsPfsUG10Ykc3CpxI,719
77
+ invenio_banners-4.0.0.dist-info/top_level.txt,sha256=ENJP1dEZ93e4ImCi7AHaVooTUV-6fQnRJ106wHitg5g,16
78
+ invenio_banners-4.0.0.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.42.0)
2
+ Generator: setuptools (75.6.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py2-none-any
5
5
  Tag: py3-none-any
@@ -18,4 +18,3 @@ invenio_banners = invenio_banners:alembic
18
18
 
19
19
  [invenio_db.models]
20
20
  invenio_banners = invenio_banners.records.models
21
-