imio.smartweb.common 1.2.15__py3-none-any.whl → 1.2.17__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,7 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
+ from imio.smartweb.common.widgets.select import TranslatedAjaxSelectFieldWidget
3
4
  from imio.smartweb.locales import SmartwebMessageFactory as _
4
- from plone.app.z3cform.widget import AjaxSelectFieldWidget
5
5
  from plone.autoform import directives
6
6
  from plone.autoform.interfaces import IFormFieldProvider
7
7
  from plone.supermodel import model
@@ -21,4 +21,4 @@ class ITopics(model.Schema):
21
21
  default=[],
22
22
  required=False,
23
23
  )
24
- directives.widget(topics=AjaxSelectFieldWidget)
24
+ directives.widget(topics=TranslatedAjaxSelectFieldWidget)
@@ -8,10 +8,36 @@ from plone.app.dexterity.behaviors.metadata import IBasic
8
8
  from plone.app.textfield.value import IRichTextValue
9
9
  from plone.app.textfield.value import RichTextValue
10
10
  from plone.dexterity.utils import iterSchemata
11
+ from plone.registry.interfaces import IRegistry
12
+ from Products.CMFPlone.resources.browser.resource import update_resource_registry_mtime
13
+ from zope.component import queryUtility
14
+ from zope.component.hooks import setSite
11
15
  from zope.lifecycleevent.interfaces import IAttributes
12
16
  from zope.schema import getFields
13
17
 
14
18
  import DateTime
19
+ import os
20
+ import Zope2
21
+
22
+
23
+ def started_zope(event):
24
+ db = Zope2.DB
25
+ connection = db.open()
26
+ zope_app = connection.root().get("Application", None)
27
+ site_id = os.getenv("SITE_ID", "Plone")
28
+ try:
29
+ site = zope_app.unrestrictedTraverse(site_id)
30
+ except KeyError:
31
+ # This happens when there is no site (ex: tests setups)
32
+ return
33
+ setSite(site)
34
+ registry = queryUtility(IRegistry)
35
+ if registry is None:
36
+ # This happens for example during site creation
37
+ return
38
+ # update resource registry time to invalidate its cache at startup
39
+ # this information is also used as ETag
40
+ update_resource_registry_mtime()
15
41
 
16
42
 
17
43
  def reindex_breadcrumb(obj, event):
@@ -1,6 +1,9 @@
1
1
  <configure
2
2
  xmlns="http://namespaces.zope.org/zope">
3
3
 
4
+ <subscriber for="zope.processlifetime.IProcessStarting"
5
+ handler=".subscribers.started_zope"/>
6
+
4
7
  <subscriber for="plone.dexterity.interfaces.IDexterityContent
5
8
  zope.lifecycleevent.interfaces.IObjectAddedEvent"
6
9
  handler=".subscribers.added_content" />
@@ -0,0 +1,61 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ from imio.smartweb.common.testing import IMIO_SMARTWEB_COMMON_INTEGRATION_TESTING
4
+ from imio.smartweb.common.widgets.select import TranslatedAjaxSelectWidget
5
+ from plone.api import portal as portal_api
6
+ from zope.publisher.browser import TestRequest
7
+
8
+ import mock
9
+ import unittest
10
+
11
+
12
+ class TestVocabulary(unittest.TestCase):
13
+ layer = IMIO_SMARTWEB_COMMON_INTEGRATION_TESTING
14
+
15
+ def setUp(self):
16
+ """Custom shared utility setup for tests"""
17
+ self.request = TestRequest()
18
+
19
+ def test_translated_ajax_select(self):
20
+ portal_api.get_current_language = mock.Mock(return_value="fr")
21
+ widget = TranslatedAjaxSelectWidget(self.request)
22
+ widget.update()
23
+ self.assertEqual(
24
+ {
25
+ "name": None,
26
+ "value": "",
27
+ "pattern": "select2",
28
+ "pattern_options": {"separator": ";"},
29
+ },
30
+ widget._base_args(),
31
+ )
32
+
33
+ widget.vocabulary = "imio.smartweb.vocabulary.Topics"
34
+ self.assertEqual(
35
+ widget._base_args(),
36
+ {
37
+ "name": None,
38
+ "value": "",
39
+ "pattern": "select2",
40
+ "pattern_options": {
41
+ "vocabularyUrl": "http://nohost/plone/@@getVocabulary?name=imio.smartweb.vocabulary.Topics",
42
+ "separator": ";",
43
+ },
44
+ },
45
+ )
46
+ widget.value = "entertainment"
47
+ self.assertEqual(
48
+ widget._base_args(),
49
+ {
50
+ "name": None,
51
+ "value": "entertainment",
52
+ "pattern": "select2",
53
+ "pattern_options": {
54
+ "vocabularyUrl": "http://nohost/plone/@@getVocabulary?name=imio.smartweb.vocabulary.Topics",
55
+ "initialValues": {
56
+ "entertainment": "Activités et divertissement",
57
+ },
58
+ "separator": ";",
59
+ },
60
+ },
61
+ )
File without changes
@@ -0,0 +1,31 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ from plone import api
4
+ from plone.app.z3cform.widget import AjaxSelectWidget
5
+ from z3c.form.interfaces import IFieldWidget
6
+ from z3c.form.widget import FieldWidget
7
+ from zope.interface import implementer
8
+ from zope.i18n import translate
9
+
10
+
11
+ class TranslatedAjaxSelectWidget(AjaxSelectWidget):
12
+ """Translated Ajax select widget for z3c.form."""
13
+
14
+ def _ajaxselect_options(self):
15
+ options = super(TranslatedAjaxSelectWidget, self)._ajaxselect_options()
16
+ current_lang = api.portal.get_current_language()[:2]
17
+ translated_initial_values = {}
18
+ for token, value in list(options.get("initialValues", {}).items()):
19
+ translated_initial_values[token] = translate(
20
+ value, domain="imio.smartweb", target_language=current_lang
21
+ )
22
+ if translated_initial_values:
23
+ options["initialValues"] = translated_initial_values
24
+ return options
25
+
26
+
27
+ @implementer(IFieldWidget)
28
+ def TranslatedAjaxSelectFieldWidget(field, request, extra=None):
29
+ if extra is not None:
30
+ request = extra
31
+ return FieldWidget(field, TranslatedAjaxSelectWidget(request))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: imio.smartweb.common
3
- Version: 1.2.15
3
+ Version: 1.2.17
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
@@ -161,6 +161,21 @@ Changelog
161
161
  =========
162
162
 
163
163
 
164
+ 1.2.17 (2024-06-06)
165
+ -------------------
166
+
167
+ - WEB-4113 : Add `TranslatedAjaxSelectFieldWidget` to fix translations of initial
168
+ values in select2 fields
169
+ [laulaz]
170
+
171
+
172
+ 1.2.16 (2024-05-30)
173
+ -------------------
174
+
175
+ - WEB-4107 : Update resource registries modification time (used as ETag) at Zope startup
176
+ [laulaz]
177
+
178
+
164
179
  1.2.15 (2024-05-27)
165
180
  -------------------
166
181
 
@@ -1,4 +1,4 @@
1
- imio.smartweb.common-1.2.15-py3.11-nspkg.pth,sha256=XZ3YhlzwpUCC8tXtelHRqxVxo3NWomIiMsUfUshrbeE,1011
1
+ imio.smartweb.common-1.2.17-py3.11-nspkg.pth,sha256=XZ3YhlzwpUCC8tXtelHRqxVxo3NWomIiMsUfUshrbeE,1011
2
2
  imio/smartweb/common/__init__.py,sha256=Na9XBfEQUMrm2c5jbqQgwWeg40ih0aXVG1vT8NeAjMQ,2709
3
3
  imio/smartweb/common/adapters.py,sha256=rLlObjqZm3hs2hgUT-LmJytwhT-E1rTvbpIi0mmKQqY,610
4
4
  imio/smartweb/common/adapters.zcml,sha256=ndYNj0J_BFfVpX_7JhY2asSwLzXG-WmjLdfwL9hX_No,254
@@ -14,8 +14,8 @@ imio/smartweb/common/privacy.py,sha256=ePuR-c-w7AmXSWA6czpfFK-wYNdoCm5yzEUKNSFKD
14
14
  imio/smartweb/common/privacy.zcml,sha256=KHC4JJt-9MbPcHHukN7QLwpMFXj96gXb0-vzU2ZboGk,1772
15
15
  imio/smartweb/common/profiles.zcml,sha256=EJoh-_QIN8ozCsPiEnx2mBmqC0vLrL7KF69PD90b6Zg,1278
16
16
  imio/smartweb/common/setuphandlers.py,sha256=ejKHdgROXjmDM7dgoAh9sITiAJDfQGNxTEOO5JaSEaE,1053
17
- imio/smartweb/common/subscribers.py,sha256=GHG_PIqsNV7K-pr_cXceQx1WCXylvQiv1lCgSGNJIno,2608
18
- imio/smartweb/common/subscribers.zcml,sha256=WZNhGtbTux2DoWHhLCQd1uJY27VhVLsibf0bdsclHOU,860
17
+ imio/smartweb/common/subscribers.py,sha256=pbPQJ1YrfPlYCfxLAJ5sOy_5OToAfs2egX68z2-EFRw,3490
18
+ imio/smartweb/common/subscribers.zcml,sha256=8v2lqNNVAHlrh2G3jtjVgr3Asrw8WJLS9jSX5U6juFg,971
19
19
  imio/smartweb/common/testing.py,sha256=GKlYMHJUSxZFVX0o_R_c_Au1VYlkd-GjykQqfONHv7I,1985
20
20
  imio/smartweb/common/testing.zcml,sha256=7N-ALtklyWeLSzZmlxN2Tp-aZe_3An--w_6BGl1991E,172
21
21
  imio/smartweb/common/utils.py,sha256=jzNLR41JVehAxqqQV2WaUiYkB1V6xpMpPGE-G3JJ7Pc,7041
@@ -24,7 +24,7 @@ imio/smartweb/common/vocabularies.zcml,sha256=iFJer5q3wabBp_EZivPPVUqI1_9w5P_Ft1
24
24
  imio/smartweb/common/behaviors/__init__.py,sha256=iwhKnzeBJLKxpRVjvzwiRE63_zNpIBfaKLITauVph-0,24
25
25
  imio/smartweb/common/behaviors/configure.zcml,sha256=RfGH8DIybHpxxe2HUsjH2QKSiWYpV7lCZhGN6KLFwCw,531
26
26
  imio/smartweb/common/behaviors/iam.py,sha256=17ON7M6FHXOM_8NOHT_QnJJuAIs4diWCrguHP6Lh5oA,825
27
- imio/smartweb/common/behaviors/topics.py,sha256=mguoFXN5XjcGXvA5HeV_l7-gJ5eR0hfjN1nbXYogcWw,832
27
+ imio/smartweb/common/behaviors/topics.py,sha256=K9XkhTBxxp_nBBeQ-ovUpmOc6raXIiYqmzJtlKVdhbI,863
28
28
  imio/smartweb/common/browser/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
29
29
  imio/smartweb/common/browser/collective_taxonomy_controlpanel.py,sha256=QngrsXOIjOt0xHEt2r0W66CPg5msY4H7mDkRaAEGQdg,3044
30
30
  imio/smartweb/common/browser/configure.zcml,sha256=1cDR2cy7O6WX33cFmbJU971wxg22LkLJYiMKCmBTWrA,3177
@@ -97,6 +97,7 @@ imio/smartweb/common/tests/test_utils.py,sha256=S4QrNVvkHv3Oxp45fWQ65dmGsk7POgUn
97
97
  imio/smartweb/common/tests/test_viewlets.py,sha256=NVEZWEmYo4K_-81Q6w-JTx2nT_3NBcJCl3946MAUnhU,1738
98
98
  imio/smartweb/common/tests/test_vocabularies.py,sha256=C-78USTvOHljuMSLkNb9onSRxLEJmBQLpktetAO74RE,848
99
99
  imio/smartweb/common/tests/test_vocabulary.py,sha256=4E5i5znt_hLhnnRay1iBaOZRmQyFJs8-OMdPm4iSGSg,1638
100
+ imio/smartweb/common/tests/test_widgets.py,sha256=FQ2FphLRZQ1yuMngQ6cu4LxDaLVTAg1VyIUILV0XRUI,2009
100
101
  imio/smartweb/common/tests/resources/image.png,sha256=GBnPJt2ALEefn8GJAY1Lh8o9L6l6G77GJSyS0uveHvQ,1185
101
102
  imio/smartweb/common/tests/resources/image_1400x800.png,sha256=Iy3bWGH4NBlgYC5BolZiNYFTKmCm0_I9MZDZo4sw_V4,30604
102
103
  imio/smartweb/common/tests/resources/image_1800x700.png,sha256=aQcMisSFQO78c6QX4mO7qIfDb9SDRmfzTuPjxMJ_0HM,32643
@@ -132,10 +133,12 @@ imio/smartweb/common/viewlets/privacy.pt,sha256=bAD-I6s3LUgkh30vyTbP3pNUZQYua1Kx
132
133
  imio/smartweb/common/viewlets/privacy.py,sha256=H752etTTIFCM0wTwjESQFl0PStJfCoSRfcePSUQOp8E,449
133
134
  imio/smartweb/common/viewlets/skip_to_content.pt,sha256=FFfTxvRl8V52FzFE6In6B34ApgShNntvMp6F1qwfL0g,376
134
135
  imio/smartweb/common/viewlets/skip_to_content.py,sha256=wm22NUf8Qh5uzz8p4vkLCdFNiDv9zUGAueRyXAIXQDo,496
135
- imio.smartweb.common-1.2.15.dist-info/LICENSE.GPL,sha256=gXf5dRMhNSbfLPYYTY_5hsZ1r7UU1OaKQEAQUhuIBkM,18092
136
- imio.smartweb.common-1.2.15.dist-info/LICENSE.rst,sha256=5dd78Fdt0e-oM2ICBrMpjHnT8vEP-jhBDF7akXni6B4,655
137
- imio.smartweb.common-1.2.15.dist-info/METADATA,sha256=hpPy5ZJ6R9wtfDuXI7FP-z057PBjqVekgZ-hGJX-Qcg,14848
138
- imio.smartweb.common-1.2.15.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
139
- imio.smartweb.common-1.2.15.dist-info/namespace_packages.txt,sha256=Pg8AH8t9viMMW1hJbNZvTy_n2jXG2igIYUpon5RA4Js,19
140
- imio.smartweb.common-1.2.15.dist-info/top_level.txt,sha256=ZktC0EGzThvMTAin9_q_41rzvvfMT2FYbP8pbhSLMSA,5
141
- imio.smartweb.common-1.2.15.dist-info/RECORD,,
136
+ imio/smartweb/common/widgets/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
137
+ imio/smartweb/common/widgets/select.py,sha256=vfVdbecH7qDfJvWV6TfkpqocD6AA5G4yIq7XqSOuVNw,1142
138
+ imio.smartweb.common-1.2.17.dist-info/LICENSE.GPL,sha256=gXf5dRMhNSbfLPYYTY_5hsZ1r7UU1OaKQEAQUhuIBkM,18092
139
+ imio.smartweb.common-1.2.17.dist-info/LICENSE.rst,sha256=5dd78Fdt0e-oM2ICBrMpjHnT8vEP-jhBDF7akXni6B4,655
140
+ imio.smartweb.common-1.2.17.dist-info/METADATA,sha256=JSs5I9lmfEo-eKA4m96TnRIXC7FIYwANeUBFn9i6EdE,15154
141
+ imio.smartweb.common-1.2.17.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
142
+ imio.smartweb.common-1.2.17.dist-info/namespace_packages.txt,sha256=Pg8AH8t9viMMW1hJbNZvTy_n2jXG2igIYUpon5RA4Js,19
143
+ imio.smartweb.common-1.2.17.dist-info/top_level.txt,sha256=ZktC0EGzThvMTAin9_q_41rzvvfMT2FYbP8pbhSLMSA,5
144
+ imio.smartweb.common-1.2.17.dist-info/RECORD,,