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

Mary Gardiner mary-twisted at puzzling.org
Sun Jan 23 02:12:28 MST 2005


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?

-Mary



More information about the Twisted-web mailing list