49ea0b572fb6ec1a551f59b5439f2b1276fc7db2
[myslice.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.domid,self.active)
19             return son.domid==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                      'title': son.title,
26                      'domid': son.domid,
27                      'classname': son.classname,
28                      }
29                    for (son,rank) in zip(self.sons,ranks) ]}
30         return env
31