add a notion of 'active' in Composite, used in rendering Tabs for now
[unfold.git] / engine / composite.py
1 from engine.plugin import Plugin
2
3 class Composite (Plugin):
4
5     def __init__ (self, sons=[], active=None, *args, **kwds):
6         Plugin.__init__ (self, *args, **kwds)
7         self.sons=sons
8         self.active=active
9         
10     def insert (self, plugin):
11         self.sons.append(plugin)
12
13     # xxx currently there is no guarantee that exactly one son will be active
14     def template_env (self, request):
15         # this is designed so as to support a template like
16         # {% for son in sons %} {{ son.rendered }} ...
17         def is_active (son):
18             print 'comparing >%s< and >%s<'%(son.name,self.active)
19             return son.name==self.active
20         ranks=range(len(self.sons))
21         env = { 'sons':
22                  [ { 'rendered': son.render(request),
23                      'rank': rank,
24                      'active': is_active(son),
25                      # this should probably come from son._settings..
26                      'title': son.title,
27                      'name': son.name,
28                      'uuid': son.uuid,
29                      'classname': son.classname,
30                      }
31                    for (son,rank) in zip(self.sons,ranks) ]}
32         return env
33