durusmail: quixote-users: Building a community
Building a community
2003-01-02
2003-01-02
2003-01-02
2003-01-02
2003-01-02
2003-01-04
2003-01-04
Building a community
Tom Jenkins
2003-01-04
Neil Schemenauer wrote:

>     # myapp.department module
>
>     class DepartmentUI:
>         def __init__(self, component):
>             self.department = get_department(component) # careful with input!
>
>         def agency(self, request):
>             return AgencyUI(self.department, component)
>
>     def _q_getname(request, component):
>         return DepartmentUI(component)
>
>     class AgencyUI:
>         def __init__(self, department):
>             self.department = department
>             self.agency = None
>
>         def _q_getname(self, request, component):
>             self.agency = get_agency(self.department, component)
>             return self # or something else
>
>         def showSomeInfo(self, request):
>             ...
>
> That's a little rough but hopefully enough to give you the idea.  The
> key idea is that DepartmentUI passes the department object to AgencyUI.
>

Just a quick note for anyone looking at this code, it won't work as
written.  The problem is for the url:
     /department/1/agency/5
the traversal stops at 'agency' with a TraversalError exception raised.
  In Publisher's get_component method the container is checked for the
existence of _q_exports.  The bound method 'agency' does not have this
and so it fails.

What I did instead was give DepartmentUI a _q_getname method.  i check
for the explicit string 'agency'

class DepartmentUI:
     ....

     def _q_getname(self, request, component):
        if component == 'agency':
            return get_agency(self.department)
        return None


Tom


reply