incubator-bloodhound-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gary <gary.mar...@wandisco.com>
Subject Re: svn commit: r1327544 - in /incubator/bloodhound/trunk/bloodhound_multiproduct/multiproduct: __init__.py common.py ticket/web_ui.py web_ui.py
Date Wed, 18 Apr 2012 15:47:40 GMT
Hi,

Just added a degree of generic handling of the product namespaces so 
that any /products/<product-short-name>/nonproductpath will be able to 
work somewhat transparently without components needing to know about 
products. .It also notes the active product so that any product-aware 
component can respond appropriately.

Cheers,
     Gary


On 04/18/2012 04:28 PM, gjm@apache.org wrote:
> Author: gjm
> Date: Wed Apr 18 15:28:50 2012
> New Revision: 1327544
>
> URL: http://svn.apache.org/viewvc?rev=1327544&view=rev
> Log:
> multiproduct: provide product namespace and some generic handling of product urls #24
>
> Added:
>      incubator/bloodhound/trunk/bloodhound_multiproduct/multiproduct/web_ui.py   (with
props)
> Removed:
>      incubator/bloodhound/trunk/bloodhound_multiproduct/multiproduct/common.py
> Modified:
>      incubator/bloodhound/trunk/bloodhound_multiproduct/multiproduct/__init__.py
>      incubator/bloodhound/trunk/bloodhound_multiproduct/multiproduct/ticket/web_ui.py
>
> Modified: incubator/bloodhound/trunk/bloodhound_multiproduct/multiproduct/__init__.py
> URL: http://svn.apache.org/viewvc/incubator/bloodhound/trunk/bloodhound_multiproduct/multiproduct/__init__.py?rev=1327544&r1=1327543&r2=1327544&view=diff
> ==============================================================================
> --- incubator/bloodhound/trunk/bloodhound_multiproduct/multiproduct/__init__.py (original)
> +++ incubator/bloodhound/trunk/bloodhound_multiproduct/multiproduct/__init__.py Wed Apr
18 15:28:50 2012
> @@ -20,4 +20,4 @@
>   from model import MultiProductEnvironmentProvider
>   from product_admin import ProductAdminPanel
>   import multiproduct.ticket
> -import common
> +from web_ui import ProductModule
>
> Modified: incubator/bloodhound/trunk/bloodhound_multiproduct/multiproduct/ticket/web_ui.py
> URL: http://svn.apache.org/viewvc/incubator/bloodhound/trunk/bloodhound_multiproduct/multiproduct/ticket/web_ui.py?rev=1327544&r1=1327543&r2=1327544&view=diff
> ==============================================================================
> --- incubator/bloodhound/trunk/bloodhound_multiproduct/multiproduct/ticket/web_ui.py
(original)
> +++ incubator/bloodhound/trunk/bloodhound_multiproduct/multiproduct/ticket/web_ui.py
Wed Apr 18 15:28:50 2012
> @@ -31,25 +31,14 @@ from trac.util.datefmt import from_utime
>   from trac.util.translation import _, tag_
>   from genshi.builder import tag
>
> -from multiproduct.common import match_product_path
> -
> -TICKET_RE = re.compile(r'/ticket/(?P<ticket>[0-9]+)$')
>   REPORT_RE = re.compile(r'/report(?:/(?:([0-9]+)|-1))?$')
>
>   class ProductTicketModule(TicketModule):
>       """Product Overrides for the TicketModule"""
>
>       # IRequestHandler methods
> -    def match_request(self, req):
> -        """Override of TicketModule match_request"""
> -        pathinfo = match_product_path(self.env, req)
> -        # is it a newticket request:
> -        if pathinfo == "/newticket":
> -            return True
> -        tmatch = TICKET_RE.match(pathinfo)
> -        if tmatch:
> -            req.args['id'] = tmatch.group('ticket')
> -            return True
> +    #def match_request(self, req):
> +    # override not yet required
>
>       def process_request(self, req):
>           """Override for TicketModule process_request"""
>
> Added: incubator/bloodhound/trunk/bloodhound_multiproduct/multiproduct/web_ui.py
> URL: http://svn.apache.org/viewvc/incubator/bloodhound/trunk/bloodhound_multiproduct/multiproduct/web_ui.py?rev=1327544&view=auto
> ==============================================================================
> --- incubator/bloodhound/trunk/bloodhound_multiproduct/multiproduct/web_ui.py (added)
> +++ incubator/bloodhound/trunk/bloodhound_multiproduct/multiproduct/web_ui.py Wed Apr
18 15:28:50 2012
> @@ -0,0 +1,98 @@
> +
> +#  Licensed to the Apache Software Foundation (ASF) under one
> +#  or more contributor license agreements.  See the NOTICE file
> +#  distributed with this work for additional information
> +#  regarding copyright ownership.  The ASF licenses this file
> +#  to you under the Apache License, Version 2.0 (the
> +#  "License"); you may not use this file except in compliance
> +#  with the License.  You may obtain a copy of the License at
> +#
> +#   http://www.apache.org/licenses/LICENSE-2.0
> +#
> +#  Unless required by applicable law or agreed to in writing,
> +#  software distributed under the License is distributed on an
> +#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
> +#  KIND, either express or implied.  See the License for the
> +#  specific language governing permissions and limitations
> +#  under the License.
> +
> +"""ProductModule
> +
> +Provides request filtering to capture product related paths
> +"""
> +import re
> +
> +from trac.core import Component, implements
> +from trac.resource import ResourceNotFound
> +from trac.util.translation import _
> +from trac.web.api import IRequestFilter, IRequestHandler, Request, HTTPNotFound
> +from trac.web.main import RequestDispatcher
> +
> +from multiproduct.model import Product
> +
> +PRODUCT_RE = re.compile(r'^/products/(?P<pid>[^/]*)(?P<pathinfo>.*)')
> +
> +class ProductModule(Component):
> +    """Base Product behaviour"""
> +
> +    implements(IRequestFilter, IRequestHandler)
> +
> +    # IRequestFilter methods
> +    def pre_process_request(self, req, handler):
> +        """pre process request filter"""
> +        pid = None
> +        match = PRODUCT_RE.match(req.path_info)
> +        if match:
> +            dispatcher = RequestDispatcher(self.env)
> +            pid = match.group('pid')
> +
> +        if pid:
> +            products = Product.select(self.env, where={'prefix': pid})
> +            if pid and len(products) == 1:
> +                req.args['productid'] = pid
> +                req.args['product'] = products[0].name
> +                if handler is self and match.group('pathinfo') not in ('', '/'):
> +                    # select a new handler
> +                    environ = req.environ.copy()
> +                    pathinfo = environ['PATH_INFO'].split('/')
> +                    pathinfo = '/'.join(pathinfo[:1] + pathinfo[3:])
> +                    environ['PATH_INFO'] = pathinfo
> +                    newreq = Request(environ, lambda *args, **kwds: None)
> +
> +                    new_handler = None
> +                    for hndlr in dispatcher.handlers:
> +                        if hndlr is not self and hndlr.match_request(newreq):
> +                            new_handler = hndlr
> +                            break
> +                    if new_handler is None:
> +                        if req.path_info.endswith('/'):
> +                            target = req.path_info.rstrip('/').encode('utf-8')
> +                            if req.query_string:
> +                                target += '?' + req.query_string
> +                            req.redirect(req.href + target, permanent=True)
> +                        raise HTTPNotFound('No handler matched request to %s',
> +                                           req.path_info)
> +                    handler = new_handler
> +            else:
> +                raise ResourceNotFound(_("Product %(id)s does not exist.",
> +                                         id=pid), _("Invalid product id"))
> +
> +        return handler
> +
> +    def post_process_request(self, req, template, data, content_type):
> +        """post process request filter"""
> +        return (template, data, content_type)
> +
> +    # IRequestHandler methods
> +    def match_request(self, req):
> +        """match request handler"""
> +        if req.path_info.startswith('/products'):
> +            return True
> +        return False
> +
> +    def process_request(self, req):
> +        """process request handler"""
> +        if req.args.get('productid', None):
> +            return 'product.html', None, None
> +        return 'product_list.html', None, None
> +
> \ No newline at end of file
>
> Propchange: incubator/bloodhound/trunk/bloodhound_multiproduct/multiproduct/web_ui.py
> ------------------------------------------------------------------------------
>      svn:eol-style = native
>
>


Mime
View raw message