--- a/src/pyams_skin/container.py Thu Jul 12 18:23:31 2018 +0200
+++ b/src/pyams_skin/container.py Fri Jul 13 08:49:51 2018 +0200
@@ -97,15 +97,16 @@
return {'status': 'success'}
-def switch_element_visibility(request, interface, adapter_name=''):
- """Set container element visibility
+def switch_element_attribute(request, interface, adapter_name='', attribute_name=''):
+ """Sswitch container element attribute
:param request: original browser request; request should contain a parameter called
"object_name" which contains the name of the element which should be switched.
A NotFound exception is raised if argument is not provided or if given argument
doesn't match an existing element.
: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.
+ :param attribute: name of the boolean attribute to be switcher
+ :return: a JSON object containing a boolean "attribute" property defining new element value.
"""
context = request.context
if interface.providedBy(context):
@@ -120,5 +121,18 @@
element = container.get(str(object_name))
if element is None:
raise NotFound()
- element.visible = not element.visible
- return {'visible': element.visible}
+ setattr(element, attribute_name, not getattr(element, attribute_name))
+ return {attribute_name: getattr(element, attribute_name)}
+
+
+def switch_element_visibility(request, interface, adapter_name=''):
+ """Set container element visibility
+
+ :param request: original browser request; request should contain a parameter called
+ "object_name" which contains the name of the element which should be switched.
+ A NotFound exception is raised if argument is not provided or if given argument
+ doesn't match an existing element.
+ :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.
+ """
+ return switch_element_attribute(request, interface, adapter_name, 'visible')