On Thu, 07 Sep 2006 14:33:56 +0300, Nuutti Kotivuori <[EMAIL PROTECTED]> wrote:
Nuutti Kotivuori wrote:
,----[ datapage.py ]
| class DataPage(TestPage):
|     datapageFactory = loaders.xmlfile('datapage.xhtml')
|
|     def macro_test(self, ctx):
|         return 'Test successful.'
|
|     def macro_snippet_one(self, ctx):
|         return Snippets().one(ctx)
|
|     def macro_snippet_two(self, ctx):
|         return Snippets().two(ctx, 'foo', 'bar')
|
|     def macro_snippet_three(self, ctx):
|         return Snippets().three(ctx)
|
| class Snippets(rend.Fragment):
|     docFactory = loaders.xmlfile('snippets.xhtml')
|
|     def one(self, ctx):
|         context = self.rend(ctx, None)
|         context.tag = inevow.IQ(context.tag).onePattern('one')
|         return context
|
|     def two(self, ctx, arg1, arg2):
|         context = self.rend(ctx, None)
|         context.tag = inevow.IQ(context.tag).onePattern('two')
|         context.tag = context.tag.fillSlots('arg1', arg1)
|                                  .fillSlots('arg2', arg2)
|         return context
|
|     def three(self, ctx):
|         context = self.rend(ctx, None)
|         context.tag = inevow.IQ(context.tag).onePattern('three')
|         return context
|
|     def render_three_special(self, ctx, data):
|         import datetime
|         return 'special render with time %s' % datetime.datetime.now()
`----

Now, this method seems to work, but I'm not sure if I'm too happy with
it yet.

I have to say that this way of organizing code doesn't strike me as too 
effective. Also you seem to be misusing the Fragment object IMHO. It's pretty 
useless to call self.rend and then substituting the tag attribute (which was 
created by the rend object, just don't call rend at all and do something else).

Anyway the real problem with this organization is encapsulation of the relevant 
methods, in my opinion it might become very hard to handle these very complex 
templates togheter with their methods. Unfortunately since I've never needed 
something like this I can't even come up with a valuable solution, sorry.

_______________________________________________
Twisted-web mailing list
[email protected]
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web

Reply via email to