imio.smartweb.common 1.2.8__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.
- imio/smartweb/common/behaviors/topics.py +2 -2
- imio/smartweb/common/browser/collective_taxonomy_controlpanel.py +63 -0
- imio/smartweb/common/browser/configure.zcml +16 -0
- imio/smartweb/common/browser/static/smartweb-common-view-compiled.css +1 -1
- imio/smartweb/common/browser/static/src/view.less +9 -2
- imio/smartweb/common/browser/vocabulary.py +26 -0
- imio/smartweb/common/interfaces.py +2 -1
- imio/smartweb/common/profiles/default/metadata.xml +1 -1
- imio/smartweb/common/profiles/default/registry.xml +10 -4
- imio/smartweb/common/profiles/testing/catalog.xml +9 -0
- imio/smartweb/common/profiles/testing/metadata.xml +1 -0
- imio/smartweb/common/profiles/testing/types/Document.xml +1 -0
- imio/smartweb/common/rest/odwb.py +67 -0
- imio/smartweb/common/rest/search_filters.py +19 -7
- imio/smartweb/common/testing.py +1 -1
- imio/smartweb/common/testing.zcml +8 -0
- imio/smartweb/common/tests/test_rest.py +38 -0
- imio/smartweb/common/tests/test_taxonomy.py +140 -0
- imio/smartweb/common/tests/test_vocabulary.py +45 -0
- imio/smartweb/common/upgrades/configure.zcml +44 -0
- imio/smartweb/common/upgrades/profiles/1027_to_1028/restored-faceted-jquery.xml +7 -0
- imio/smartweb/common/upgrades/profiles/1028_to_1029/registry.xml +15 -0
- imio/smartweb/common/upgrades/upgrades.py +7 -0
- imio/smartweb/common/utils.py +37 -0
- imio/smartweb/common/viewlets/skip_to_content.pt +6 -0
- {imio.smartweb.common-1.2.8.dist-info → imio.smartweb.common-1.2.13.dist-info}/METADATA +56 -4
- {imio.smartweb.common-1.2.8.dist-info → imio.smartweb.common-1.2.13.dist-info}/RECORD +33 -25
- {imio.smartweb.common-1.2.8.dist-info → imio.smartweb.common-1.2.13.dist-info}/WHEEL +1 -1
- imio/smartweb/common/browser/static/patched.web3862.eea.faceted-jquery.min.js +0 -2
- /imio.smartweb.common-1.2.8-py3.8-nspkg.pth → /imio.smartweb.common-1.2.13-py3.10-nspkg.pth +0 -0
- {imio.smartweb.common-1.2.8.dist-info → imio.smartweb.common-1.2.13.dist-info}/LICENSE.GPL +0 -0
- {imio.smartweb.common-1.2.8.dist-info → imio.smartweb.common-1.2.13.dist-info}/LICENSE.rst +0 -0
- {imio.smartweb.common-1.2.8.dist-info → imio.smartweb.common-1.2.13.dist-info}/namespace_packages.txt +0 -0
- {imio.smartweb.common-1.2.8.dist-info → imio.smartweb.common-1.2.13.dist-info}/top_level.txt +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
2
|
|
|
3
3
|
from imio.smartweb.locales import SmartwebMessageFactory as _
|
|
4
|
-
from plone.app.z3cform.widget import
|
|
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=
|
|
24
|
+
directives.widget(topics=AjaxSelectFieldWidget)
|
|
@@ -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
|
|
|
@@ -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,67 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
from imio.smartweb.common.utils import is_staging_or_local
|
|
4
|
+
from plone import api
|
|
5
|
+
from plone.restapi.services import Service
|
|
6
|
+
from zope.interface import implementer
|
|
7
|
+
from zope.interface import Interface
|
|
8
|
+
|
|
9
|
+
import logging
|
|
10
|
+
import requests
|
|
11
|
+
|
|
12
|
+
logger = logging.getLogger("imio.smartweb.common")
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class IOdwbService(Interface):
|
|
16
|
+
|
|
17
|
+
def available():
|
|
18
|
+
""" """
|
|
19
|
+
|
|
20
|
+
def reply():
|
|
21
|
+
""" """
|
|
22
|
+
|
|
23
|
+
def remove():
|
|
24
|
+
""" """
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@implementer(IOdwbService)
|
|
28
|
+
class OdwbService(Service):
|
|
29
|
+
|
|
30
|
+
def available(self):
|
|
31
|
+
staging_or_local = is_staging_or_local()
|
|
32
|
+
if staging_or_local:
|
|
33
|
+
logger.info(
|
|
34
|
+
"Don't send odwb data when we are in staging or local environment"
|
|
35
|
+
)
|
|
36
|
+
return not staging_or_local
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class OdwbBaseEndpointGet(OdwbService):
|
|
40
|
+
|
|
41
|
+
def __init__(self, context, request, odwb_imio_service, odbw_pushkey):
|
|
42
|
+
self.odwb_api_push_url = "https://www.odwb.be/api/push/1.0"
|
|
43
|
+
self.odwb_imio_service = odwb_imio_service
|
|
44
|
+
self.odwb_pushkey = api.portal.get_registry_record(odbw_pushkey)
|
|
45
|
+
|
|
46
|
+
self.context = context
|
|
47
|
+
self.request = request
|
|
48
|
+
self.__datas__ = []
|
|
49
|
+
|
|
50
|
+
def odwb_query(self, url, payload, headers=None):
|
|
51
|
+
if headers is None:
|
|
52
|
+
headers = {"Content-Type": "application/json"}
|
|
53
|
+
try:
|
|
54
|
+
response = requests.post(url, headers=headers, data=payload)
|
|
55
|
+
return response.text
|
|
56
|
+
except requests.exceptions.ConnectionError as e:
|
|
57
|
+
logger.error("ODWB : Connection error: %s", e)
|
|
58
|
+
return "ODWB : Connection error occurred"
|
|
59
|
+
except requests.exceptions.Timeout as e:
|
|
60
|
+
logger.error("ODWB : Request timed out: %s", e)
|
|
61
|
+
return "ODWB : Request timed out"
|
|
62
|
+
except requests.exceptions.HTTPError as e:
|
|
63
|
+
logger.error("ODWB : HTTP error occurred: %s", e)
|
|
64
|
+
return "ODWB : HTTP error occurred"
|
|
65
|
+
except Exception as e:
|
|
66
|
+
logger.error("ODWB : An unexpected error occurred: %s", e)
|
|
67
|
+
return "ODWB : Unexpected error occurred"
|
|
@@ -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
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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
|
-
|
|
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
|
|
107
|
+
results[metadata] = [{"token": v, "title": v} for v in values]
|
|
108
|
+
results[metadata].sort(key=itemgetter("title"))
|
|
97
109
|
|
|
98
110
|
return results
|
imio/smartweb/common/testing.py
CHANGED
|
@@ -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")
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
2
|
|
|
3
|
+
from imio.smartweb.common.rest.odwb import OdwbService
|
|
3
4
|
from imio.smartweb.common.rest.utils import get_restapi_query_lang
|
|
4
5
|
from imio.smartweb.common.testing import IMIO_SMARTWEB_COMMON_ACCEPTANCE_TESTING
|
|
5
6
|
from plone import api
|
|
6
7
|
from plone.app.testing import setRoles
|
|
7
8
|
from plone.app.testing import TEST_USER_ID
|
|
8
9
|
from plone.restapi.testing import RelativeSession
|
|
10
|
+
from unittest.mock import patch
|
|
9
11
|
|
|
10
12
|
import transaction
|
|
11
13
|
import unittest
|
|
@@ -29,6 +31,10 @@ class TestREST(unittest.TestCase):
|
|
|
29
31
|
title="Doc 1",
|
|
30
32
|
)
|
|
31
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"
|
|
32
38
|
api.content.transition(self.doc1, "publish")
|
|
33
39
|
|
|
34
40
|
self.doc2 = api.content.create(
|
|
@@ -98,11 +104,31 @@ class TestREST(unittest.TestCase):
|
|
|
98
104
|
],
|
|
99
105
|
)
|
|
100
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
|
+
|
|
101
126
|
query = {
|
|
102
127
|
"portal_type": "Event",
|
|
103
128
|
"metadata_fields": [
|
|
104
129
|
"iam",
|
|
105
130
|
"topics",
|
|
131
|
+
"container_uid",
|
|
106
132
|
"effective",
|
|
107
133
|
"end",
|
|
108
134
|
"has_leadimage",
|
|
@@ -112,8 +138,20 @@ class TestREST(unittest.TestCase):
|
|
|
112
138
|
}
|
|
113
139
|
response = self.api_session.get("/@search-filters", params=query)
|
|
114
140
|
json = response.json()
|
|
141
|
+
self.assertNotIn("container_uid", json)
|
|
115
142
|
self.assertNotIn("effective", json)
|
|
116
143
|
self.assertNotIn("end", json)
|
|
117
144
|
self.assertNotIn("has_leadimage", json)
|
|
118
145
|
self.assertNotIn("start", json)
|
|
119
146
|
self.assertNotIn("UID", json)
|
|
147
|
+
|
|
148
|
+
@patch("imio.smartweb.common.utils.api.portal.get")
|
|
149
|
+
def test_odwb_service_environnement(self, mock_get):
|
|
150
|
+
mock_portal = mock_get.return_value
|
|
151
|
+
mock_portal.absolute_url.return_value = "http://localhost:8080"
|
|
152
|
+
endpoint = OdwbService()
|
|
153
|
+
self.assertEqual(endpoint.available(), False)
|
|
154
|
+
|
|
155
|
+
mock_portal.absolute_url.return_value = "https://www.production.be"
|
|
156
|
+
endpoint = OdwbService()
|
|
157
|
+
self.assertEqual(endpoint.available(), True)
|
|
@@ -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
|
+
)
|