src/pyams_skin/container.py
changeset 324 49c7deef8eef
parent 309 820cffe32002
child 373 a2435ed351a9
equal deleted inserted replaced
323:391f772a2e6d 324:49c7deef8eef
    95     # Delete element
    95     # Delete element
    96     del container[name]
    96     del container[name]
    97     return {'status': 'success'}
    97     return {'status': 'success'}
    98 
    98 
    99 
    99 
   100 def switch_element_visibility(request, interface):
   100 def switch_element_visibility(request, interface, adapter_name=''):
   101     """Set container element visibility
   101     """Set container element visibility
   102 
   102 
   103     :param request: original browser request; request should contain a parameter called
   103     :param request: original browser request; request should contain a parameter called
   104         "object_name" which contains the name of the element which should be switched.
   104         "object_name" which contains the name of the element which should be switched.
   105         A NotFound exception is raised if argument is not provided or if given argument
   105         A NotFound exception is raised if argument is not provided or if given argument
   106         doesn't match an existing element.
   106         doesn't match an existing element.
   107     :param interface: container interface to which request's context should be adapted
   107     :param interface: container interface to which request's context should be adapted
   108     :return: a JSON object containing a boolean "visible" property defining new element visibility.
   108     :return: a JSON object containing a boolean "visible" property defining new element visibility.
   109     """
   109     """
   110     container = interface(request.context, None)
   110     context = request.context
   111     if container is None:
   111     if interface.providedBy(context):
   112         raise NotFound()
   112         container = context
       
   113     else:
       
   114         container = request.registry.queryAdapter(context, interface, name=adapter_name)
       
   115         if container is None:
       
   116             raise NotFound()
   113     object_name = request.params.get('object_name')
   117     object_name = request.params.get('object_name')
   114     if not object_name:
   118     if not object_name:
   115         raise NotFound()
   119         raise NotFound()
   116     element = container.get(str(object_name))
   120     element = container.get(str(object_name))
   117     if element is None:
   121     if element is None: