[Twisted-web] Re: Page object design: wrapping a dictionary containing data

Michael Hudson mwh at python.net
Sun Jan 23 03:24:02 MST 2005


Mary Gardiner <mary-twisted at puzzling.org> writes:

> I've got a Page object that derives all its data from a dictionary, eg:
>
> {
>     'project_name': 'project',
>     'project_description': 'hello',
>     # ... you get the idea
> }
>
> What's a good way for the Page object to wrap that dictionary that
> doesn't involve doing this:
>
>     def data_name(self, ctx, data):
>         return self.d['project_name']
>
>     def data_description(self, ctx, data):
>         return self.d['project_description']
>
>     # and so on for every key in the dictionary
>
> I vaguely recall that the equivalent of this used to be possible in
> Woven:
>
>     def data_project(self, ctx, data):
>         return self.d
>
> and then that the data items were accessible by (say)
> stan.directive("project/project_name"). This doesn't look like its
> supported in Nevow. Is this correct? What alternative designs are there
> for something like this?

I think something like this:

    def data_dict(self, thing):
        return self.d[thing]

then nevow:data="dict project_name" shoud work.  I think.

Cheers,
mwh

-- 
39. Re graphics:  A picture is worth 10K words - but only those
    to describe the picture.  Hardly any sets of 10K words can be
    adequately described with pictures.
  -- Alan Perlis, http://www.cs.yale.edu/homes/perlis-alan/quotes.html




More information about the Twisted-web mailing list