Exemple #1
0
 def button(
     self,
     link,
     text="Open",
     width="auto",
     color="white",
     background_color="black",
 ):
     self.deprecatedPrint()
     return tags.Center(
         tags.Div(
             attributes.InlineStyle(margin="48px 0"),
             tags.A(
                 attributes.Class("button"),
                 attributes.Href(link),
                 attributes.InlineStyle(
                     background_color=background_color,
                     color=color,
                     border_radius="4px",
                     display="inline-block",
                     font_family="sans-serif",
                     font_size="18px",
                     font_weight="bold",
                     line_height="60px",
                     text_align="center",
                     text_decoration="none",
                     width=width,
                     max_width="300px",
                     padding_left="10px",
                     padding_right="10px",
                     _webkit_text_size_adjust="none",
                 ),
                 tags.Text(text),
             ),
         ))
Exemple #2
0
 def button(self, text, link, color="#ffffff", background_color="#B200FD"):
     return tags.Center(
         tags.Div(
             attributes.InlineStyle(margin="48px 0"),
             tags.A(
                 attributes.Class("button"),
                 attributes.Href(link),
                 attributes.InlineStyle(
                     background_color=background_color,
                     color=color,
                     border_radius="4px",
                     display="inline-block",
                     font_family="sans-serif",
                     font_size="18px",
                     font_weight="bold",
                     line_height="60px",
                     text_align="center",
                     text_decoration="none",
                     width="300px",
                     _webkit_text_size_adjust="none",
                 ),
                 tags.Text(text),
             ),
         )
     )
Exemple #3
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)
Exemple #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)
Exemple #5
0
 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)
Exemple #6
0
 def generate(self,
              title,
              logo=None,
              display="embed",
              footer=None,
              **kwargs):
     self.deprecatedPrint()
     gen_html = tags.Html(
         attributes.Lang("en"),
         tags.Head(
             tags.Meta(
                 attributes.HttpEquiv("Content-Type"),
                 attributes.Content("text/html; charset=utf-8"),
             ),
             tags.Meta(
                 attributes.HttpEquiv("Content-Type"),
                 attributes.Content("width=device-width, initial-scale=1"),
             ),
             tags.Meta(
                 attributes.Name("viewport"),
                 attributes.Content("width=device-width, initial-scale=1"),
             ),
             tags.Meta(
                 attributes.HttpEquiv("X-UA-Compatible"),
                 attributes.Content("IE=edge"),
             ),
             tags.Style(tags.Text(base_style)),
             tags.Title(tags.Text(title)),
         ),
         tags.Body(
             attributes.InlineStyle(margin="0 !important",
                                    padding="0 !important"),
             tags.Div(
                 attributes.InlineStyle(display="none",
                                        max_height="0",
                                        overflow="hidden"),
                 tags.Text(title),
             ),
             tags.Div(
                 attributes.InlineStyle(display="none",
                                        max_height="0",
                                        overflow="hidden"),
                 tags.Text(" ‌" * 240),
             ),
             tags.Text(table_ie9),
             tags.Div(
                 {
                     "name": "role",
                     "value": "article"
                 },
                 {
                     "name": "aria-label",
                     "value": title
                 },
                 attributes.Lang("en"),
                 attributes.Class("basic_font"),
                 attributes.InlineStyle(
                     background_color="white",
                     color="#2b2b2b",
                     font_size="18px",
                     font_weight="400",
                     line_height="28px",
                     margin="0 auto",
                     max_width="720px",
                     padding="40px 20px 40px 20px",
                 ),
                 self.header(logo, self.title(title)),
                 self.main(**kwargs),
                 footer,
             ),
             tags.Text(table_ie9_close),
         ),
     )
     res = gen_html.render()
     self.__display(res, display)
     return res