imio.smartweb.common 1.2.41__py3-none-any.whl → 1.2.42__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.
@@ -1,6 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  from collections import Counter
4
+ from DateTime import DateTime
4
5
  from imio.smartweb.common.rest.utils import get_json
5
6
  from plone import api
6
7
  from plone.restapi.search.handler import SearchHandler
@@ -38,6 +39,9 @@ class FindEndpointHandler(SearchHandler):
38
39
  query.get("field_name"),
39
40
  query.get("expected_values"),
40
41
  )
42
+ elif query.get("type_of_request") == "catalog":
43
+ json_str_query = query.get("json_str_query")
44
+ results = self.search_from_json(json_str_query)
41
45
  else:
42
46
  return super().search(query)
43
47
  return results
@@ -164,6 +168,73 @@ class FindEndpointHandler(SearchHandler):
164
168
  result[label] = {"count": count, "percent": round(percent, 2)}
165
169
  return result
166
170
 
171
+ def normalize_catalog_params(self, params):
172
+ """Recursilvly normalize catalog values :
173
+ - dicts keys 'query' -> try to convert DateTime
174
+ - list/tuple -> normalizing recursilvly
175
+ """
176
+ if isinstance(params, dict):
177
+ new = {}
178
+ for key, value in params.items():
179
+ # Special case : bloc of catalog criteria -> {'query': '...', 'range': 'min'}
180
+ if isinstance(value, dict) and "query" in value:
181
+ crit = value.copy()
182
+ q = crit.get("query")
183
+
184
+ # if string test DateTime
185
+ if isinstance(q, str):
186
+ try:
187
+ crit["query"] = DateTime(q)
188
+ except Exception:
189
+ # let in string
190
+ pass
191
+
192
+ # Normalizing others
193
+ for k2, v2 in crit.items():
194
+ if k2 != "query":
195
+ crit[k2] = self.normalize_catalog_params(v2)
196
+
197
+ new[key] = crit
198
+
199
+ else:
200
+ new[key] = self.normalize_catalog_params(value)
201
+ return new
202
+
203
+ if isinstance(params, (list, tuple)):
204
+ return [self.normalize_catalog_params(v) for v in params]
205
+
206
+ return params
207
+
208
+ def search_from_json(self, json_str):
209
+ """
210
+ Docstring for search_from_json
211
+
212
+ :param self: Description
213
+ :param json_str: Description
214
+ :example1: {"portal_type":"imio.events.Event","effective": {"query":"2025-12-12","range": "min"},"enableAutopublishing":true}
215
+ """
216
+ data = json.loads(json_str) or {}
217
+ attrs = [k for k, v in data.items()]
218
+ attrs = attrs + ["Title", "getPath"]
219
+ query_params = self.normalize_catalog_params(data)
220
+ catalog = api.portal.get_tool("portal_catalog")
221
+ brains = catalog(**query_params)
222
+
223
+ results = []
224
+ for brain in brains:
225
+ item = {}
226
+ for name in attrs:
227
+ value = getattr(brain, name, None)
228
+ if value is None:
229
+ value = getattr(brain.getObject(), name, None)
230
+ if callable(value):
231
+ value = value()
232
+ if isinstance(value, DateTime):
233
+ value = value.ISO8601()
234
+ item[name] = value
235
+ results.append(item)
236
+ return results
237
+
167
238
 
168
239
  class FindEndpoint(Service):
169
240
  def reply(self):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: imio.smartweb.common
3
- Version: 1.2.41
3
+ Version: 1.2.42
4
4
  Summary: Common utilities, vocabularies, taxonomies for imio.smartweb & co products
5
5
  Home-page: https://github.com/imio/imio.smartweb.common
6
6
  Author: iMio
@@ -178,6 +178,13 @@ Changelog
178
178
  =========
179
179
 
180
180
 
181
+ 1.2.42 (2025-12-11)
182
+ -------------------
183
+
184
+ - Add a new type of request in @find endpoint
185
+ [boulch]
186
+
187
+
181
188
  1.2.41 (2025-11-28)
182
189
  -------------------
183
190
 
@@ -1,4 +1,4 @@
1
- imio.smartweb.common-1.2.41-py3.12-nspkg.pth,sha256=XZ3YhlzwpUCC8tXtelHRqxVxo3NWomIiMsUfUshrbeE,1011
1
+ imio.smartweb.common-1.2.42-py3.12-nspkg.pth,sha256=XZ3YhlzwpUCC8tXtelHRqxVxo3NWomIiMsUfUshrbeE,1011
2
2
  imio/smartweb/common/__init__.py,sha256=Na9XBfEQUMrm2c5jbqQgwWeg40ih0aXVG1vT8NeAjMQ,2709
3
3
  imio/smartweb/common/adapters.py,sha256=dG4MALuHPQI6lTeNvs5p4vVOxHoBBYaWN6g8J96KxzQ,1507
4
4
  imio/smartweb/common/adapters.zcml,sha256=VO3luZDtRL9FIIEghxPrqpx8paZF3m6MGEy-8kF1sOQ,437
@@ -82,7 +82,7 @@ imio/smartweb/common/profiles/testing/types/Folder.xml,sha256=RPxIPgViAK0GGGTPKb
82
82
  imio/smartweb/common/profiles/uninstall/browserlayer.xml,sha256=glaCGlITwc36-1Fi2z0VCbLcoQ5GddkAhuW-SGYeZy8,130
83
83
  imio/smartweb/common/rest/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
84
84
  imio/smartweb/common/rest/configure.zcml,sha256=eT5gr-PcfMRxQzMME7T3nzz2Y0BVI4r9HyKHIccQC2s,575
85
- imio/smartweb/common/rest/endpoint.py,sha256=QDxyYuhI7ipB-JkFbMsl2OS7Vk-Uc39NwTJ41ZKZVDc,7411
85
+ imio/smartweb/common/rest/endpoint.py,sha256=QhurWC0_FuKef8fvEM3I8hSVCWcizAl5eIhQrNkhvvY,10074
86
86
  imio/smartweb/common/rest/odwb.py,sha256=zRZxowUaE76xlW_blc92vRCzToUpnzw3O5mxFXaeScU,2249
87
87
  imio/smartweb/common/rest/search_filters.py,sha256=upZAZ6h50qiSXo0q22lUgNlcmX5elFtrIQs_jFBl1-s,3832
88
88
  imio/smartweb/common/rest/utils.py,sha256=9zc5ge_DmVuexxN09c3U6QAITAI1s2hc0m6eZuylSxM,1269
@@ -158,10 +158,10 @@ imio/smartweb/common/viewlets/skip_to_content.py,sha256=wm22NUf8Qh5uzz8p4vkLCdFN
158
158
  imio/smartweb/common/widgets/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
159
159
  imio/smartweb/common/widgets/select.py,sha256=5sV0UIgwu4AvwpgVmJeSZwUWz7OPD9VxYMowfmjcfbA,1313
160
160
  imio/smartweb/common/widgets/templates/ajaxselect_display.pt,sha256=v8TT2Xc19er6SUGWabgNfIdrayFYIjxyLK9H_XkIG3M,1209
161
- imio_smartweb_common-1.2.41.dist-info/licenses/LICENSE.GPL,sha256=gXf5dRMhNSbfLPYYTY_5hsZ1r7UU1OaKQEAQUhuIBkM,18092
162
- imio_smartweb_common-1.2.41.dist-info/licenses/LICENSE.rst,sha256=5dd78Fdt0e-oM2ICBrMpjHnT8vEP-jhBDF7akXni6B4,655
163
- imio_smartweb_common-1.2.41.dist-info/METADATA,sha256=IMOqMnAl_g9U45WYc8wiW7zmgUB2HErN-ZH4ijXIxmk,19497
164
- imio_smartweb_common-1.2.41.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
165
- imio_smartweb_common-1.2.41.dist-info/namespace_packages.txt,sha256=Pg8AH8t9viMMW1hJbNZvTy_n2jXG2igIYUpon5RA4Js,19
166
- imio_smartweb_common-1.2.41.dist-info/top_level.txt,sha256=ZktC0EGzThvMTAin9_q_41rzvvfMT2FYbP8pbhSLMSA,5
167
- imio_smartweb_common-1.2.41.dist-info/RECORD,,
161
+ imio_smartweb_common-1.2.42.dist-info/licenses/LICENSE.GPL,sha256=gXf5dRMhNSbfLPYYTY_5hsZ1r7UU1OaKQEAQUhuIBkM,18092
162
+ imio_smartweb_common-1.2.42.dist-info/licenses/LICENSE.rst,sha256=5dd78Fdt0e-oM2ICBrMpjHnT8vEP-jhBDF7akXni6B4,655
163
+ imio_smartweb_common-1.2.42.dist-info/METADATA,sha256=s8PcbA3TDG89vfer_qqHIM-DTaFsFIOrLz6hjjDKisw,19597
164
+ imio_smartweb_common-1.2.42.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
165
+ imio_smartweb_common-1.2.42.dist-info/namespace_packages.txt,sha256=Pg8AH8t9viMMW1hJbNZvTy_n2jXG2igIYUpon5RA4Js,19
166
+ imio_smartweb_common-1.2.42.dist-info/top_level.txt,sha256=ZktC0EGzThvMTAin9_q_41rzvvfMT2FYbP8pbhSLMSA,5
167
+ imio_smartweb_common-1.2.42.dist-info/RECORD,,