Esempio n. 1
0
    def __init__(self, render='', action=None, component_to_update=None, with_request=False, permissions=None, subject=None, args=(), **kw):
        """Initialisation

        In:
          - ``render`` -- can be:

            - a string -- name of the view that will be rendered on the current
              component
            - a function -- this function will be called and the result sent
              back to the client

          - ``action`` -- action to call
          - ``args``, ``kw`` -- ``action`` parameters

          - ``component_to_update`` -- can be:

            - ``None`` -- the current view will be updated
            - a string -- the DOM id of the HTML to update
            - a tag -- this tag will be updated

          - ``with_request`` -- will the request and response objects be passed to the action?

          - ``permissions`` -- permissions needed to execute the action
          - ``subject`` -- subject to test the permissions on
        """
        self.render = render
        self.with_request = with_request
        self.component_to_update = component_to_update

        # Wrap the ``action`` into a wrapper that will check the user permissions
        action = security.wrapper(action or self.no_action, permissions, subject)
        self.action = partial.Partial(action, *args, **kw)
Esempio n. 2
0
    def _action(self, action, priority, args, with_request, permissions, subject, **kw):
        """Register an action

        In:
          - ``action`` -- action
          - ``priority`` - ``action`` priority
          - ``args``, ``kw`` -- ``action`` parameters
          - ``with_request`` -- will the request and response objects be passed to the action?
          - ``permissions`` -- permissions needed to execute the action
          - ``subject`` -- subject to test the permissions on

        Return:
          - ``self``
        """
        action = security.wrapper(action, permissions, subject or self.renderer.component())
        action = partial.Partial(action, *args, **kw)

        # Generate a hidden field with the action attached
        self.append(self.renderer.div(self.renderer.input(type='hidden', name=self.renderer.register_callback(priority, action, with_request))))
        return self
Esempio n. 3
0
    def action(self, action, args, with_request=False, permissions=None, subject=None, **kw):
        """Register an action

        In:
          - ``action`` -- action
          - ``args``, ``kw`` -- ``action`` parameters
          - ``with_request`` -- will the request and response objects be passed to the action?
          - ``permissions`` -- permissions needed to execute the action
          - ``subject`` -- subject to test the permissions on

        Return:
          - ``self``
        """
        if isinstance(action, ajax.Update):
            self._async_action(self.renderer, action, with_request)
        else:
            # Wrap the ``action`` into a wrapper that will check the user permissions
            action = security.wrapper(action, permissions, subject or self.renderer.component())
            action = partial.Partial(action, *args, **kw)

            # Double dispatch with the renderer
            self.renderer.action(self, action, with_request)

        return self