Generate style for each table (too much style is currently included); set border styles in cells

svn: r19882
This commit is contained in:
Doug Blank 2012-06-19 15:42:32 +00:00
parent 8f012c19b5
commit 846a46ee7f

View File

@ -194,13 +194,14 @@ def nbsp(string):
class Table(object):
"""
>>> table = Table()
>>> table = Table("css_id")
>>> table.columns("Col1", "Col2", "Col3")
>>> table.row("1", "2", "3")
>>> table.row("4", "5", "6")
>>> table.get_html()
"""
def __init__(self):
def __init__(self, id):
self.id = id # css id
self.db = DbDjango()
self.access = SimpleAccess(self.db)
self.table = SimpleTable(self.access)
@ -209,10 +210,27 @@ class Table(object):
self.doc = doc
self.doc.set_link_attrs({"class": "browsecell"})
# None is paperstyle, which is ignored:
self.doc = Doc(HtmlDoc.HtmlDoc(make_basic_stylesheet(Table={"set_width":95}), None))
self.doc = Doc(HtmlDoc.HtmlDoc(
make_basic_stylesheet(
Table={"set_width":95},
TableHeaderCell={"set_bottom_border": True,
"set_right_border": True,
"set_padding": .1,
},
TableDataCell={"set_bottom_border": True,
"set_right_border": True,
"set_padding": .1,
},
),
None))
self.doc.doc._backend = HtmlBackend()
self.doc.doc.use_table_headers = True
# You can set elements id, class, etc:
self.doc.doc.htmllist += [Html('div', class_="content", id="Gallery", style="overflow: auto; height:150px; background-color: #f4f0ec;")]
self.doc.doc.htmllist += [
Html('div',
class_="content",
id=self.id,
style="overflow: auto; height:150px; background-color: #f4f0ec;")]
def columns(self, *args):
self.table.columns(*args)
@ -232,8 +250,12 @@ class Table(object):
def get_html(self):
# The HTML writer escapes data:
self.table.write(self.doc) # 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:
retval = "<style>%s</style>" % self.doc.doc.style_declaration
# We have a couple of HTML bits that we want to unescape:
return str(self.doc.doc.htmllist[0]).replace("&amp;nbsp;", "&nbsp;")
return retval + str(self.doc.doc.htmllist[0]).replace("&amp;nbsp;", "&nbsp;")
def build_args(**kwargs):
retval = ""
@ -273,7 +295,7 @@ def make_button(text, url, *args):
def event_table(obj, user, action, url, args):
retval = ""
table = Table()
table = Table("event_table")
table.columns(
_("Description"),
_("Type"),
@ -305,7 +327,7 @@ def event_table(obj, user, action, url, args):
def name_table(obj, user, action, url=None, *args):
retval = ""
table = Table()
table = Table("name_table")
table.columns(_("Name"),
_("Type"),
_("Group As"),
@ -345,7 +367,7 @@ def surname_table(obj, user, action, url=None, *args):
person_handle = args[0]
order = args[1]
retval = ""
table = Table()
table = Table("surname_table")
table.columns(_("Order"), _("Surname"),)
if user.is_authenticated():
try:
@ -366,7 +388,7 @@ def surname_table(obj, user, action, url=None, *args):
def source_table(obj, user, action, url=None, *args):
retval = ""
table = Table()
table = Table("source_table")
table.columns(_("ID"),
_("Title"),
_("Author"),
@ -394,7 +416,7 @@ def source_table(obj, user, action, url=None, *args):
def citation_table(obj, user, action, url=None, *args):
retval = ""
table = Table()
table = Table("citation_table")
table.columns(_("ID"),
_("Confidence"),
_("Page"))
@ -420,7 +442,7 @@ def citation_table(obj, user, action, url=None, *args):
def repository_table(obj, user, action, url=None, *args):
retval = ""
table = Table()
table = Table("repository_table")
table.columns(
_("ID"),
_("Type"),
@ -437,7 +459,7 @@ def repository_table(obj, user, action, url=None, *args):
def note_table(obj, user, action, url=None, *args):
retval = ""
table = Table()
table = Table("note_table")
table.columns(
_("ID"),
_("Type"),
@ -462,7 +484,7 @@ def note_table(obj, user, action, url=None, *args):
def data_table(obj, user, action, url=None, *args):
retval = ""
table = Table()
table = Table("data_table")
table.columns(_("Type"),
_("Value"),
)
@ -477,7 +499,7 @@ def data_table(obj, user, action, url=None, *args):
def attribute_table(obj, user, action, url=None, *args):
retval = ""
table = Table()
table = Table("attribute_table")
table.columns(_("Type"),
_("Value"),
)
@ -497,7 +519,7 @@ def attribute_table(obj, user, action, url=None, *args):
def address_table(obj, user, action, url=None, *args):
retval = ""
table = Table()
table = Table("address_table")
table.columns(_("Date"),
_("Address"),
_("City"),
@ -521,7 +543,7 @@ def address_table(obj, user, action, url=None, *args):
def location_table(obj, user, action, url=None, *args):
retval = ""
table = Table()
table = Table("location_table")
table.columns(_("Date"),
_("Address"),
_("City"),
@ -538,7 +560,7 @@ def location_table(obj, user, action, url=None, *args):
def media_table(obj, user, action, url=None, *args):
retval = ""
table = Table()
table = Table("media_table")
table.columns(_("Description"),
_("Type"),
)
@ -562,7 +584,7 @@ def media_table(obj, user, action, url=None, *args):
def internet_table(obj, user, action, url=None, *args):
retval = ""
table = Table()
table = Table("internet_table")
table.columns(_("Type"),
_("Path"),
_("Description"))
@ -581,7 +603,7 @@ def internet_table(obj, user, action, url=None, *args):
def association_table(obj, user, action, url=None, *args):
retval = ""
table = Table()
table = Table("association_table")
table.columns(_("Name"),
_("ID"),
_("Association"))
@ -600,7 +622,7 @@ def association_table(obj, user, action, url=None, *args):
def lds_table(obj, user, action, url=None, *args):
retval = ""
table = Table()
table = Table("lds_table")
table.columns(_("Type"),
_("Date"),
_("Status"),
@ -624,7 +646,7 @@ def lds_table(obj, user, action, url=None, *args):
def reference_table(obj, user, action, url=None, *args):
retval = ""
table = Table()
table = Table("reference_table")
table.columns(
_("Type"),
_("Reference"),
@ -637,7 +659,7 @@ def reference_table(obj, user, action, url=None, *args):
def person_reference_table(obj, user, action):
retval = ""
table = Table()
table = Table("person_reference_table")
table.columns(
_("Type"),
_("Reference"),
@ -659,7 +681,7 @@ def person_reference_table(obj, user, action):
def note_reference_table(obj, user, action):
retval = ""
table = Table()
table = Table("note_reference_table")
table.columns(
_("Type"),
_("Reference"),
@ -678,7 +700,7 @@ def note_reference_table(obj, user, action):
def event_reference_table(obj, user, action):
retval = ""
table = Table()
table = Table("event_reference_table")
table.columns(
_("Type"),
_("Reference"),
@ -697,7 +719,7 @@ def event_reference_table(obj, user, action):
def repository_reference_table(obj, user, action):
retval = ""
table = Table()
table = Table("repository_reference_table")
table.columns(
_("Type"),
_("Reference"),
@ -716,7 +738,7 @@ def repository_reference_table(obj, user, action):
def citation_reference_table(obj, user, action):
retval = ""
table = Table()
table = Table("citation_reference_table")
table.columns(
_("Type"),
_("Reference"),
@ -735,7 +757,7 @@ def citation_reference_table(obj, user, action):
def source_reference_table(obj, user, action):
retval = ""
table = Table()
table = Table("source_reference_table")
table.columns(
_("Type"),
_("Reference"),
@ -749,7 +771,7 @@ def source_reference_table(obj, user, action):
def media_reference_table(obj, user, action):
retval = ""
table = Table()
table = Table("media_reference_table")
table.columns(
_("Type"),
_("Reference"),
@ -768,7 +790,7 @@ def media_reference_table(obj, user, action):
def place_reference_table(obj, user, action):
retval = ""
table = Table()
table = Table("place_reference_table")
table.columns(
_("Type"),
_("Reference"),
@ -781,7 +803,7 @@ def place_reference_table(obj, user, action):
def tag_reference_table(obj, user, action):
retval = ""
table = Table()
table = Table("tag_reference_table")
table.columns(
_("Type"),
_("Reference"),
@ -800,7 +822,7 @@ def tag_reference_table(obj, user, action):
def children_table(obj, user, action, url=None, *args):
retval = ""
table = Table()
table = Table("children_table")
table.columns(
_("#"),
_("ID"),