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
Neil Schemenauer
2003-01-06
On Sat, Jan 04, 2003 at 05:36:42PM -0500, Tom Jenkins wrote:
> now when i tried hitting
>    /department/2/agency/4/view
> I would get an exception in Publisher on
[...]
> container =  and
> component = 4

Ah yes, there was a fundamential bug in my original code.  The problem
is the 'agency' must be a namespace, not a function that returns a
namespace.  Here's one way to do it:

    class DepartmentUI:
        def __init__(self, component):
            self.department = get_department(component) # careful with input!
            self.agency = AgencyUI(self.department)

    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):
            ...


To lazily create AgencyUI you can use a property:

    class DepartmentUI(object):
        ...

        def _get_agency_ui(self):
            return AgencyUI(self.department)
        agency = property(_get_agency_ui)

Hopefully I got that right since I didn't test it. :-)

  Neil

reply