Advertisement
Mochinov

Untitled

Sep 7th, 2022
949
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.52 KB | None | 0 0
  1.  
  2.  
  3. class FormElementStructure:
  4.     """
  5.    Класс для установки настроек формы
  6.  
  7.    """
  8.     element_list = {
  9.         'password': '<input type="password" name="%s" placeholder="%s" class="%s" %s>',
  10.         '_file': '<input type="file" name="%s" placeholder="%s" class="%s" %s>',
  11.  
  12.         'text': '<input type="text" name="%s" placeholder="%s class="%s" %s>',
  13.         'email': '<input type="email" name="%s" placeholder="%s" class="%s" %s>',
  14.         'number': '<input type="number" name="%s" min="0" max="9999999" placeholder="%s" class="%s" %s>',
  15.         'url': '<input type="url" name="%s" placeholder="%s" class="%s" %s>',
  16.         'phone': '<input type="tel" name="%s" pattern="[0-9]{3}-[0-9]{3}-[0-9]{4}" placeholder="%s" class="%s" %s>',
  17.     }
  18.  
  19.     @staticmethod
  20.     def form_element(
  21.         cls,
  22.         name: str,
  23.         type_form: str,
  24.         class_element: str,
  25.         placeholder: str,
  26.         attrs: dict = None,
  27.     ) -> str:
  28.         """_summary_
  29.  
  30.        Args:
  31.            name (str): _description_
  32.            type_form (str): _description_
  33.            class_element (str): _description_
  34.            placeholder (str): _description_
  35.            attrs (dict, optional): _description_. Defaults to None.
  36.  
  37.        Returns:
  38.            str: _description_
  39.        """
  40.         return cls.element_list[type_form].format(
  41.             name,
  42.             placeholder,
  43.             class_element,
  44.             ' '.join([f'data-{item}={attrs[item]}' for item in attrs]),
  45.         )
  46.  
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement