From d09a7cda398c7ed6ce7cb11155413f66fe82f149 Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Thu, 20 Dec 2012 09:21:47 +0100 Subject: [PATCH] fix the tabs widget --- engine/composite.py | 13 +++++++++++++ plugins/tabs.py | 10 ---------- plugins/templates/tabs.html | 8 ++++---- plugins/verticallayout.py | 12 ------------ 4 files changed, 17 insertions(+), 26 deletions(-) diff --git a/engine/composite.py b/engine/composite.py index 71f358da..cd653f8d 100644 --- a/engine/composite.py +++ b/engine/composite.py @@ -9,3 +9,16 @@ class Composite (Plugin): def insert (self, plugin): self.sons.append(plugin) + def render_env (self, request): + # this is designed so as to support a template like + # {% for son in sons %} {{ son.rendered }} ... + return { 'sons': + [ { 'rendered': son.render(request), + 'title': son.title(), + 'uuid': son.uuid} + for son in self.sons ]} + + # 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 render_env above would son.active=True diff --git a/plugins/tabs.py b/plugins/tabs.py index 46e404bc..4008e4fa 100644 --- a/plugins/tabs.py +++ b/plugins/tabs.py @@ -12,14 +12,4 @@ class Tabs (Composite): def template (self): return "tabs.html" - def render_env (self, request): - env = {} - sons_rendered = [ son.render(request) for son in self.sons ] - sons_titles = [ son.title() for son in self.sons ] - ids = range (len(self.sons)) - # for now we don't have a title to pass - sons = [ { 'id':id, 'rendered':rendered, 'title':title } - for id,rendered,title in zip (ids, sons_rendered, sons_titles) ] - env['sons']=sons - return env diff --git a/plugins/templates/tabs.html b/plugins/templates/tabs.html index e8de9eb6..c9d792a7 100644 --- a/plugins/templates/tabs.html +++ b/plugins/templates/tabs.html @@ -1,13 +1,13 @@ {# could try to set class='active' on the one we want to highlight #} +
{% for son in sons %}
{{ son.rendered }} -
+
{% endfor %} - + diff --git a/plugins/verticallayout.py b/plugins/verticallayout.py index eeb134d3..6f976011 100644 --- a/plugins/verticallayout.py +++ b/plugins/verticallayout.py @@ -7,15 +7,3 @@ class VerticalLayout (Composite) : def title (self) : return "VLayout title" def template (self): return "verticallayout.html" - - def render_env (self, request): - env = {} - sons_rendered = [ son.render(request) for son in self.sons ] - sons_titles = [ son.title() for son in self.sons ] - ids = range (len(self.sons)) - # for now we don't have a title to pass - sons = [ { 'id':id, 'rendered':rendered, 'title':title } - for id,rendered,title in zip (ids, sons_rendered, sons_titles) ] - env['sons']=sons - return env - -- 2.43.0