From 84543219273c475538e491650df572d057d04c77 Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Thu, 16 Apr 2009 15:08:28 +0000 Subject: [PATCH] initial --- plekit/python/table.py | 176 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 176 insertions(+) create mode 100644 plekit/python/table.py diff --git a/plekit/python/table.py b/plekit/python/table.py new file mode 100644 index 0000000..3e1f9bb --- /dev/null +++ b/plekit/python/table.py @@ -0,0 +1,176 @@ +# $Id$ + +class plekit_table: + + def __init__ (self, table_id, headers, column_sort, + caption=None, + search_area=True, pagesize_area=True, notes_area=True, + search_width=40, pagesize=25, pagesize_def=999, + max_pages=10, + notes=None): + self.table_id=table_id + self.headers=headers + self.column_sort =column_sort + self.caption=caption + self.search_area=search_area + self.pagesize_area=pagesize_area + self.notes_area=notes_area + self.search_width =search_width + self.pagesize =pagesize + self.pagesize_def=pagesize_def + self.max_pages=max_pages + self.notes=notes + + def columns (self): + return len(self.headers) + + def start (self): + paginator = self.table_id + "_paginator" + classname = "paginationcallback-%s" % paginator + classname += " max-pages-%d" % self.max_pages + classname += " paginate-%d" % self.pagesize + # instantiate paginator callback + table_id = self.table_id + print """ + +
+ + +""" % locals() + + if self.pagesize_area: + print self.pagesize_area_html () + if self.search_area: + print self.search_area_html () + + if (self.caption): + print "" % self.caption + print "" + for (label,type) in self.headers.iteritems(): + if type == "none": + classpart="" + elif type == "string" or type == "int" or type == "float": + classpart="sortable" + elif type.find ("date-") == 0: + classpart="sortable-" + type + else: + classpart="sortable-sort" + type + print ''%locals() + + print """\n""" + + ########## + ## unlike the php version there is no support for last-minute options, pass them all to the constructor + def end (self): + print self.bottom_html() + if (self.notes_area): + print self.notes_area_html() + + ########## + def pagesize_area_html (self): + width=len(self.headers) + pagesize_text_id = self.table_id + "_pagesize" + result = """ + +""" % locals() + return result + + ########## + def search_area_html (self): + width = len(self.headers) + search_text_id = self.table_id + "_search" + search_reset_id = self.table_id + "_search_reset" + search_and_id = self.table_id + "_search_and" + result = """ + +""" % locals() + return result + + ########## + ## start a section + def tfoot_start (self): print self.tfoot_start_html() + def tfoot_start_html (self): + self.has_tfoot=true + return "" + + ########## + def bottom_html (self): + result="" + if self.has_tfoot: + result += "" + else: + result += "" + result += "
%s
%(label)s
+
+ + + reset visible size +
+
\n" + return result + + ########## + default_notes = [ + "Enter & or | in the search area to switch between AND and OR search modes", + "Hold down the shift key to select multiple columns to sort" ] + + def notes_area_html (self): + if (self.notes): + notes=self.notes + else: + notes=array() + notes = notes + default_notes + result = "" + result += "

Notes\n" + for note in notes: + result += "
%s\n" % note + result += "

" + return result + + ########## + def row_start (self, id=None, classpart=None): + print "\n" + + def row_end (self): + print "\n" + + ########## + ## supported options: + ## (*) only-if : if set and false, then print 'n/a' instead of (presumably void) $text + ## (*) classpart + ## (*) columns + ## (*) hfill + ## (*) align + def cell (self, text,only_if=True, classpart=None, columns=None, hfill=None, align=None): + print self.cell_html (text, only_if, classpart, columns, hfill, align) + def cell_html (self, text, only_if=True, classpart=None, columns=None, hfill=None, align=None): + if not only_if: + text="n/a" + html="" + html += "