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

Donovan Preston dp at ulaluma.com
Mon Jan 24 08:22:00 MST 2005

On Jan 23, 2005, at 2:24 AM, Michael Hudson wrote:

> 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?

Model path notation (/ and ..) are not yet supported by Nevow. But you 
don't need model path notation to do what you want. If all you want to 
do is pass a dict to the Page and have template directives locate data 
in that dict, you don't have to do anything at all:

	dict(one=1, two=2),
		"""<html xmlns:n="http://nevow.com/ns/nevow/0.1">
	<div n:render="string" n:data="one" />
	<span n:render="string" n:data="two" />


Is it really that hard to figure out that things like this are 
possible? :-(


More information about the Twisted-web mailing list