Commits

Anonymous committed ac3f89c

Grid updates by Ergo, mainly styling and CSS classes.

Comments (0)

Files changed (5)

 
 * webhelpers.html.grid / webhelpers.pylonslib.grid:
 
-  - Updates by Ergo, including SQLAlchemy grid classes.
+  - Updates by Ergo, including SQLAlchemy grid classes, and styling.
 
 * webhelpers.misc:
 

webhelpers/html/grid.py

     """
     def __init__(self, itemlist, columns, column_labels=None,
                   column_formats=None, start_number=1,
-                 order_column=None, order_direction='asc'):
+                 order_column=None, order_direction=None):
         self.labels = column_labels or {}
         self.exclude_ordering = columns
         self.itemlist = itemlist
         columns = []        
         for col_num, column in enumerate(self.columns):
             if column in self.column_formats:
-                r = self.column_formats[column](col_num,
+                r = self.column_formats[column](col_num + 1,
                                                 self. calc_row_no(i, column),
                                                 record)
             else:
-                r = self.default_column_format(col_num,
+                r = self.default_column_format(col_num + 1,
                                                self.calc_row_no(i, column),
                                                record, column)
             columns.append(r)
         for i, record in enumerate(self.itemlist):
             columns = self.make_columns(i, record)
             if hasattr(self, 'custom_record_format'):
-                r = self.custom_record_format(i, record, columns)
+                r = self.custom_record_format(i + 1, record, columns)
             else:
-                r = self.default_record_format(i, record, columns)
+                r = self.default_record_format(i + 1, record, columns)
             records.append(r)
         return HTML(*records)
     
 
     def default_record_format(self, i, record, columns):
         if i % 2 == 0:
-            class_name = "even"
+            class_name = "even r%s" % i
         else:
-            class_name = "odd"
+            class_name = "odd r%s" % i
         return HTML.tag("tr", columns, class_=class_name)
 
     def default_header_record_format(self, headers):
         header_label):
         if column_name == "_numbered":
             column_name = "numbered"
-        class_name = "c%s %s" % (column_number, column_name)
-        return HTML.tag("td", header_label, class_=class_name)
+        if column_name in self.exclude_ordering:
+            class_name = "c%s %s" % (column_number, column_name)
+            return HTML.tag("td", header_label, class_=class_name)
+        else:
+            header_label = HTML(header_label, HTML.tag("span", class_="marker"))
+            class_name = "c%s ordering %s" % (column_number, column_name)
+            return HTML.tag("td", header_label, class_=class_name)
 
 
 class GridSqlalchemy(Grid):
     """ This grid will work well with sqlalchemy row instances """
     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)
+        return HTML.tag("td", getattr(record, column_name), class_=class_name)

webhelpers/html/grid_demo.py

 
 
 
-table.stylized caption a:link,table.stylized caption a:visited{
+table.stylized caption a:link,table.stylized caption a:visited {
     color: #ffffff;
     text-decoration: none;
     font-weight: bold;
 }
 
-table.stylized caption a:link,table.stylized caption a:hover{
+table.stylized caption a:link,table.stylized caption a:hover {
     color: #ffcc00;
     text-decoration: none;
     font-weight: bold;
     width: 30px;
 }
 
-table.stylized td.ordering.dsc {
-    background-color: #666666;
-    padding-right: 20px;
-}
-
-table.stylized td.ordering.asc {
-    background-color: #666666;
+table.stylized td.ordering{
+    background-color: #666666 !important;
     padding-right: 20px;
 }
 
     display: block;
     float: right;
     margin: 0px -18px;
+/* background-image for neutral marker here */
+}
+
+table.stylized td.ordering.dsc .marker {
+/* background-image for dsc marker here */
 }
 
 table.stylized td.ordering.asc .marker {
-    height: 20px;
-    width: 20px;
-    display: block;
-    float: right;
-    margin: 0px -18px;
+/* background-image for asc marker here */
 }
 
 table.stylized .header a:link,table.stylized .header a:visited {

webhelpers/public/stylesheets/grid.css

 	width: 30px;
 }
 
-table.stylized td.ordering.dsc {
-	background-color: #666666;
-	padding-right: 20px;
-}
-
-table.stylized td.ordering.asc {
-	background-color: #666666;
+table.stylized td.ordering{
+	background-color: #666666 !important;
 	padding-right: 20px;
 }
 
 	display: block;
 	float: right;
 	margin: 0px -18px;
+/* background-image for neutral marker here */
+}
+
+table.stylized td.ordering.dsc .marker {
+/* background-image for dsc marker here */
 }
 
 table.stylized td.ordering.asc .marker {
-	height: 20px;
-	width: 20px;
-	display: block;
-	float: right;
-	margin: 0px -18px;
+/* background-image for asc marker here */
 }
 
 table.stylized .header a:link,table.stylized .header a:visited {

webhelpers/pylonslib/grid.py

         from pylons import url
         # this will handle possible URL generation
         request_copy = self.request.copy().GET
-        self.order_column = request_copy.pop("order_col", None)
-        self.order_dir = request_copy.pop("order_dir", None)
+        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')
+        
         if column == self.order_column and self.order_dir == "asc":
             new_order_dir = "dsc"
         else:
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.