From e961e344078a9c86e7b5ab576ddc5f918d25bac2 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Sun, 15 Apr 2012 23:04:03 -0500 Subject: [PATCH] add grid actions support --- edbob/pyramid/forms/formalchemy.py | 41 ++++++++++--------- edbob/pyramid/templates/edbob/index.mako | 1 + .../templates/forms/grid_readonly.mako | 17 +++----- 3 files changed, 29 insertions(+), 30 deletions(-) diff --git a/edbob/pyramid/forms/formalchemy.py b/edbob/pyramid/forms/formalchemy.py index d81c070..41f332c 100644 --- a/edbob/pyramid/forms/formalchemy.py +++ b/edbob/pyramid/forms/formalchemy.py @@ -218,27 +218,30 @@ class AlchemyGrid(formalchemy.Grid): # qs += '&%s=%s' % (urllib.quote_plus(k), urllib.quote_plus(v)) # return qs - # def get_actions(self): + def get_actions(self): + """ + Returns an HTML snippet containing ```` elements for each "action" + defined in the grid. + """ - # def get_class(text): - # c = text.lower() - # c = c.replace(' ', '-') - # return c + def get_class(text): + return text.lower().replace(' ', '-') - # res = '' - # for action in self.config['actions']: - # if isinstance(action, basestring): - # text = action - # class_ = get_class(text) - # else: - # text = action[0] - # if len(action) > 1: - # class_ = action[1] - # else: - # class_ = get_class(text) - # res += literal('%s' % - # (' ' + class_ if class_ else '', text)) - # return res + res = '' + for action in self.config['actions']: + if isinstance(action, basestring): + text = action + cls = get_class(text) + else: + text = action[0] + if len(action) == 2: + cls = action[1] + else: + cls = get_class(text) + res += literal( + '%s' % + (cls, text)) + return res # def get_uuid(self): # """ diff --git a/edbob/pyramid/templates/edbob/index.mako b/edbob/pyramid/templates/edbob/index.mako index 3871aae..a640fa5 100644 --- a/edbob/pyramid/templates/edbob/index.mako +++ b/edbob/pyramid/templates/edbob/index.mako @@ -1,4 +1,5 @@ <%inherit file="/base.mako" /> +<%def name="menu()">
diff --git a/edbob/pyramid/templates/forms/grid_readonly.mako b/edbob/pyramid/templates/forms/grid_readonly.mako index d05feae..275c5a8 100644 --- a/edbob/pyramid/templates/forms/grid_readonly.mako +++ b/edbob/pyramid/templates/forms/grid_readonly.mako @@ -1,9 +1,5 @@
-##url="${grid.url_grid}" -## objurl="${grid.url_object}" delurl="${grid.url_object}" -## usedlg="${grid.config['use_dialog']}"> - @@ -13,9 +9,9 @@ % for field in grid.iter_fields(): ${grid.th_sortable(field)|n} % endfor -## % for i in range(len(grid.config['actions'])): -## -## % endfor + % for i in range(len(grid.config['actions'])): + + % endfor % if grid.deletable: % endif @@ -25,7 +21,6 @@ % for i, row in enumerate(grid.rows): <% grid._set_active(row) %> -## % if checkboxes: @@ -33,10 +28,10 @@ % for field in grid.iter_fields(): % endfor -## ${grid.get_actions()} - %if grid.deletable: + ${grid.get_actions()} + % if grid.deletable: - %endif + % endif % endfor
   
${h.checkbox('check-'+grid.model.uuid, disabled=True)}${grid.render_field(field, True)|n}