Esempio n. 1
0
    def __getitem__(self, name):
        if name == "+":
            # To-Do: Ideally this should be POST-only to protect
            # against CSRF. It's not critical.
            try:
                layout = self.request.TraversalRequestNameStack.pop()
            except IndexError:
                raise BadRequest("Missing layout.")

            def adding():
                """Add panel, then redirect to referer."""

                self.addPanel(layout)

                referer = (self.request.get('HTTP_REFERER')
                           or self.context.absolute_url())

                return self.request.response.redirect(referer)

            return ExplicitAcquisitionWrapper(adding, self)

        for panel in self.getAssignments():
            if panel.__name__ == name:
                return panel.__of__(self)

        raise KeyError(name)
 def getResource(self, id):
     """Get resource object by id.
     
     If any property of the resource is changed, then cookResources of the
     registry must be called."""
     resources = self.getResourcesDict()
     resource = resources.get(id, None)
     if resource is not None:
         return ExplicitAcquisitionWrapper(resource, self)
     return None
Esempio n. 3
0
def getNestedField(context, field_name):
    """ 
    """
    schema = context.Schema().copy()
    # top-level field:
    simple_field_names = field_name.split(COMPOUND_FIELD_SEPERATOR)
    toplevel_field_name = simple_field_names[0]
    toplevel_field = schema.get(toplevel_field_name)

    prefix = toplevel_field_name
    field = toplevel_field
    for f_name in simple_field_names[1:]:
        f_schema = field.Schema()
        full_name = prefix + COMPOUND_FIELD_SEPERATOR + f_name
        field = f_schema.get(full_name)
        prefix = full_name
    return ExplicitAcquisitionWrapper(field, context)
Esempio n. 4
0
    def getWrappedField(self, key):
        """Gets a field by id which is explicitly wrapped.

        XXX Maybe we should subclass field from Acquisition.Explicit?
        """
        return ExplicitAcquisitionWrapper(self.getField(key), self)