コード例 #1
0
 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)
コード例 #2
0
 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"),
     )
コード例 #3
0
ファイル: html.py プロジェクト: navinkarkera/drivers
 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)
コード例 #4
0
 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)
コード例 #5
0
ファイル: html.py プロジェクト: navinkarkera/drivers
 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,
     ]
コード例 #6
0
ファイル: html.py プロジェクト: navinkarkera/drivers
 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)
コード例 #7
0
ファイル: html.py プロジェクト: navinkarkera/drivers
 def text(self, text, *agrs):
     return tags.P(*agrs, tags.Text(text))
コード例 #8
0
 def text(self, text, font_size="18px"):
     return tags.P(tags.Text(text), attributes.InlineStyle(font_size=font_size))