From b7cc925e84f421893a99df40b717f9ab7533a11e Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Fri, 21 Dec 2012 09:57:41 +0100 Subject: [PATCH] add a notion of 'active' in Composite, used in rendering Tabs for now --- engine/composite.py | 20 +++++++++++++------- engine/plugin.py | 6 +++--- engine/views.py | 6 +++++- plugins/templates/tabs.html | 2 +- 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/engine/composite.py b/engine/composite.py index 69953f70..31b868fa 100644 --- a/engine/composite.py +++ b/engine/composite.py @@ -2,26 +2,32 @@ from engine.plugin import Plugin class Composite (Plugin): - def __init__ (self, sons=[], *args, **kwds): + def __init__ (self, sons=[], active=None, *args, **kwds): Plugin.__init__ (self, *args, **kwds) self.sons=sons + self.active=active def insert (self, plugin): self.sons.append(plugin) + # xxx currently there is no guarantee that exactly one son will be active def template_env (self, request): # this is designed so as to support a template like # {% for son in sons %} {{ son.rendered }} ... + def is_active (son): + print 'comparing >%s< and >%s<'%(son.name,self.active) + return son.name==self.active ranks=range(len(self.sons)) - return { 'sons': + env = { 'sons': [ { 'rendered': son.render(request), + 'rank': rank, + 'active': is_active(son), + # this should probably come from son._settings.. 'title': son.title, + 'name': son.name, 'uuid': son.uuid, 'classname': son.classname, - 'rank': rank} + } for (son,rank) in zip(self.sons,ranks) ]} + return env - # xxx need a way to select an active son, like e.g. - # Composite (active='some string') - # and we could then try to find that string in either title or uuid or some other place - # in which case the corresponding 'son' entry in template_env above would son.active=True diff --git a/engine/plugin.py b/engine/plugin.py index b69d098f..fd49965d 100644 --- a/engine/plugin.py +++ b/engine/plugin.py @@ -14,7 +14,7 @@ from engine.prelude import Prelude # . [ 'SliceList', 'TabbedView' ] : to debug these classes # . True : to debug all plugin -DEBUG= [ 'SliceList' ] +DEBUG= [ 'Tabs' ] class Plugin: @@ -143,8 +143,8 @@ class Plugin: print "%s.render_content: BEG --------------------"%self.classname print "template=%s"%template print "env.keys=%s"%env.keys() - print "env=%s"%env - print result + #print "env=%s"%env + #print result print "%s.render_content: END --------------------"%self.classname return result diff --git a/engine/views.py b/engine/views.py index 59a2e46a..96dfa66a 100644 --- a/engine/views.py +++ b/engine/views.py @@ -28,11 +28,15 @@ def test_plugin_view (request): foo='the value for foo', with_datatables=True), Tabs (title='Sample Tabs',name='tabs1', + active='raw1', sons = [ Raw (title='a raw plugin',name='raw1', + hidable=False, html= 3*lorem_p), SliceList(title='a slice list',name='slicelist-main', + hidable=False, list=hard_wired_slice_names), - Raw (title='raw title',name='raw2',html=lorem) ]), + Raw (title='raw title',name='raw2', + hidable=False,html=lorem) ]), SimpleList (title='SimpleList with slice names', name='simplelist2', list=hard_wired_slice_names, diff --git a/plugins/templates/tabs.html b/plugins/templates/tabs.html index c9d792a7..fe50e1f5 100644 --- a/plugins/templates/tabs.html +++ b/plugins/templates/tabs.html @@ -6,7 +6,7 @@
{% for son in sons %} -
+
{{ son.rendered }}
{% endfor %} -- 2.43.0