imio.smartweb.common 1.2.12__py3-none-any.whl → 1.2.13__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.
Files changed (31) hide show
  1. imio/smartweb/common/browser/collective_taxonomy_controlpanel.py +63 -0
  2. imio/smartweb/common/browser/configure.zcml +16 -0
  3. imio/smartweb/common/browser/static/smartweb-common-view-compiled.css +1 -1
  4. imio/smartweb/common/browser/static/src/view.less +9 -2
  5. imio/smartweb/common/browser/vocabulary.py +26 -0
  6. imio/smartweb/common/interfaces.py +2 -1
  7. imio/smartweb/common/profiles/default/metadata.xml +1 -1
  8. imio/smartweb/common/profiles/default/registry.xml +10 -4
  9. imio/smartweb/common/profiles/testing/catalog.xml +9 -0
  10. imio/smartweb/common/profiles/testing/metadata.xml +1 -0
  11. imio/smartweb/common/profiles/testing/types/Document.xml +1 -0
  12. imio/smartweb/common/rest/search_filters.py +19 -7
  13. imio/smartweb/common/testing.py +1 -1
  14. imio/smartweb/common/testing.zcml +8 -0
  15. imio/smartweb/common/tests/test_rest.py +25 -0
  16. imio/smartweb/common/tests/test_taxonomy.py +140 -0
  17. imio/smartweb/common/tests/test_vocabulary.py +45 -0
  18. imio/smartweb/common/upgrades/configure.zcml +36 -0
  19. imio/smartweb/common/upgrades/profiles/1027_to_1028/restored-faceted-jquery.xml +7 -0
  20. imio/smartweb/common/upgrades/profiles/1028_to_1029/registry.xml +15 -0
  21. imio/smartweb/common/utils.py +9 -1
  22. imio/smartweb/common/vocabularies.py +1 -10
  23. {imio.smartweb.common-1.2.12.dist-info → imio.smartweb.common-1.2.13.dist-info}/METADATA +21 -1
  24. {imio.smartweb.common-1.2.12.dist-info → imio.smartweb.common-1.2.13.dist-info}/RECORD +30 -23
  25. imio/smartweb/common/browser/static/patched.web3862.eea.faceted-jquery.min.js +0 -2
  26. /imio.smartweb.common-1.2.12-py3.10-nspkg.pth → /imio.smartweb.common-1.2.13-py3.10-nspkg.pth +0 -0
  27. {imio.smartweb.common-1.2.12.dist-info → imio.smartweb.common-1.2.13.dist-info}/LICENSE.GPL +0 -0
  28. {imio.smartweb.common-1.2.12.dist-info → imio.smartweb.common-1.2.13.dist-info}/LICENSE.rst +0 -0
  29. {imio.smartweb.common-1.2.12.dist-info → imio.smartweb.common-1.2.13.dist-info}/WHEEL +0 -0
  30. {imio.smartweb.common-1.2.12.dist-info → imio.smartweb.common-1.2.13.dist-info}/namespace_packages.txt +0 -0
  31. {imio.smartweb.common-1.2.12.dist-info → imio.smartweb.common-1.2.13.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,63 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ from collective.taxonomy.interfaces import ITaxonomy
4
+ from collective.taxonomy.jsonimpl import ImportJson as baseImportJson
5
+ from imio.smartweb.locales import SmartwebMessageFactory as _
6
+ from plone import api
7
+ from zope.component import queryUtility
8
+ from zope.i18n import translate
9
+
10
+ import json
11
+
12
+
13
+ class ImportJson(baseImportJson):
14
+ """Update taxonomy using json data."""
15
+
16
+ def __call__(self):
17
+ request = self.request
18
+ if request.method == "POST":
19
+ data = json.loads(request.get("BODY", ""))
20
+ taxonomy = queryUtility(ITaxonomy, name=data["taxonomy"])
21
+ languages = data["languages"]
22
+ items_to_check = []
23
+ nodes = data["tree"]["subnodes"]
24
+ for language in languages:
25
+ for node in nodes:
26
+ if node["translations"].get(language):
27
+ items_to_check.append(
28
+ {node["key"]: node["translations"][language]}
29
+ )
30
+ ids_remaining = [key for data in items_to_check for key in data.keys()]
31
+ if not taxonomy.inverted_data.get(language):
32
+ continue
33
+ initial_taxonomy_ids = [k for k in taxonomy.inverted_data[language]]
34
+ for id in initial_taxonomy_ids:
35
+ if id in ids_remaining:
36
+ continue
37
+ # This is a removed term
38
+ catalog = api.portal.get_tool("portal_catalog")
39
+ brains = catalog.searchResults(
40
+ object_provides=taxonomy.getGeneratedName()
41
+ )
42
+ for brain in brains:
43
+ index_key = f"taxonomy_{taxonomy.getShortName()}"
44
+ if hasattr(brain, index_key) and id in getattr(
45
+ brain, index_key
46
+ ):
47
+ obj = brain.getObject()
48
+ here = obj.absolute_url()
49
+ term_title = taxonomy.translate(
50
+ id, context=obj, target_language=language
51
+ )
52
+ return json.dumps(
53
+ {
54
+ "status": "error",
55
+ "message": translate(
56
+ _(
57
+ f'Term "{term_title}" can\'t be removed because it is used (at least) here : {here}'
58
+ ),
59
+ context=request,
60
+ ),
61
+ }
62
+ )
63
+ return super(ImportJson, self).__call__()
@@ -73,6 +73,14 @@
73
73
  layer="imio.smartweb.common.interfaces.IImioSmartwebCommonLayer"
74
74
  />
75
75
 
76
+ <browser:page
77
+ name="getVocabulary"
78
+ for="*"
79
+ class=".vocabulary.TranslatedVocabularyView"
80
+ permission="zope2.View"
81
+ layer="imio.smartweb.common.interfaces.IImioSmartwebCommonLayer"
82
+ />
83
+
76
84
  <browser:page
77
85
  for="plone.app.layout.navigation.interfaces.INavigationRoot"
78
86
  name="image_scale"
@@ -82,4 +90,12 @@
82
90
  allowed_attributes="scale tag"
83
91
  />
84
92
 
93
+ <browser:page
94
+ name="taxonomy-import"
95
+ for="Products.CMFCore.interfaces.ISiteRoot"
96
+ class=".collective_taxonomy_controlpanel.ImportJson"
97
+ permission="collective.taxonomy.ManageTaxonomies"
98
+ layer="imio.smartweb.common.interfaces.IImioSmartwebCommonLayer"
99
+ />
100
+
85
101
  </configure>
@@ -1 +1 @@
1
- .show-on-focus{border-radius:5px;box-shadow:0 0 2.9px rgba(0,0,0,.028),0 0 8.1px rgba(0,0,0,.04),0 0 19.6px rgba(0,0,0,.052),0 0 65px rgba(0,0,0,.08);display:inline-block;font-weight:500;left:10px;position:absolute!important;text-decoration:none;top:10px}.show-on-focus:not(:focus){clip:rect(0,0,0,0);border-width:0;height:1px!important;margin:-1px;overflow:hidden;padding:0!important;white-space:nowrap;width:1px!important}.show-on-focus:focus{background-color:#fff;padding:1rem;z-index:999}.show-on-focus:hover{text-decoration:underline}form .form-text{margin-bottom:.3em;margin-top:-.4em}#cookies-form #form-widgets-all_basic_cookies,#cookies-form .form-text p,#cookies-form label span.required{display:none}#gdpr-consent-banner{background:orange;display:none;left:0;padding:5px;position:fixed;top:0;width:100%;z-index:999999}.faceted-select-widget.faceted-zero-count-hidden .faceted-select-item-disabled{display:none}
1
+ .show-on-focus{border-radius:5px;box-shadow:0 0 2.9px rgba(0,0,0,.028),0 0 8.1px rgba(0,0,0,.04),0 0 19.6px rgba(0,0,0,.052),0 0 65px rgba(0,0,0,.08);color:#000!important;display:inline-block;font-weight:500;left:10px;position:absolute!important;text-decoration:none;top:10px}.show-on-focus:not(:focus){clip:rect(0,0,0,0);border-width:0;height:1px!important;margin:-1px;overflow:hidden;padding:0!important;white-space:nowrap;width:1px!important}.show-on-focus:focus{background-color:#fff!important;padding:1rem;z-index:999}.show-on-focus:hover{text-decoration:underline}#smartweb-footer{position:relative}#smartweb-footer .show-on-focus{color:#000!important}form .form-text{margin-bottom:.3em;margin-top:-.4em}#cookies-form #form-widgets-all_basic_cookies,#cookies-form .form-text p,#cookies-form label span.required{display:none}#gdpr-consent-banner{background:orange;display:none;left:0;padding:5px;position:fixed;top:0;width:100%;z-index:999999}.faceted-select-widget.faceted-zero-count-hidden .faceted-select-item-disabled{display:none}
@@ -8,7 +8,7 @@
8
8
  border-radius: 5px;
9
9
  box-shadow: 0px 0px 2.9px rgba(0, 0, 0, 0.028), 0px 0px 8.1px rgba(0, 0, 0, 0.04), 0px 0px 19.6px rgba(0, 0, 0, 0.052), 0px 0px 65px rgba(0, 0, 0, 0.08);
10
10
  font-weight: 500;
11
-
11
+ color: #000 !important;
12
12
  &:not(:focus) {
13
13
  width: 1px !important;
14
14
  height: 1px !important;
@@ -21,7 +21,7 @@
21
21
  }
22
22
 
23
23
  &:focus {
24
- background-color: #FFFFFF;
24
+ background-color: #FFFFFF!important;
25
25
  padding: 1rem;
26
26
  z-index: 999;
27
27
  }
@@ -31,6 +31,13 @@
31
31
  }
32
32
  }
33
33
 
34
+ #smartweb-footer {
35
+ position: relative;
36
+ .show-on-focus {
37
+ color: #000!important;
38
+ }
39
+ }
40
+
34
41
  // Fields description position between title and input.
35
42
  form .form-text {
36
43
  margin-top: -0.4em;
@@ -0,0 +1,26 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ from imio.smartweb.locales import SmartwebMessageFactory as _
4
+ from plone import api
5
+ from plone.app.content.browser.vocabulary import VocabularyView
6
+ from plone.app.content.utils import json_dumps
7
+ from plone.app.content.utils import json_loads
8
+ from zope.i18n import translate
9
+
10
+
11
+ class TranslatedVocabularyView(VocabularyView):
12
+
13
+ def __call__(self):
14
+ """
15
+ Translate texts in JSON response
16
+ `@getVocabulary` does not do it and returns English values
17
+ """
18
+ result = super(TranslatedVocabularyView, self).__call__()
19
+ json = json_loads(result)
20
+ if int(json.get("total", 0)) == 0:
21
+ return result
22
+ lang = api.portal.get_current_language()[:2]
23
+ for item in json["results"]:
24
+ if "text" in item:
25
+ item["text"] = translate(_(item["text"]), target_language=lang)
26
+ return json_dumps(json)
@@ -1,6 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  from collective.privacy.interfaces import ICollectivePrivacyLayer
4
+ from collective.taxonomy.interfaces import IBrowserLayer
4
5
  from imio.smartweb.locales import SmartwebMessageFactory as _
5
6
  from plone import schema
6
7
  from plone.app.z3cform.interfaces import IPloneFormLayer
@@ -10,7 +11,7 @@ from zope.interface import Interface
10
11
 
11
12
 
12
13
  class IImioSmartwebCommonLayer(
13
- IDefaultPloneLayer, IPloneFormLayer, ICollectivePrivacyLayer
14
+ IBrowserLayer, IDefaultPloneLayer, IPloneFormLayer, ICollectivePrivacyLayer
14
15
  ):
15
16
  """Marker interface that defines a browser layer."""
16
17
 
@@ -1,6 +1,6 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
2
  <metadata>
3
- <version>1026</version>
3
+ <version>1029</version>
4
4
  <dependencies>
5
5
  <dependency>profile-plone.restapi:default</dependency>
6
6
  <dependency>profile-eea.facetednavigation:default</dependency>
@@ -54,10 +54,6 @@
54
54
  <value key="load_defer">False</value>
55
55
  </records>
56
56
 
57
- <records prefix="plone.bundles/faceted.jquery"
58
- interface='Products.CMFPlone.interfaces.IBundleRegistry'>
59
- <value key="jscompilation">++plone++imio.smartweb.common/patched.web3862.eea.faceted-jquery.min.js</value>
60
- </records>
61
57
 
62
58
  <!-- TinyMCE custom configuration -->
63
59
 
@@ -1080,4 +1076,14 @@
1080
1076
  <value>False</value>
1081
1077
  </record>
1082
1078
 
1079
+ <record name="imio.smartweb.common.activate_sending_data_to_odwb_for_staging">
1080
+ <field type="plone.registry.field.Bool">
1081
+ <title>Activate sending data to odwb for staging</title>
1082
+ <description>Be careful, it must be existing an odwb table prefixing with staging and naming like prod table. Also, smartweb registry keys (odwb pushkey) must be respect.</description>
1083
+ <required>False</required>
1084
+ </field>
1085
+ <value>False</value>
1086
+ </record>
1087
+
1088
+
1083
1089
  </registry>
@@ -0,0 +1,9 @@
1
+ <?xml version="1.0"?>
2
+ <object name="portal_catalog">
3
+
4
+ <column value="local_category"/>
5
+ <column value="local_category_nl"/>
6
+ <column value="local_category_de"/>
7
+ <column value="local_category_en"/>
8
+
9
+ </object>
@@ -2,5 +2,6 @@
2
2
  <metadata>
3
3
  <dependencies>
4
4
  <dependency>profile-imio.smartweb.common:default</dependency>
5
+ <dependency>profile-collective.taxonomy:examples</dependency>
5
6
  </dependencies>
6
7
  </metadata>
@@ -5,6 +5,7 @@
5
5
  i18n:domain="plone">
6
6
 
7
7
  <property name="behaviors" purge="false">
8
+ <element value="collective.taxonomy.generated.test"/>
8
9
  <element value="imio.smartweb.iam"/>
9
10
  <element value="imio.smartweb.topics"/>
10
11
  <element value="plone.leadimage"/>
@@ -1,6 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  from imio.smartweb.common.config import VOCABULARIES_MAPPING
4
+ from imio.smartweb.common.rest.utils import get_restapi_query_lang
4
5
  from imio.smartweb.common.utils import get_term_from_vocabulary
5
6
  from operator import itemgetter
6
7
  from plone.restapi.search.handler import SearchHandler
@@ -13,6 +14,7 @@ from zope.component import getMultiAdapter
13
14
 
14
15
  # we don't need some brains metadata to construct search filters
15
16
  EXCLUDED_METADATA = [
17
+ "container_uid",
16
18
  "effective",
17
19
  "end",
18
20
  "has_leadimage",
@@ -65,6 +67,9 @@ class SearchFiltersHandler(SearchHandler):
65
67
  if not isinstance(metadatas, list):
66
68
  metadatas = [metadatas]
67
69
 
70
+ lang = get_restapi_query_lang(query)
71
+ local_categories_trans = {}
72
+
68
73
  metadatas = list(set(metadatas) - set(EXCLUDED_METADATA))
69
74
  filters = {metadata: set() for metadata in metadatas}
70
75
  for brain in brains:
@@ -72,11 +77,14 @@ class SearchFiltersHandler(SearchHandler):
72
77
  value = getattr(brain, metadata, None)
73
78
  if not value:
74
79
  continue
75
- if isinstance(value, list) or isinstance(value, tuple):
76
- for v in value:
77
- filters[metadata].add(v)
78
- else:
79
- filters[metadata].add(value)
80
+ if not isinstance(value, (list, tuple)):
81
+ value = [value]
82
+ for v in value:
83
+ filters[metadata].add(v)
84
+ if metadata == "local_category":
85
+ local_categories_trans[v] = getattr(
86
+ brain, f"{metadata}_{lang}", v
87
+ )
80
88
 
81
89
  results = {}
82
90
  for metadata, values in filters.items():
@@ -91,8 +99,12 @@ class SearchFiltersHandler(SearchHandler):
91
99
  term = serializer()
92
100
  term["title"] = json_compatible(title) # needed for translations
93
101
  results[metadata].append(term)
94
- results[metadata].sort(key=itemgetter("title"))
102
+ elif metadata == "local_category":
103
+ results[metadata] = [
104
+ {"token": v, "title": local_categories_trans[v]} for v in values
105
+ ]
95
106
  else:
96
- results[metadata] = [{"token": v, "title": v} for v in sorted(values)]
107
+ results[metadata] = [{"token": v, "title": v} for v in values]
108
+ results[metadata].sort(key=itemgetter("title"))
97
109
 
98
110
  return results
@@ -26,7 +26,7 @@ class ImioSmartwebCommonLayer(PloneSandboxLayer):
26
26
  import plone.restapi
27
27
 
28
28
  self.loadZCML(package=plone.restapi)
29
- self.loadZCML(package=imio.smartweb.common)
29
+ self.loadZCML(package=imio.smartweb.common, name="testing.zcml")
30
30
 
31
31
  def setUpPloneSite(self, portal):
32
32
  api.user.create(email="test@imio.be", username="test")
@@ -0,0 +1,8 @@
1
+ <configure
2
+ xmlns="http://namespaces.zope.org/zope">
3
+
4
+ <include package="collective.taxonomy" file="testing.zcml" />
5
+
6
+ <include file="configure.zcml" />
7
+
8
+ </configure>
@@ -31,6 +31,10 @@ class TestREST(unittest.TestCase):
31
31
  title="Doc 1",
32
32
  )
33
33
  self.doc1.topics = ["agriculture"]
34
+ self.doc1.local_category = "Titre FR"
35
+ self.doc1.local_category_nl = "NL title"
36
+ self.doc1.local_category_de = "DE title"
37
+ self.doc1.local_category_en = "EN title"
34
38
  api.content.transition(self.doc1, "publish")
35
39
 
36
40
  self.doc2 = api.content.create(
@@ -100,11 +104,31 @@ class TestREST(unittest.TestCase):
100
104
  ],
101
105
  )
102
106
 
107
+ query = {
108
+ "portal_type": "Document",
109
+ "metadata_fields": "local_category",
110
+ }
111
+ response = self.api_session.get("/@search-filters", params=query)
112
+ json = response.json()
113
+ self.assertEqual(
114
+ json["local_category"],
115
+ [{"title": "Titre FR", "token": "Titre FR"}],
116
+ )
117
+ query["translated_in_nl"] = 1
118
+ response = self.api_session.get("/@search-filters", params=query)
119
+ json = response.json()
120
+ self.assertEqual(
121
+ json["local_category"],
122
+ [{"title": "NL title", "token": "Titre FR"}],
123
+ )
124
+ del query["translated_in_nl"]
125
+
103
126
  query = {
104
127
  "portal_type": "Event",
105
128
  "metadata_fields": [
106
129
  "iam",
107
130
  "topics",
131
+ "container_uid",
108
132
  "effective",
109
133
  "end",
110
134
  "has_leadimage",
@@ -114,6 +138,7 @@ class TestREST(unittest.TestCase):
114
138
  }
115
139
  response = self.api_session.get("/@search-filters", params=query)
116
140
  json = response.json()
141
+ self.assertNotIn("container_uid", json)
117
142
  self.assertNotIn("effective", json)
118
143
  self.assertNotIn("end", json)
119
144
  self.assertNotIn("has_leadimage", json)
@@ -0,0 +1,140 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ from imio.smartweb.common.testing import IMIO_SMARTWEB_COMMON_FUNCTIONAL_TESTING
4
+ from plone import api
5
+ from plone.app.testing import setRoles
6
+ from plone.app.testing import TEST_USER_ID
7
+ from plone.app.testing.interfaces import SITE_OWNER_NAME
8
+ from plone.app.testing.interfaces import SITE_OWNER_PASSWORD
9
+ from plone.testing.z2 import Browser
10
+ from transaction import commit
11
+
12
+ import json
13
+ import unittest
14
+
15
+
16
+ class TestTaxonomy(unittest.TestCase):
17
+ layer = IMIO_SMARTWEB_COMMON_FUNCTIONAL_TESTING
18
+
19
+ def setUp(self):
20
+ """Custom shared utility setup for tests"""
21
+ self.request = self.layer["request"]
22
+ self.portal = self.layer["portal"]
23
+ setRoles(self.portal, TEST_USER_ID, ["Manager"])
24
+ self.browser = Browser(self.layer["app"])
25
+ self.browser.handleErrors = False
26
+ self.browser.addHeader(
27
+ "Authorization",
28
+ "Basic {0}:{1}".format(SITE_OWNER_NAME, SITE_OWNER_PASSWORD),
29
+ )
30
+ commit()
31
+ self.page = api.content.create(
32
+ container=self.portal,
33
+ type="Document",
34
+ title="Test page",
35
+ )
36
+
37
+ def test_removing_unused_taxonomy_term(self):
38
+ body_data = {
39
+ "languages": ["fr", "en", "nl", "ru", "da", "de"],
40
+ "tree": {
41
+ "key": "0",
42
+ "title": "Test vocabulary",
43
+ "subnodes": [
44
+ {
45
+ "key": "1",
46
+ "translations": {
47
+ "da": "Informationsvidenskab",
48
+ "de": "Informatik",
49
+ "en": "Information Science",
50
+ "ru": "Информатику",
51
+ },
52
+ "subnodes": [
53
+ {
54
+ "key": "3",
55
+ "translations": {"da": "Kronologi", "en": "Chronology"},
56
+ "subnodes": [],
57
+ }
58
+ ],
59
+ }
60
+ ],
61
+ "default_language": "da",
62
+ },
63
+ "taxonomy": "collective.taxonomy.test",
64
+ }
65
+ json_str = json.dumps(body_data)
66
+ bytes_data = json_str.encode("utf-8")
67
+ self.request.set("BODY", bytes_data)
68
+ self.request.method = "POST"
69
+ result = self.portal.restrictedTraverse("@@taxonomy-import")()
70
+ self.assertEqual(
71
+ result,
72
+ '{"status": "info", "message": "Your taxonomy has been saved with success."}',
73
+ )
74
+
75
+ def test_removing_used_taxonomy_term(self):
76
+ self.page.taxonomy_test = ["1", "2"]
77
+ body_data = {
78
+ "languages": ["fr", "en", "nl", "ru", "da", "de"],
79
+ "tree": {
80
+ "key": "0",
81
+ "title": "Test vocabulary",
82
+ "subnodes": [
83
+ {
84
+ "key": "1",
85
+ "translations": {
86
+ "da": "Informationsvidenskab",
87
+ "de": "Informatik",
88
+ "en": "Information Science",
89
+ "ru": "Информатику",
90
+ },
91
+ "subnodes": [
92
+ {
93
+ "key": "3",
94
+ "translations": {"da": "Kronologi", "en": "Chronology"},
95
+ "subnodes": [],
96
+ }
97
+ ],
98
+ }
99
+ ],
100
+ "default_language": "da",
101
+ },
102
+ "taxonomy": "collective.taxonomy.test",
103
+ }
104
+ json_str = json.dumps(body_data)
105
+ bytes_data = json_str.encode("utf-8")
106
+ self.request.set("BODY", bytes_data)
107
+ self.request.method = "POST"
108
+ result = self.portal.restrictedTraverse("@@taxonomy-import")()
109
+ self.assertEqual(
110
+ result,
111
+ '{"status": "error", "message": "Term \\"Information Science \\u00bb Book Collecting\\" can\'t be removed because it is used (at least) here : http://nohost/plone/test-page"}',
112
+ )
113
+
114
+ def test_removing_used_parent_taxonomy_term(self):
115
+ self.page.taxonomy_test = ["2"]
116
+ self.page.reindexObject()
117
+ catalog = api.portal.get_tool("portal_catalog")
118
+ brain = api.content.find(UID=self.page.UID())[0]
119
+ indexes = catalog.getIndexDataForRID(brain.getRID())
120
+ index = indexes.get("taxonomy_test")
121
+ self.assertListEqual(sorted(index), ["1", "2"])
122
+ body_data = {
123
+ "languages": ["fr", "en", "nl", "ru", "da", "de"],
124
+ "tree": {
125
+ "key": "0",
126
+ "title": "Test vocabulary",
127
+ "subnodes": [],
128
+ "default_language": "da",
129
+ },
130
+ "taxonomy": "collective.taxonomy.test",
131
+ }
132
+ json_str = json.dumps(body_data)
133
+ bytes_data = json_str.encode("utf-8")
134
+ self.request.set("BODY", bytes_data)
135
+ self.request.method = "POST"
136
+ result = self.portal.restrictedTraverse("@@taxonomy-import")()
137
+ self.assertEqual(
138
+ result,
139
+ '{"status": "error", "message": "Term \\"Information Science\\" can\'t be removed because it is used (at least) here : http://nohost/plone/test-page"}',
140
+ )
@@ -0,0 +1,45 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ from imio.smartweb.common.testing import IMIO_SMARTWEB_COMMON_INTEGRATION_TESTING
4
+ from plone import api
5
+ from plone.app.testing import setRoles
6
+ from plone.app.testing import TEST_USER_ID
7
+ from unittest.mock import patch
8
+ from zope.component import queryMultiAdapter
9
+
10
+ import json
11
+ import unittest
12
+
13
+
14
+ class TestVocabulary(unittest.TestCase):
15
+ layer = IMIO_SMARTWEB_COMMON_INTEGRATION_TESTING
16
+
17
+ def setUp(self):
18
+ """Custom shared utility setup for tests"""
19
+ self.request = self.layer["request"]
20
+ self.portal = self.layer["portal"]
21
+ setRoles(self.portal, TEST_USER_ID, ["Manager"])
22
+ self.document = api.content.create(
23
+ container=self.portal,
24
+ type="Document",
25
+ title="My Doc",
26
+ )
27
+
28
+ def test_getvocabulary(self):
29
+ self.request.form = {
30
+ "name": "imio.smartweb.vocabulary.Topics",
31
+ "field": "topics",
32
+ }
33
+ view = queryMultiAdapter((self.document, self.request), name="getVocabulary")
34
+ result = json.loads(view())
35
+ self.assertEqual(result["results"][0]["id"], "entertainment")
36
+ self.assertEqual(result["results"][0]["text"], "Entertainment")
37
+ with patch("plone.api.portal.get_current_language", return_value="fr"):
38
+ view = queryMultiAdapter(
39
+ (self.document, self.request), name="getVocabulary"
40
+ )
41
+ result = json.loads(view())
42
+ self.assertEqual(result["results"][0]["id"], "entertainment")
43
+ self.assertEqual(
44
+ result["results"][0]["text"], "Activités et divertissement"
45
+ )
@@ -116,6 +116,22 @@
116
116
  provides="Products.GenericSetup.interfaces.EXTENSION"
117
117
  />
118
118
 
119
+ <genericsetup:registerProfile
120
+ name="upgrade_1027_to_1028"
121
+ title="Upgrade common from 1027 to 1028"
122
+ directory="profiles/1027_to_1028"
123
+ description="Unpatch (restore original) eea.facetednavigation jquery"
124
+ provides="Products.GenericSetup.interfaces.EXTENSION"
125
+ />
126
+
127
+ <genericsetup:registerProfile
128
+ name="upgrade_1028_to_1029"
129
+ title="Upgrade common from 1028 to 1029"
130
+ directory="profiles/1028_to_1029"
131
+ description="Cover use case for sending data in odwb for a staging environment"
132
+ provides="Products.GenericSetup.interfaces.EXTENSION"
133
+ />
134
+
119
135
  <genericsetup:upgradeStep
120
136
  title="Configure first official release"
121
137
  description="Run needed registry step"
@@ -384,4 +400,24 @@
384
400
  profile="imio.smartweb.common:default"
385
401
  />
386
402
 
403
+ <genericsetup:upgradeSteps
404
+ source="1027"
405
+ destination="1028"
406
+ profile="imio.smartweb.common:default">
407
+ <genericsetup:upgradeDepends
408
+ title="Unpatch (restore original) eea.facetednavigation jquery"
409
+ import_profile="imio.smartweb.common.upgrades:upgrade_1027_to_1028"
410
+ />
411
+ </genericsetup:upgradeSteps>
412
+
413
+ <genericsetup:upgradeSteps
414
+ source="1028"
415
+ destination="1029"
416
+ profile="imio.smartweb.common:default">
417
+ <genericsetup:upgradeDepends
418
+ title="Cover use case for sending data in odwb for a staging environment"
419
+ import_profile="imio.smartweb.common.upgrades:upgrade_1028_to_1029"
420
+ />
421
+ </genericsetup:upgradeSteps>
422
+
387
423
  </configure>
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0"?>
2
+ <registry>
3
+ <records prefix="plone.bundles/faceted.jquery"
4
+ interface='Products.CMFPlone.interfaces.IBundleRegistry'>
5
+ <value key="jscompilation">++plone++facetednavigation/faceted-jquery.min.js</value>
6
+ </records>
7
+ </registry>
@@ -0,0 +1,15 @@
1
+ <?xml version="1.0"?>
2
+ <registry
3
+ xmlns:i18n="http://xml.zope.org/namespaces/i18n"
4
+ i18n:domain="imio.smartweb">
5
+
6
+ <record name="imio.smartweb.common.activate_sending_data_to_odwb_for_staging">
7
+ <field type="plone.registry.field.Bool">
8
+ <title>Activate sending data to odwb for staging</title>
9
+ <description>Be careful, it must be existing an odwb table prefixing with staging and naming like prod table. Also, smartweb registry keys (odwb pushkey) must be respect.</description>
10
+ <required>False</required>
11
+ </field>
12
+ <value>False</value>
13
+ </record>
14
+
15
+ </registry>
@@ -179,16 +179,24 @@ def is_staging_or_local():
179
179
  parsed_url = urlparse(portal_url)
180
180
  scheme = parsed_url.scheme
181
181
  netloc = parsed_url.netloc
182
- elem = ["localhost", "127.0.0.1", "nohost"]
182
+ elem = ["localhost", "127.0.0.1"]
183
183
  pattern = "|".join(map(re.escape, elem))
184
184
  if scheme == "http" and re.search(pattern, netloc):
185
185
  return True
186
186
  elif scheme == "https" and "staging" in netloc:
187
+ if activate_sending_data_to_odwb_for_staging() is True:
188
+ return False
187
189
  return True
188
190
  else:
189
191
  return False
190
192
 
191
193
 
194
+ def activate_sending_data_to_odwb_for_staging():
195
+ return api.portal.get_registry_record(
196
+ "imio.smartweb.common.activate_sending_data_to_odwb_for_staging", default=False
197
+ )
198
+
199
+
192
200
  def get_parent_of_type(context, content_type):
193
201
  # Traverse up the hierarchy until we find an object with the specified content type
194
202
  parent = context