invenio-banners 5.1.1__py2.py3-none-any.whl → 5.2.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.

@@ -10,6 +10,6 @@
10
10
 
11
11
  from .ext import InvenioBanners
12
12
 
13
- __version__ = "5.1.1"
13
+ __version__ = "5.2.0"
14
14
 
15
15
  __all__ = ("__version__", "InvenioBanners")
@@ -8,7 +8,7 @@
8
8
 
9
9
  """Models."""
10
10
 
11
- from datetime import datetime
11
+ from datetime import datetime, timezone
12
12
 
13
13
  import sqlalchemy as sa
14
14
  from flask import current_app
@@ -90,7 +90,7 @@ class BannerModel(db.Model, Timestamp):
90
90
  @classmethod
91
91
  def get_active(cls, url_path):
92
92
  """Return active banners."""
93
- now = datetime.utcnow()
93
+ now = datetime.now(timezone.utc).replace(tzinfo=None)
94
94
 
95
95
  query = (
96
96
  db.session.query(cls)
@@ -110,12 +110,12 @@ class BannerModel(db.Model, Timestamp):
110
110
  return active_banners.all()
111
111
 
112
112
  @classmethod
113
- def search(cls, search_params, filters):
113
+ def search(cls, search_params, filters=None):
114
114
  """Filter banners accordingly to query params."""
115
- if filters == []:
116
- filtered = db.session.query(BannerModel).filter()
117
- else:
115
+ if filters:
118
116
  filtered = db.session.query(BannerModel).filter(or_(*filters))
117
+ else:
118
+ filtered = db.session.query(BannerModel).filter()
119
119
 
120
120
  banners = filtered.order_by(
121
121
  search_params["sort_direction"](text(",".join(search_params["sort"])))
@@ -130,7 +130,7 @@ class BannerModel(db.Model, Timestamp):
130
130
  @classmethod
131
131
  def disable_expired(cls):
132
132
  """Disable any old still active messages to keep everything clean."""
133
- now = datetime.utcnow()
133
+ now = datetime.now(timezone.utc).replace(tzinfo=None)
134
134
 
135
135
  query = (
136
136
  db.session.query(cls)
@@ -1,6 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  #
3
- # Copyright (C) 2022-2024 CERN.
3
+ # Copyright (C) 2022-2025 CERN.
4
4
  #
5
5
  # Invenio-Banners is free software; you can redistribute it and/or modify it
6
6
  # under the terms of the MIT License; see LICENSE file for more details.
@@ -19,6 +19,8 @@ class BannerServerSearchRequestArgsSchema(SearchRequestArgsSchema):
19
19
  """Banner request parameters."""
20
20
 
21
21
  sort_direction = ma.fields.Str()
22
+ active = ma.fields.Bool()
23
+ url_path = ma.fields.Str()
22
24
 
23
25
 
24
26
  class BannerResourceConfig(RecordResourceConfig):
@@ -22,7 +22,7 @@ class BannerSchema(BaseRecordSchema):
22
22
  category = fields.String(required=True, metadata={"default": "info"})
23
23
  start_datetime = fields.DateTime(
24
24
  required=True,
25
- metadata={"default": datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S")},
25
+ metadata={"default": datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M:%S")},
26
26
  )
27
27
  end_datetime = fields.DateTime(allow_none=True)
28
28
  active = fields.Boolean(required=True, metadata={"default": True})
@@ -1,6 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  #
3
- # Copyright (C) 2022-2023 CERN.
3
+ # Copyright (C) 2022-2025 CERN.
4
4
  # Copyright (C) 2024 Graz University of Technology.
5
5
  #
6
6
  # Invenio-Banners is free software; you can redistribute it and/or modify it
@@ -15,7 +15,7 @@ from invenio_db.uow import unit_of_work
15
15
  from invenio_records_resources.services import RecordService
16
16
  from invenio_records_resources.services.base import LinksTemplate
17
17
  from invenio_records_resources.services.base.utils import map_search_params
18
- from sqlalchemy import func
18
+ from sqlalchemy import and_, func, literal, or_
19
19
 
20
20
  from ..records.models import BannerModel
21
21
 
@@ -37,14 +37,35 @@ class BannerService(RecordService):
37
37
  )
38
38
 
39
39
  def search(self, identity, params):
40
- """Search for banners matching the querystring."""
40
+ """Search for banners with multiple filter options.
41
+
42
+ Supports filtering by:
43
+ - active: boolean filter
44
+ - url_path: prefix matching (empty paths match all, specific paths match as prefixes)
45
+ - q: text or date search across multiple fields
46
+
47
+ active and url_path filters are combined with AND logic, while OR is used while combining them with the q filters.
48
+ """
41
49
  self.require_permission(identity, "search")
42
50
 
51
+ active_filter_param = params.pop("active", None)
52
+ url_path_filter_param = params.pop("url_path", None)
43
53
  search_params = map_search_params(self.config.search, params)
44
54
 
45
- query_param = search_params["q"]
46
- filters = []
55
+ and_filters = []
56
+ if active_filter_param is not None:
57
+ and_filters.append(BannerModel.active.is_(active_filter_param))
58
+
59
+ if url_path_filter_param is not None:
60
+ and_filters.append(
61
+ or_(
62
+ BannerModel.url_path == "",
63
+ literal(url_path_filter_param).like(BannerModel.url_path + "%"),
64
+ )
65
+ )
47
66
 
67
+ filters = [and_(*and_filters)] if and_filters else []
68
+ query_param = search_params["q"]
48
69
  if query_param:
49
70
  filters.extend(
50
71
  [
@@ -53,13 +74,6 @@ class BannerService(RecordService):
53
74
  BannerModel.category.ilike(f"%{query_param}%"),
54
75
  ]
55
76
  )
56
- bool_value = self._validate_bool(query_param)
57
- if bool_value is not None:
58
- filters.extend(
59
- [
60
- BannerModel.active.is_(bool_value),
61
- ]
62
- )
63
77
 
64
78
  datetime_value = self._validate_datetime(query_param)
65
79
  if datetime_value is not None:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: invenio-banners
3
- Version: 5.1.1
3
+ Version: 5.2.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
@@ -66,6 +66,11 @@ https://invenio-banners.readthedocs.io/
66
66
  Changes
67
67
  =======
68
68
 
69
+ Version v5.2.0 (released 2025-08-06)
70
+
71
+ - search: add query params active and url_path for search, add None as default value for filters
72
+ - global: replace deprecated datetime utcnow() with now(timezone.utc)
73
+
69
74
  Version v5.1.1 (released 2025-07-22)
70
75
 
71
76
  - fix: mo files not included into build
@@ -1,4 +1,4 @@
1
- invenio_banners/__init__.py,sha256=N_NHYX6xP_tyYWkBF8-aJ2hhDiKEGCyiBWwB_kdMpGA,430
1
+ invenio_banners/__init__.py,sha256=zU3w6wJxTF6TfiuRsQhMsCLALwApY56lh1utoLp-Zvk,430
2
2
  invenio_banners/config.py,sha256=csFr0XWaYh05hAjvY44pA6taQFDUmocQ08mX4e5jiEY,1364
3
3
  invenio_banners/ext.py,sha256=rRIgDgZIyGhm2M8WHWApMPRcBVe3eHkaHzTOt-YH6aw,1836
4
4
  invenio_banners/proxies.py,sha256=nfACfpSgfCHiixSy2cO4G9y_lHFQj6onOeBLifYY6IQ,638
@@ -9,9 +9,9 @@ invenio_banners/administration/banners.py,sha256=N-7iBxyp6LRuDXSlktXqncmPnISGHTm
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=iKlk4dOMRJKVmr5BT1TpgSjXY2D8V16L92Sj3ggnOKA,4427
12
+ invenio_banners/records/models.py,sha256=vK3lTr7qocSC9LWviOXqQhAbdmq_4y2BlOrWVrlc43U,4496
13
13
  invenio_banners/resources/__init__.py,sha256=bQbqlVhQKjJXiiNmqsf_Z1R_4PqmmNTb-Kwj-2lEfQQ,402
14
- invenio_banners/resources/config.py,sha256=Ng0TowZk3GCG1tOv0TKtUpeDwY8RIK6adEUYCVVnKZg,1435
14
+ invenio_banners/resources/config.py,sha256=FuNDsM_WWJoo_DX2ibM6SO2GPvlCwYxbBaH_SvqRc94,1496
15
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
@@ -19,8 +19,8 @@ invenio_banners/services/config.py,sha256=uzKWmgPIGHAG00Zs5BHlp1Y6WzbNzfS_tkXA3l
19
19
  invenio_banners/services/errors.py,sha256=1suJcPwdLyK3hqK0gicgTMUX2OAk_Y8TaqancnkXyEA,542
20
20
  invenio_banners/services/permissions.py,sha256=EbC4oeFaBHCYTPnDMrtoS9Cgo4skhjz694qhGEnZYHs,830
21
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
22
+ invenio_banners/services/schemas.py,sha256=34oIXNmIU2pkkL3AOGhTkwaUgh9yUFCdJQ4Dp6jClfw,1451
23
+ invenio_banners/services/service.py,sha256=l7AZuH85Xr4He4vORw-pxtVRk3VoKxOOBMXAo43U0eY,5460
24
24
  invenio_banners/templates/semantic-ui/invenio_banners/banner.html,sha256=mOPfWsxRMIftoCyU82WeHlEhHFvy56BTF4wDJHpzX-o,811
25
25
  invenio_banners/translations/messages.pot,sha256=uqnF8VA0glId6_gSPuRFnOpmH8vspCOX9b6emJw3Gf4,4672
26
26
  invenio_banners/translations/ar/LC_MESSAGES/messages.mo,sha256=lneRS0Vp0D7yGmsZUiD2ZThZUvgymnzupcrfPMs9nn8,4395
@@ -81,10 +81,10 @@ invenio_banners/translations/zh_CN/LC_MESSAGES/messages.mo,sha256=NfQYcvNS44LX_k
81
81
  invenio_banners/translations/zh_CN/LC_MESSAGES/messages.po,sha256=JHhsMcsmSd8saIK5mOECFBHbfHcWpmYjVk_8elm7whs,4962
82
82
  invenio_banners/translations/zh_TW/LC_MESSAGES/messages.mo,sha256=4nTza7lSLzUOcZh19Kmwym0-2xhslmUgsKqRHhFkSnw,590
83
83
  invenio_banners/translations/zh_TW/LC_MESSAGES/messages.po,sha256=aqhqHPr0Q6dc_eCGBtn9sqFVpfyd81uPS3_SWGOlPXw,4870
84
- invenio_banners-5.1.1.dist-info/licenses/AUTHORS.rst,sha256=fQsy2e1bLnwt_a89-kO6CwBwN7o58Ix9F9195b2iTJo,295
85
- invenio_banners-5.1.1.dist-info/licenses/LICENSE,sha256=UvI8pR8jGWqe0sTkb_hRG6eIrozzWwWzyCGEpuXX4KE,1062
86
- invenio_banners-5.1.1.dist-info/METADATA,sha256=AxpGD-ZZy-OEpjzsais1xxJo8eB90DtKDLfgclsNPSY,4409
87
- invenio_banners-5.1.1.dist-info/WHEEL,sha256=JNWh1Fm1UdwIQV075glCn4MVuCRs0sotJIq-J6rbxCU,109
88
- invenio_banners-5.1.1.dist-info/entry_points.txt,sha256=A6LQWHkrQXiid3LGWKIz2C4eZfaHSGne3mkcy00j2Fg,782
89
- invenio_banners-5.1.1.dist-info/top_level.txt,sha256=ENJP1dEZ93e4ImCi7AHaVooTUV-6fQnRJ106wHitg5g,16
90
- invenio_banners-5.1.1.dist-info/RECORD,,
84
+ invenio_banners-5.2.0.dist-info/licenses/AUTHORS.rst,sha256=fQsy2e1bLnwt_a89-kO6CwBwN7o58Ix9F9195b2iTJo,295
85
+ invenio_banners-5.2.0.dist-info/licenses/LICENSE,sha256=UvI8pR8jGWqe0sTkb_hRG6eIrozzWwWzyCGEpuXX4KE,1062
86
+ invenio_banners-5.2.0.dist-info/METADATA,sha256=SZ4a51ARhvG_XbHTdqswHJ3mbpTW_OsgBTt1n2H7by8,4615
87
+ invenio_banners-5.2.0.dist-info/WHEEL,sha256=JNWh1Fm1UdwIQV075glCn4MVuCRs0sotJIq-J6rbxCU,109
88
+ invenio_banners-5.2.0.dist-info/entry_points.txt,sha256=A6LQWHkrQXiid3LGWKIz2C4eZfaHSGne3mkcy00j2Fg,782
89
+ invenio_banners-5.2.0.dist-info/top_level.txt,sha256=ENJP1dEZ93e4ImCi7AHaVooTUV-6fQnRJ106wHitg5g,16
90
+ invenio_banners-5.2.0.dist-info/RECORD,,