def _add_script_table_row(self, table, scriptname, parent): tablerow = TableRow() # scriptname cell scriptname_cell = TableCell(scriptname) # command cell (we use # an empty cell as default) command_cell = TableCell() # parent cell if parent is None: parent = '(defined here)' # if script is defined here, instead of inherited # we make the command anchors. durl = 'delete.%s.%s' % (table.context, scriptname) eurl = 'edit.%s.%s' % (table.context, scriptname) delanchor = Anchor('delete', href=durl) editanchor = Anchor('edit', href=eurl) command_cell = TableCell(editanchor) command_cell.append(Break()) command_cell.append(delanchor) parent_cell = TableCell(parent) # append the cells to the rows tablerow.append(scriptname_cell) tablerow.append(parent_cell) tablerow.append(command_cell) table.append(tablerow)
class SimpleTitleElement(Table): def __init__(self, title, **attributes): Table.__init__(self, **attributes) self.row = TableRow() self.cell = TableCell() self.set(self.row) self.row.set(self.cell) self.h1 = Header(level=1) self._font = Font(color='gold') self.cell.set(self.h1) self.h1.set(self._font) self.set_title(title) def set_font(self, **attributes): self._font.attributes.clear() self._font.attributes.update(attributes) def set_title(self, title): self._title = title self._font.set(self._title) # use this to make action links to the right of the title def create_rightside_table(self): self._rstable = Table(border=0) self.row.append(TableCell(self._rstable, align='right')) def append_rightside_anchor(self, anchor): row = TableRow() self._rstable.append(row) cell = TableCell(align='right', rowspan=1) row.set(cell) font = Font(color='gold') cell.set(font) font.set(anchor)
def append_rightside_anchor(self, anchor): row = TableRow() self._rstable.append(row) cell = TableCell(align='right', rowspan=1) row.set(cell) font = Font(color='gold') cell.set(font) font.set(anchor)
def set_options(self, items): hrow = TableRow() self.set(hrow) hrow.append(TableHeader('Option')) hrow.append(TableHeader('Value')) for k, v in items: row = TableRow() self.append(row) row.append(TableCell(k)) row.append(TableCell(str(v)))
class SimpleTitleTable(Table): def __init__(self, title, **args): Table.__init__(self, **args) self.row = TableRow() self.td = TableCell() self.append(self.row) self.row.append(self.td) self.set_title(title) def set_title(self, title): self._title = title self.td.set(Header(title, 1))
def _add_table_row(self, table, fields, row): tablerow = TableRow() for field in fields: tablerow.append(TableCell(str(row[field]))) durl = 'delete.%s.%s' % (table.context, row[fields[0]]) eurl = 'edit.%s.%s' % (table.context, row[fields[0]]) delanchor = Anchor('delete', href=durl) editanchor = Anchor('edit', href=eurl) cell = TableCell(editanchor) cell.append(Break()) cell.append(delanchor) tablerow.append(cell) table.append(tablerow)
def _add_variables_table_row(self, table, fields, row): tablerow = TableRow() for field in fields: tablerow.append(TableCell(str(row[field]))) ident = '%s||%s' % (row['trait'], row['name']) durl = 'delete.%s.%s' % (table.context, ident) eurl = 'edit.%s.%s' % (table.context, ident) delanchor = Anchor('delete', href=durl) editanchor = Anchor('edit', href=eurl) cell = TableCell(editanchor) cell.append(Break()) cell.append(delanchor) tablerow.append(cell) table.append(tablerow)
def refresh_page(self): self.clear_body() title = SectionTitle('Kernels') self.body.append(title) kernels = self.kernels.get_kernels() table = Table() self.body.append(table) for kernel in kernels: tablerow = TableRow() cell = TableCell(kernel) tablerow.append(cell) del_anchor = Anchor('(delete)', href='delete||kernel||%s' % kernel) cell = TableCell(del_anchor) tablerow.append(cell) table.append(tablerow)
def __init__(self, fields, idcol, action, record, **args): Table.__init__(self, **args) self.record = record for field in fields: row = TableRow() row.append(TableCell(Bold(field))) val = TableCell() data = str(record[field]) if action: href = '%s?%s=%s' % (action, idcol, record[idcol]) a = Anchor(data, href=href) val.append(a) else: val.append(data) row.append(val) self.append(row)
def __init__(self, title, **args): Table.__init__(self, **args) self.row = TableRow() self.td = TableCell() self.append(self.row) self.row.append(self.td) self.set_title(title)
def __init__(self, rows, **atts): Table.__init__(self, **atts) packages = [] package_actions = {} for row in rows: if row.package not in packages: packages.append(row.package) package_actions[row.package] = [row.action] else: package_actions[row.package].append(row.action) for package in packages: tablerow = TableRow() tablerow.append(TableCell(package)) tablerow.append(TableCell(', '.join(package_actions[package]))) anchor = Anchor('delete', href='delete.package.%s' % package) tablerow.append(anchor) self.append(tablerow)
def set_rows(self, rows): for row in rows: tablerow = TableRow() show_anchor = Anchor(row.template, href='show.template.%s' % row.template) tablerow.append(TableCell(show_anchor)) template_data = '%s:%s (%s)' % (row.owner, row.grp_owner, row.mode) data_anchor = Anchor(template_data, href='edit.templatedata.%s' % row.template) edit_anchor = Anchor('(edit)', href='edit.template.%s' % row.template) del_anchor = Anchor('(delete)', href='delete.template.%s' % row.template) tablerow.append(TableCell(data_anchor)) cmdcell = TableCell() cmdcell.set(edit_anchor) cmdcell.append(del_anchor) tablerow.append(cmdcell) #tablerow.append(TableCell(edit_anchor)) #tablerow.append(TableCell(del_anchor)) self.append(tablerow)
def _make_scripts_table(self, trait): rows = self.trait._scripts.scripts(trait=trait) if rows: bgcolor = self.cfg.get('management_gui', 'traitdoc_variables_table_color') table = Table(bgcolor=bgcolor) for row in rows: script = row.script sa = Anchor(script, href='show.script.%s' % script) ea = Anchor('(edit)', href='edit.script.%s' % script) da = Anchor('(delete)', href='delete.script.%s' % script) trow = TableRow() trow.append(TableCell(sa)) trow.append(TableCell(ea)) trow.append(TableCell(da)) table.append(trow) return table
def __init__(self, fields, idcol, action, record, **args): Table.__init__(self, **args) self.record = record refdata = None if hasattr(record, '_refdata'): refdata = record._refdata for field in fields: row = TableRow() row.append(TableCell(Bold(field))) val = TableCell() data = str(record[field]) if refdata is not None and field in refdata.cols: print 'hello there - fix me' elif action: val.append(Anchor(data, href=action)) else: val.append(data) row.append(val) self.append(row)
def _setup_section(self, name, fields, rows): title = SectionTitle(name, bgcolor=self._bgcolor_section) title.set_font(color=self._other_section_font_color) anchor = Anchor('new', href='new.%s.machine' % name) title.row.append(TableCell(anchor)) self.body.append(title) if len(rows): table = self._make_table(name, fields, rows, border=1, cellspacing=1) color_header(table, self._bgcolor_thead) self.body.append(table)
def set_machine(self, machine): self.machine.set_machine(machine) self.clear_body() title = SectionTitle('Machine: %s' % machine) title['bgcolor'] = 'IndianRed' title['width'] = '100%' self.body.append(title) mtable = Table() for k, v in self.machine.current.items(): tablerow = TableRow() tablerow.append(TableCell(Bold(k))) tablerow.append(TableCell(v)) mtable.append(tablerow) self.body.append(mtable) newanchor = Anchor('new', href='new.machine.foo') editanchor = Anchor('edit', href='edit.machine.%s' % machine) self.body.append(Ruler()) self.body.append(editanchor) self.body.append(Break()) self.body.append(newanchor)
def __init__(self, title, **attributes): Table.__init__(self, **attributes) self.row = TableRow() self.cell = TableCell() self.set(self.row) self.row.set(self.cell) self.h1 = Header(level=1) self._font = Font(color='gold') self.cell.set(self.h1) self.h1.set(self._font) self.set_title(title)
def set_suite(self, suite): self.suite = suite self.cursor.set_suite(suite) self.clear_body() attributes = dict(bgcolor='IndianRed', width='100%') title = SimpleTitleElement('Suite: %s' % suite, **attributes) title.cell.attributes['align'] = 'center' self.body.append(title) apt_rows = self.cursor.get_apt_rows() if len(apt_rows): aptsrc_table = Table(bgcolor='khaki') self.body.append(aptsrc_table) fields = ['apt_id', 'uri', 'dist', 'sections', 'local_path'] headrow = TableRow() for field in fields: headrow.append(TableCell(Bold(field))) for row in apt_rows: tblrow = TableRow() aptsrc_table.append(tblrow) for field in fields: tblrow.append(TableCell(row[field]))
def _setup_main_attributes(self): machine = self.machine.current_machine attribute_table = Table(bgcolor=self._bgcolor_table, border=1) headrow = TableRow(bgcolor=self._bgcolor_thead) for col in ['Attribute', 'Value', 'Inherited From', 'Command']: headrow.append(TableHeader(col)) attribute_table.append(headrow) for attribute in ['kernel', 'profile', 'diskconfig']: errormsg = '' try: value, inherited_from = self.machine.get_attribute(attribute) except AttributeUnsetInAncestryError: errormsg = "WARNING: not set anywhere" value, inherited_from = errormsg, errormsg tablerow = TableRow() href = 'select.attribute||%s.%s' % (attribute, machine) anchor = Anchor(attribute, href=href) cell = TableCell(Bold(anchor, ':')) tablerow.append(cell) cell = TableCell(value) tablerow.append(value) cell = TableCell() if inherited_from is not None: if errormsg: anchor = Bold(errormsg) else: anchor = Anchor(inherited_from, href='select.machine.%s' % inherited_from) cell.append(anchor) else: cell.append('(set here)') tablerow.append(cell) cell = TableCell() anchor = Anchor('clear', href='delete.attribute||%s.%s' % (attribute, machine)) if inherited_from is None: cell.set(anchor) tablerow.append(cell) attribute_table.append(tablerow) self.body.append(attribute_table)
def _setup_section(self, name, fields, rows): title = SectionTitle(name) title.set_font(color='DarkViolet') anchor = Anchor('new', href='new.%s.mtype' % name) title.row.append(TableCell(anchor)) self.body.append(title) if len(rows): table = self._make_table(name, fields, rows, border=1, cellspacing=1) color_header(table, 'MediumOrchid2') self.body.append(table)
def _setup_variables_section(self, rows): section = 'Variables' machine = self.machine.current_machine relation = self.machine.relation # make the section title = SectionTitle(section, bgcolor=self._bgcolor_section) title.set_font(color=self._other_section_font_color) anchor = Anchor('new', href='new.%s.machine' % section) title.row.append(TableCell(anchor)) self.body.append(title) if len(rows): table = self._make_variables_table(rows, border=1, cellspacing=1) color_header(table, self._bgcolor_thead) self.body.append(table)
def _setup_parent_table(self): machine = self.machine.current_machine parent_table = Table(bgcolor=self._bgcolor_table, border=1) parent = self.machine.parent if parent is None: parent = '(No Parent Set)' headrow = TableRow(bgcolor=self._bgcolor_thead) for col in ['parent', 'command']: headrow.append(TableHeader(col)) parent_table.append(headrow) mainrow = TableRow() parent_cell = TableCell(parent) mainrow.append(parent_cell) select_anchor = Anchor('select', href='select.parent.%s' % machine) delete_anchor = Anchor('delete', href='delete.parent.%s' % machine) command_cell = TableCell() command_cell.append(select_anchor) if self.machine.parent is not None: #command_cell.append(Break()) command_cell.append('|=====|') command_cell.append(delete_anchor) mainrow.append(command_cell) parent_table.append(mainrow) self.body.append(parent_table)
def _setup_script_section(self): machine = self.machine.current_machine relation = self.machine.relation scriptnames = relation.scripts.scriptnames scripts = [] for scriptname in scriptnames: result = relation.get_script(scriptname, show_inheritance=True) if result is not None: # if result is not None, then result is a tuple # that is (fileobj, parent) # but we need scriptname, parent scripts.append((scriptname, result[1])) # make the section title = SectionTitle('Scripts', bgcolor=self._bgcolor_section) title.set_font(color=self._other_section_font_color) anchor = Anchor('new', href='new.%s.machine' % 'Scripts') title.row.append(TableCell(anchor)) self.body.append(title) if len(scripts): table = self._make_script_table(scripts, border=1, cellspacing=1) color_header(table, self._bgcolor_thead) self.body.append(table)
def _set_youtube_video(self, entity): db = self.app.db name = TableHeader(str(entity.name), colspan=2, align="center") name_row = TableRow(name) self.set(name_row) yid = Bold("Youtube ID: ") cell = TableCell(yid) cell.append(str(entity.extfields["youtubeid"].value)) self.append(TableRow(cell)) filename = str(entity.extfields["local-filename"].value) filehandler = self.app.filehandler dpath = filehandler.main_path / "downloads" fullpath = dpath / filename if fullpath.exists(): href = myurl.make("play", "entity", str(entity.entityid)) cell = TableCell(Anchor("play", href=href)) else: href = myurl.make("download", "entity", str(entity.entityid)) youtubeid = str(entity.extfields["youtubeid"].value) mainhref = Url("http://youtube.com/watch?v=%s" % youtubeid) cell = TableCell(Anchor("download", href=href)) cell.append(Anchor("(main url)", href=mainhref)) self.append(TableRow(cell))
def set_info(self, guestid): guests_db = self.app.guests data = guests_db.get_guest_data(guestid) name = '%s %s' % (data['firstname'], data['lastname']) fullname = TableHeader(name, colspan=0, align='center') fullname_row = TableRow(fullname) edit_anchor = Anchor('edit', href='guest||edit||%d' % guestid) cell = TableCell(edit_anchor) fullname_row.append(cell) self.set(fullname_row) title = data['title'] if title: title = TableCell(title, colspan=2) title_row = TableRow(title) self.append(title_row) desc = data['description'] if desc: desc = self.app.guests.unescape_text(desc) span = Span(desc) cell = TableCell(span, colspan=2) if len(desc) > 150: span['style'] = 'font-size: x-small' desc_row = TableRow(cell) self.append(desc_row) ################# # works section # ################# workheader = TableHeader('Works', colspan=0, align='center') new_work_anchor = Anchor('add', href='work||new||%d' % guestid) cell = TableCell(new_work_anchor) workheader_row = TableRow(workheader) workheader_row.append(cell) self.append(workheader_row) # add works works = guests_db.get_guest_works(guestid) if works: worktable = GuestWorksTable(width='100%') worktable.set_info(works) cell = TableCell(worktable, colspan=2) trow = TableRow(cell) self.append(trow) else: workheader.set('No Works') ####################### # appearances section # ####################### appearance_header = TableHeader('Appearances', colspan=0, align='center') new_appearance_anchor = Anchor('add', href='appearance||new||%d' % guestid) cell = TableCell(new_appearance_anchor) appearance_header_row = TableRow(appearance_header) appearance_header_row.append(cell) self.append(appearance_header_row) appearances = guests_db.get_appearances(guestid) if appearances: for row in appearances: #print row url = row['url'] sdate = parse_appearance_m3u_url(url) app_anchor = Anchor(sdate, href=url) cell = TableCell(app_anchor) h1, h2 = make_mp3_links(url) h1_anchor = Anchor('(hr1)', href=h1) h2_anchor = Anchor('(hr2)', href=h2) span = Span(style='font-size: xx-small') span.append(h1_anchor) span.append(h2_anchor) cell.append(span) trow = TableRow(cell) cell = TableCell() edit_anchor = Anchor('edit', href='appearance||edit||%s' % url) play_anchor = Anchor('(play)', href='appearance||play||%s' % url) cell.append(edit_anchor) cell.append(play_anchor) trow.append(cell) self.append(trow) else: appearance_header.set('No Appearances') ####################### # pictures section # ####################### pix_header = TableHeader('Pictures', colspan=0, align='center') newpix_anchor = Anchor('add', href='picture||new||%d' % guestid) cell = TableCell(newpix_anchor) pix_header_row = TableRow(pix_header) pix_header_row.append(cell) self.append(pix_header_row) pictures = guests_db.get_guest_pictures(guestid) if pictures: datadir = self.app.datadir for row in pictures: filename = row['all_pictures.filename'] fullpath = os.path.join(datadir, filename) image = Image(src=fullpath, width='100', height='100') cell = TableCell(image) trow = TableRow(cell) span = Span(style='font-size: xx-small') span.append(filename) cell = TableCell(span) trow.append(cell) self.append(trow) else: pix_header.set('No Pictures')
def set_suite(self, suite, apt_ids): self._content = [] headrow = TableRow(TableCell('Suite: %s' % suite)) self.append(headrow) aptsrc_row = TableRow(TableCell('Apt Sources'))
def __init__(self, fields, idcol, action, record, **atts): Table.__init__(self, **atts) self.record = record refdata = None if hasattr(record, '_refdata'): refdata = record._refdata for field in fields: # make url first if action if action: stringlist = map(str, [action, field, record[idcol]]) url = '.'.join(stringlist) row = TableRow() keycell = TableCell() keycell.set(Bold(field)) row.append(keycell) valcell = TableCell() # the following code needs more comments # this should be a private method called _make_valcell if refdata is not None and field in refdata.cols: ridcol = refdata.cols[field] refrec = refrec.data[field][record[ridcol]] node = refdata.object[field](refrec) if action: valcell.set(Anchor(node, href=url)) else: valcell.set(node) elif action: valcell.set(Anchor(record[field], href=url)) else: valcell.set(record[field]) row.append(valcell) self.val = valcell self.key = keycell self.append(row)
def _make_packages_section(self, trait): ptitle = TraitSectionTitle(self.cfg, 'Packages', **self._sectitle_atts) ptitle_anchor = Anchor('(new)', href='new.package.%s' % trait) cell = TableCell(ptitle_anchor) ptitle.row.append(cell) return ptitle
def _add_table_row(self, table, fields, row): tablerow = TableRow() for field in fields: tablerow.append(TableCell(str(row[field]))) table.append(tablerow)
def __init__(self, text): print "Warning, TxtTD is deprecated" TableCell.__init__(self, text)