Пример #1
0
    def route( self, request ):
        """:meth:`pluggdapps.web.webinterfaces.IHTTPRouter.route` interface
        method.
        """
        resp = request.response
        c = resp.context
        variants = []
        for name, viewd in self.views.items() :
            path = request.uriparts['path']
            m = viewd['compiled_pattern'].match( path )
            variants.append( (name, viewd, m) ) if m else None

        if variants :
            variant = self.negotiate( request, variants )
            if variant :
                name, viewd, m = variant
                resp.media_type = viewd['media_type']
                resp.charset = viewd['charset']
                resp.language = viewd['language']
                resp.content_coding = viewd['content_coding']
                request.matchdict = m.groupdict()
                request.view = plugincall(
                 viewd['view'], 
                 lambda:self.query_plugin(IHTTPView, viewd['view'], name, viewd)
                )
                # Call IHTTPResource plugin configured for this view callable.
                res = viewd['resource']
                res = plugincall(
                            res, lambda : self.query_plugin(IHTTPResource,res)
                      )
                res( request, c ) if res else None
                # If etag is available, compute and subsequently clear them.
                etag = c.etag.hashout( prefix='resp-' )
                c.setdefault( 'etag', etag ) if etag else None
                c.etag.clear()
            else :
                from pluggdapps.web.views import HTTPNotAcceptable
                request.matchdict = matchdict
                request.view = HTTPNotAcceptable
        else :
            request.matchdict = {}
            request.view = self['defaultview']

        if callable( request.view ) :   # Call the view-callable
            request.view( request, c )
            # If etag is available, compute and subsequently clear them.
            etag=c.etag.hashout(prefix='view-', joinwith=c.etag.pop('etag',''))
            c.setdefault( 'etag', etag ) if etag else None
            c.etag.clear()
Пример #2
0
 def onboot( self ):
     """:meth:`pluggapps.web.webinterfaces.IHTTPRouter.onboot` interface
     method."""
     self['defaultview'] = plugincall(
         self['defaultview'],
         lambda:self.query_plugin(IHTTPView, self['defaultview'], name, None)
     )