Exemple #1
0
class KSSView(SiteView):
    """KSS view

    This allows setting up the content of the response, and then
    generate it out.
    """

    interface.implements(IKSSView)

    def __init__(self, context, request):
        super(KSSView, self).__init__(context, request)
        self._initcommands()

    def _initcommands(self):
        self.commands = KSSCommands()

    # XXX avoid weird acquisition behaviour in Zope 2... this should
    # go away when Five views aren't Acquisition objects anymore.

    def _set_context(self, context):
        self._context = [context]

    def _get_context(self):
        return self._context[0]

    context = property(_get_context, _set_context)

    def render(self):
        """Views can use this to return their command set."""
        notify(BeforeRenderKSSCommandsEvent(self))
        return self.commands.render(self.request)

    def cancelRedirect(self):
        if self.request.response.getStatus() in (302, 303):
            # Try to not redirect if requested
            self.request.response.setStatus(200)

    def getCommands(self):
        return self.commands

    def getCommandSet(self, name):
        commandset = getRegisteredCommandSet(name)
        # return the adapted view
        return commandset.provides(self)
Exemple #2
0
 def _initcommands(self):
     self.commands = KSSCommands()