Added interface to SimpleTable for setting column widths

svn: r20041
This commit is contained in:
Doug Blank 2012-07-21 18:00:37 +00:00
parent 685641ec27
commit daaf25867d
2 changed files with 8 additions and 3 deletions

View File

@ -188,10 +188,13 @@ class SimpleTable(object):
else:
self._rows.sort(lambda a, b: cmp(a[idx],b[idx]))
def write(self, document):
def write(self, document, column_widths=None):
doc = document.doc
columns = len(self._columns)
doc.start_table('simple', 'Table')
if column_widths:
doc._tbl.set_column_widths(column_widths)
else:
doc._tbl.set_column_widths([100/columns] * columns)
doc._tbl.set_columns(columns)
if self.title:

View File

@ -205,6 +205,7 @@ class Table(object):
self.db = DbDjango()
self.access = SimpleAccess(self.db)
self.table = SimpleTable(self.access)
self.column_widths = None
class Doc(object):
def __init__(self, doc):
self.doc = doc
@ -249,7 +250,7 @@ class Table(object):
def get_html(self):
# The HTML writer escapes data:
self.table.write(self.doc) # forces to htmllist
self.table.write(self.doc, self.column_widths) # forces to htmllist
# FIXME: do once, or once per table?
self.doc.doc.build_style_declaration(self.id) # can pass id, for whole
# FIXME: don't want to repeat this, unless diff for each table:
@ -837,6 +838,7 @@ def children_table(obj, user, act, url=None, *args):
_("Maternal"),
_("Birth Date"),
)
table.column_widths = [3] + [98/6] * 6
family = obj
obj_type = ContentType.objects.get_for_model(family)