add grid actions support

This commit is contained in:
Lance Edgar 2012-04-15 23:04:03 -05:00
parent ce08699104
commit e961e34407
3 changed files with 29 additions and 30 deletions

View file

@ -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 ``<td>`` 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('<td class="action%s"><a href="#">%s</a></td>' %
# (' ' + 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(
'<td class="action %s"><a href="#">%s</a></td>' %
(cls, text))
return res
# def get_uuid(self):
# """

View file

@ -1,4 +1,5 @@
<%inherit file="/base.mako" />
<%def name="menu()"></%def>
<div class="wrapper">

View file

@ -1,9 +1,5 @@
<div class="grid${' '+class_ if class_ else ''}" ${grid.url_attrs()|n}>
##url="${grid.url_grid}"
## objurl="${grid.url_object}" delurl="${grid.url_object}"
## usedlg="${grid.config['use_dialog']}">
<table>
<thead>
<tr>
@ -13,9 +9,9 @@
% for field in grid.iter_fields():
${grid.th_sortable(field)|n}
% endfor
## % for i in range(len(grid.config['actions'])):
## <th>&nbsp;</th>
## % endfor
% for i in range(len(grid.config['actions'])):
<th>&nbsp;</th>
% endfor
% if grid.deletable:
<th>&nbsp;</th>
% endif
@ -25,7 +21,6 @@
<tbody>
% for i, row in enumerate(grid.rows):
<% grid._set_active(row) %>
## <tr uuid="${grid.model.uuid}" class="${'even' if i % 2 else 'odd'}">
<tr ${grid.row_attrs(i)|n}>
% if checkboxes:
<td class="checkbox">${h.checkbox('check-'+grid.model.uuid, disabled=True)}</td>
@ -33,10 +28,10 @@
% for field in grid.iter_fields():
<td class="${grid.field_name(field)}">${grid.render_field(field, True)|n}</td>
% endfor
## ${grid.get_actions()}
%if grid.deletable:
${grid.get_actions()}
% if grid.deletable:
<td class="delete">&nbsp;</td>
%endif
% endif
</tr>
% endfor
</tbody>