# HG changeset patch # User Thierry Florac # Date 1527081526 -7200 # Node ID 49c7deef8eef3f428885b2bf7f13bfefbd0a24b3 # Parent 391f772a2e6d8d96e2d256c732f224b2843cb46c Added test in "switch_element_visibility" function diff -r 391f772a2e6d -r 49c7deef8eef 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()