def table(self, data, border=True): elems = [] table_arr = None if isinstance(data, pd.DataFrame): table_arr = list(data.values.tolist()) elif isinstance(data, list): table_arr = data else: raise ValueError("Table should be array") for row in table_arr: res = [] if isinstance(row, list): for i in range(len(row)): cell = row[i] if isinstance(data, pd.DataFrame): col = list(data.columns)[i] res.append(tags.Td(self.__convert(cell, col))) else: res.append( tags.Td(tags.Text(cell) if isinstance(cell, str) else cell) ) else: res.append(tags.Td(tags.Text(row) if isinstance(row, str) else row)) elems.append(tags.Tr(res)) tab = tags.Table( attributes.InlineStyle(width="100%"), attributes.Class("table_border") if border else None, elems, ) return tags.P(tab)
def text(self, text, font_size="18px"): self.deprecatedPrint() return tags.P( tags.Text(text), attributes.InlineStyle(font_size=font_size, padding_left="10px", padding_right="10px"), )
def footer(self, text, first=None, *elems): one = [ attributes.InlineStyle( font_size="16px", font_weight="400", line_height="24px", margin_top="48px", ), tags.Text(text), first, ] return tags.Footer(tags.P(one), *elems)
def table(self, data, border=True): self.deprecatedPrint() elems = [] table_arr = None row_link = False row_link_index = -1 if isinstance(data, pd.DataFrame): table_arr = list(data.values.tolist()) row_link = True if "row_link" in data.columns else False try: row_link_index = list(data.columns).index("row_link") except ValueError: pass elif isinstance(data, list): table_arr = data else: error_text = f"Table should be array, not {data.__name__}" self.print_error(error_text) return None for row in table_arr: res = [] if isinstance(row, list): for i in range(len(row)): cell = row[i] if isinstance(data, pd.DataFrame): col = list(data.columns)[i] if row_link: if col != "row_link": link = row[row_link_index] res.append( tags.Td( tags.A( attributes.Href(link), self.__convert(cell, col), ))) else: res.append(tags.Td(self.__convert(cell, col))) else: res.append( tags.Td( tags.Text(cell) if isinstance(cell, str ) else cell)) else: res.append( tags.Td(tags.Text(row) if isinstance(row, str) else row)) elems.append(tags.Tr(res)) tab = tags.Table( attributes.InlineStyle(width="100%"), attributes.Class("table_border") if border else None, elems, ) return tags.P(tab)
def main( self, content=None, sub_title=None, cover=None, table=None, button=None, footer=None, ): return [ tags.Main( cover, self.subtitle(sub_title) if sub_title else None, tags.P(tags.Text(content) if isinstance(content, str) else content), table, button, ), footer, ]
def table(self, cells, column=2, border=False): elems = [] if len(cells) > column: sliced = slice_per(cells, column) for row in sliced: res = [] for cell in row: res.append( tags.Td(tags.Text(cell) if isinstance(cell, str) else cell) ) elems.append(tags.Tr(res)) else: row = cells res = [] for cell in row: res.append(tags.Td(tags.Text(cell) if isinstance(cell, str) else cell)) elems.append(tags.Tr(res)) tab = tags.Table( attributes.InlineStyle(width="100%"), attributes.Class("table_border") if border else None, elems, ) return tags.P(tab)
def text(self, text, *agrs): return tags.P(*agrs, tags.Text(text))
def text(self, text, font_size="18px"): return tags.P(tags.Text(text), attributes.InlineStyle(font_size=font_size))