Anonymous avatar Anonymous committed 5aa14d7 Merge

Mege ergo's grid updates.

Comments (0)

Files changed (3)

webhelpers/html/grid.py

     def default_column_format(self, column_number, i, record, column_name):
         class_name = "c%s" % (column_number)
         return HTML.tag("td", getattr(record, column_name), class_=class_name)
+
+class ListGrid(Grid):
+    """ A grid class for a sequence of lists.
+    
+    This grid class assumes that the rows are lists rather than dicts, and
+    uses attribute access to retrieve the column values.
+    The columns attribute during init MUST specify list indices as strings 
+    like this: grid = ListGrid(list_data, columns=['1', '3', '2', '0']) 
+    
+    """
+    
+    def default_column_format(self, column_number, i, record, column_name):
+        class_name = "c%s" % (column_number)
+        return HTML.tag("td", record[int(column_name)], class_=class_name)

webhelpers/html/grid_demo.py

 import urllib
 
 from webhelpers.html import *
-from webhelpers.html.grid import Grid
+from webhelpers.html.grid import *
 from webhelpers.html.tags import link_to
 from webhelpers.misc import subclasses_only
 # XXX You may find other helpers in webhelpers.html.tags useful too
                  )
         return g
 
-
 class OrderingDirectionHeaderAwareDemo(_DemoBase):
     name = "OrderDirectionHeaderAwareDemo"
     description = """\
         #enable ordering support
         g.exclude_ordering = []
         return g
+    
+    
+list_data = [
+             [1,'a',3,'c',5],
+             [11,'aa',33,'cc',55],
+             [111,'aaa',333,'ccc',555]
+             ]
+    
+class ListDemo(_DemoBase):
+    name = "List grid demo"
+    description = """\
+This table shows a basic grid generated from lists - it has customized order of columns."""
+
+    def get_grid(self):
+        """
+        basic demo
+        """
+        
+        g = ListGrid(list_data, columns=['1', '3', '2', '0'])
+        return g
+    
 demos = subclasses_only(_DemoBase, globals())
 
 #demos = [BasicDemo, CustomColumnDemo]

webhelpers/pylonslib/grid.py

     
     def __init__(self, request, *args, **kw):
         self.request = request
-        super(GridPylons, self).__init__(*args, **kw)
+        super(PylonsGrid, self).__init__(*args, **kw)
     
     def generate_header_link(self, column_number, column, label_text):
         """ This handles generation of link and then decides to call
         """ 
         from pylons import url
         # this will handle possible URL generation
-        request_copy = self.request.copy().GET
-        if not self.order_column: 
-            self.order_column = request_copy.pop("order_col", None)
-        if not self.order_dir:
-            self.order_dir = request_copy.pop("order_dir", 'asc')
+        request_copy = dict(self.request.copy().GET) 
+        self.order_column = request_copy.pop("order_col", None)
+        self.order_dir = request_copy.pop("order_dir", None)
         
         if column == self.order_column and self.order_dir == "asc":
             new_order_dir = "dsc"
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.