Source

WebHelpers / unfinished / grid_pylons.py

from pylons import request, url
from webhelpers.html.builder import HTML, literal
import grid

class NoRequestException(Exception):
    pass

class GridPylons(grid.Grid):
    
    def generate_header_link(self, column_number, column, label_text):
        # this will handle possible url generation
        if not hasattr(self, 'request'):
            raise NoRequestException('Could not find self.request for this grid')
        request_copy = self.request.copy().GET
        if 'order_by' in request_copy:
            self.order_column = request_copy.pop('order_by')
        else:
            self.order_column = None
            
        if self.order_column and column == self.order_column[0:-4] and self.order_column[-3:] == 'asc':
            new_ordering = column + '_dsc'
        else:
            new_ordering = column + '_asc'
        url_href = url(order_by=new_ordering, **request_copy)        
        label_text = HTML.tag("a", href=url_href, c=label_text)
        #lets test if the column we try to order on is this column
        if self.order_column and column == self.order_column[0:-4] and self.order_column[-3:] == 'asc':
            return self.default_header_ordered_column_format(i, 'asc', column, label_text)
        elif self.order_column and column == self.order_column[0:-4] and self.order_column[-3:] == 'dsc':
            return self.default_header_ordered_column_format(i, 'dsc', column, label_text)
        else:
            return self.default_header_column_format(i, column, label_text)
        
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.