Commits

Anonymous committed 3ef47fe

grid css + small typos for grid demo

Comments (0)

Files changed (4)

unfinished/grid.py

-from webhelpers.html.builder import HTML, literal
-
-class Grid(object):
-    
-    def default_column_format(self, column_number, i, record, column_name):
-        class_name = 'c%s' % (column_number)
-        return HTML.tag('td', record[column_name], class_=class_name)
-    
-    def numbered_column_format(self, column_number, i, record):
-        class_name = 'c%s' % (column_number)
-        return HTML.tag('td', i, class_=class_name)
-    
-    def default_record_format(self, i, record, class_name, columns):
-        return HTML.tag('tr', columns, class_=class_name)
-
-    def default_record_format(self, i, record, class_name, columns):
-        return HTML.tag('tr', columns, class_=class_name)
-
-    def default_header_record_format(self, headers):
-        return HTML.tag('tr', headers, class_='header')
-
-    def default_header_ordered_column_format(self, column_number, order, column_name, header_label):
-        header_label = HTML(header_label, HTML.tag('span', class_='marker'))
-        if column_name == '_numbered':
-            column_name = 'numbered'
-        class_name = 'c%s ordering %s %s' % (column_number, order, column_name)
-        return HTML.tag('td', header_label, class_=class_name)
-
-    def default_header_column_format(self, column_number, column_name, 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)
-    
-    def generate_header_link(self, column_number, column, label_text):
-        return None
-    
-    def __init__(self, itemlist, *args, **kwargs):
-        self.custom_record_format = None
-        self.labels = {}
-        self.exclude_ordering = ['_numbered']
-        self.itemlist = itemlist
-        columns = kwargs['columns']
-        if '_numbered' in columns:
-            self.labels['_numbered'] = 'no.'
-        self.columns = columns
-        self.format = kwargs.get('format', {})
-        self._start_number = kwargs.get('start_number', 1)
-        
-
-    def make_headers(self):
-        header_columns = []
-            
-        for i, column in enumerate(self.columns):
-            # let's generate header column contents
-            label_text = ''
-            if column in self.labels:
-                label_text = self.labels[column]
-            else:
-                label_text = column.replace('_', ' ').title()
-            # handle non clickable columns
-            if column in self.exclude_ordering:
-                header = self.default_header_column_format(i + 1, column, label_text)
-            # handle clickable columns
-            else:
-                header = self.generate_header_link(i + 1, column, label_text)
-                if header is None:
-                    header = self.default_header_column_format(i + 1, column, label_text)                    
-            header_columns.append(header)               
-        return HTML(*header_columns)
-    
-    def make_columns(self, i, record):
-        columns = []        
-        for col_num, column in enumerate(self.columns):
-            if column in self.format:
-                columns.append(self.format[column](col_num, i, record))
-            else:
-                if column == '_numbered':
-                    columns.append(self.numbered_column_format(col_num, i + self._start_number, record))
-                else:
-                    columns.append(self.default_column_format(col_num, i, record, column)) 
-        return HTML(*columns)
-    
-    def __html__(self):
-        ''' renders the grid '''
-        records = []
-        #first render headers record
-        records.append(self.default_header_record_format(self.make_headers()))
-        for i, record in enumerate(self.itemlist):
-            if i % 2 == 0:
-                class_name = 'even'
-            else:
-                class_name = 'odd'
-            if self.custom_record_format is None:
-                records.append(self.default_record_format(i, record, class_name, self.make_columns(i, record)))
-            else:
-                records.append(self.custom_record_format(i, record, class_name, self.make_columns(i, record)))
-
-        return HTML(*records)
-    
-    def __str__(self):
-        return self.__html__()

unfinished/grid_demo.py

         <p>%(description)s</p>
     </body>
 </html>
-"""
+""")
 # XXX There should be helpers to create a basic HTML file.
 
 #### Demo base class ####
         filename = name + ".html"
         dic = {
             "title": d.name or d.__class__.__name__.lower(),
-            "description" d.description,
+            "description": d.description,
             "grid": d.get_grid(),
             }
         html = HTML_TEMPLATE % dic

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)
-        

webhelpers/public/stylesheets/grid.css

+/******************* tables ****************/
+table.stylized {
+	background-color: #ffffff;
+	border-collapse: separate;
+	border-spacing: 1px;
+	border-bottom: 2px solid #666666;
+	margin: 1px 5px 5px 5px;
+	-moz-border-radius: 5px;
+	-webkit-border-radius: 5px;
+	width: 100%;
+	border-collapse: collapse;
+}
+
+table.stylized caption {
+	color: #ffffff;
+	background-color: #444466;
+	padding: 5px;
+	font-size: 1.3em;
+	font-weight: bold;
+	margin: 5px 0px 0px 0px;
+	-moz-border-radius: 5px;
+	-webkit-border-radius: 5px;
+}
+
+
+
+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{
+	color: #ffcc00;
+	text-decoration: none;
+	font-weight: bold;
+}
+	
+table.stylized thead {
+	background-color: #ffffff;
+}
+
+table.stylized tbody {
+	background-color: #ffffff;
+}
+
+table.stylized tfooter {
+	background-color: #ffffff;
+}
+
+table.stylized th {
+	text-align: center;
+}
+
+table.stylized tr.header {
+	text-align: center;
+}
+
+table.stylized tr.header td, table.stylized th {
+	text-align: center;
+	color: #ffffff;
+}
+
+table.stylized td {
+	padding: 5px 5px 5px 5px;
+	border: 1px solid #dcdcdc;
+}
+
+
+table.stylized tr.odd td {
+	border-top: 1px solid #999 !important;
+	background-color: #ffffff;
+}
+
+table.stylized tr.even td {
+	border-top: 1px solid #999 !important;
+	background-color: #f6f6f6;
+}
+
+table.stylized .no {
+	width: 30px;
+}
+
+table.stylized td.ordering.dsc {
+	background-color: #666666;
+	padding-right: 20px;
+}
+
+table.stylized td.ordering.asc {
+	background-color: #666666;
+	padding-right: 20px;
+}
+
+table.stylized td.ordering.dsc .marker {
+	height: 20px;
+	width: 20px;
+	display: block;
+	float: right;
+	margin: 0px -18px;
+}
+
+table.stylized td.ordering.asc .marker {
+	height: 20px;
+	width: 20px;
+	display: block;
+	float: right;
+	margin: 0px -18px;
+}
+
+table.stylized .header a:link,table.stylized .header a:visited {
+	color: #ffffff;
+	text-decoration: none;
+	font-weight: bold;
+}
+
+table.stylized td.ordering a:link,table.stylized td.ordering a:visited {
+	color: #ffcc00;
+	text-decoration: none;
+	font-weight: bold;
+}