add grid actions support
This commit is contained in:
		
							parent
							
								
									ce08699104
								
							
						
					
					
						commit
						e961e34407
					
				
					 3 changed files with 29 additions and 30 deletions
				
			
		| 
						 | 
				
			
			@ -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):
 | 
			
		||||
    #     """
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,4 +1,5 @@
 | 
			
		|||
<%inherit file="/base.mako" />
 | 
			
		||||
<%def name="menu()"></%def>
 | 
			
		||||
 | 
			
		||||
<div class="wrapper">
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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> </th>
 | 
			
		||||
##	% endfor
 | 
			
		||||
	% for i in range(len(grid.config['actions'])):
 | 
			
		||||
	    <th> </th>
 | 
			
		||||
	% endfor
 | 
			
		||||
	% if grid.deletable:
 | 
			
		||||
	    <th> </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"> </td>
 | 
			
		||||
	    %endif
 | 
			
		||||
	    % endif
 | 
			
		||||
	  </tr>
 | 
			
		||||
      % endfor
 | 
			
		||||
    </tbody>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue