Added test in "switch_element_visibility" function
authorThierry Florac <thierry.florac@onf.fr>
Wed, 23 May 2018 15:18:46 +0200
changeset 324 49c7deef8eef
parent 323 391f772a2e6d
child 325 e55bab04b4d6
Added test in "switch_element_visibility" function
src/pyams_skin/container.py
--- a/src/pyams_skin/container.py	Wed May 23 15:18:07 2018 +0200
+++ b/src/pyams_skin/container.py	Wed May 23 15:18:46 2018 +0200
@@ -97,7 +97,7 @@
     return {'status': 'success'}
 
 
-def switch_element_visibility(request, interface):
+def switch_element_visibility(request, interface, adapter_name=''):
     """Set container element visibility
 
     :param request: original browser request; request should contain a parameter called
@@ -107,9 +107,13 @@
     :param interface: container interface to which request's context should be adapted
     :return: a JSON object containing a boolean "visible" property defining new element visibility.
     """
-    container = interface(request.context, None)
-    if container is None:
-        raise NotFound()
+    context = request.context
+    if interface.providedBy(context):
+        container = context
+    else:
+        container = request.registry.queryAdapter(context, interface, name=adapter_name)
+        if container is None:
+            raise NotFound()
     object_name = request.params.get('object_name')
     if not object_name:
         raise NotFound()