# $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 self.has_tfoot=False 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_dict = locals() result_dict.update(self.__dict__) result = """ """ % result_dict 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_dict = locals() result_dict.update(self.__dict__) result = """ """ % result_dict 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=[] notes = notes + self.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 += "