Esempio n. 1
0
 def render(self):
     attributes = self.attributes.copy()
     if self.value:
         attributes['value'] = str(self.value)
     return (
         self.html.format(flatten_attributes(attributes), self.label.text)
     )
Esempio n. 2
0
 def __render_input(self, id, attributes, label_text):
     element = self.html.format(attributes)
     output = '{0}{1}'
     attrs = self.label.attributes.copy()
     attrs['for'] = id
     flat_attrs = flatten_attributes(attrs)
     if self.wrapped:
         if self.label_position == 'left':
             return (
                 self.label.html.format(
                     flat_attrs,
                     output.format(
                         label_text,
                         element))
             )
         return (
             self.label.html.format(
                 flat_attrs,
                 output.format(element,
                               label_text))
         )
     else:
         label = self.label.html.format(flat_attrs, label_text)
         if self.label_position == 'left':
             return output.format(label, element)
         return output.format(element, label)
Esempio n. 3
0
 def __render_input(self, id, attributes, label_text):
     element = self.html.format(attributes)
     output = '{0}{1}'
     attrs = self.label.attributes.copy()
     attrs['for'] = id
     flat_attrs = flatten_attributes(attrs)
     if self.wrapped:
         if self.label_position == 'left':
             return (
                 self.label.html.format(
                     flat_attrs,
                     output.format(
                         label_text,
                         element))
             )
         return (
             self.label.html.format(
                 flat_attrs,
                 output.format(element,
                               label_text))
         )
     else:
         label = self.label.html.format(flat_attrs, label_text)
         if self.label_position == 'left':
             return output.format(label, element)
         return output.format(element, label)
Esempio n. 4
0
 def render(self):
     multiple_elements = self.has_multiple_elements()
     elements = []
     for index, label_value_pair in enumerate(self.values):
         attributes = self.attributes.copy()
         label_text, value = label_value_pair
         if multiple_elements:
             element_id = '{0}_{1}'.format(self.name, index)
         else:
             element_id = self.name
         attributes.update({
             'name': self.name,
             'id': element_id
         })
         if value:
             attributes['value'] = value
         if isinstance(self.value, (list, tuple)) and value in self.value:
             attributes['checked'] = 'checked'
         elif self.value and value == self.value:
             attributes['checked'] = 'checked'
         flat_attributes = flatten_attributes(attributes)
         element = self.__render_input(
             element_id,
             flat_attributes,
             label_text)
         elements.append(element)
     return ''.join(elements)
Esempio n. 5
0
 def render(self, **kwargs):
     multiple_elements = self.has_multiple_elements()
     elements = []
     for index, label_value_pair in enumerate(self.values):
         attributes = self.attributes.copy()
         label_text, value = label_value_pair
         if multiple_elements:
             element_id = '{0}_{1}'.format(self.name, index)
         else:
             element_id = self.name
         attributes.update({
             'name': self.name,
             'id': element_id
         })
         attributes.update(kwargs)
         if value:
             attributes['value'] = value
         if isinstance(self.value, (list, tuple)) and value in self.value:
             attributes['checked'] = 'checked'
         elif self.value and value == self.value:
             attributes['checked'] = 'checked'
         flat_attributes = flatten_attributes(attributes)
         element = self.__render_input(
             element_id,
             flat_attributes,
             label_text)
         elements.append(element)
     return ''.join(elements)
Esempio n. 6
0
 def render(self, **kwargs):
     attributes = self.attributes.copy()
     attributes.update(kwargs)
     if self.value:
         attributes['value'] = str(self.value)
     label = kwargs.get('label', self.label.text)
     return self.html.format(flatten_attributes(attributes), label)
Esempio n. 7
0
 def render(self):
     attributes = self.attributes.copy()
     return (
         self.html.format(
             flatten_attributes(attributes),
             self._options_render())
     )
Esempio n. 8
0
 def render(self, field):
     attrs = self.attributes.copy()
     if not 'id' in field.attributes and field.name:
         # inject id based on field name
         id = field.name
         field.attributes['id'] = id
         attrs['for'] = id
     return self.html.format(flatten_attributes(attrs), self.text)
Esempio n. 9
0
 def render(self, field):
     attrs = self.attributes.copy()
     if not 'id' in field.attributes and field.name:
         # inject id based on field name
         id = field.name
         field.attributes['id'] = id
         attrs['for'] = id
     return self.html.format(flatten_attributes(attrs), self.text)
Esempio n. 10
0
 def render(self, **kwargs):
     attributes = self.attributes.copy()
     attributes.update(kwargs)
     return (
         self.html.format(
             flatten_attributes(attributes),
             self._options_render())
     )
Esempio n. 11
0
    def open(self, **kwargs):
        """Render the start tag of the form.

        Any addition kwargs will be used within the attributes.
        """
        attrs = self.attributes.copy()
        if kwargs:
            attrs.update(kwargs)
        return '<form {0}>'.format(flatten_attributes(attrs))
Esempio n. 12
0
    def open(self, **kwargs):
        """Render the start tag of the form.

        Any addition kwargs will be used within the attributes.
        """
        attrs = self.attributes.copy()
        if kwargs:
            attrs.update(kwargs)
        return '<form {0}>'.format(flatten_attributes(attrs))
Esempio n. 13
0
 def render(self):
     if self.button_mode:
         attributes = self.attributes.copy()
         return (
             self.html.format(
                 flatten_attributes(attributes),
                 self.label.text)
         )
     return super(Submit, self).render()
Esempio n. 14
0
    def render(self):
        """Render the element as html.

        Does not need to be called directly, as will be called by __str__
        natively.
        """
        attributes = self.attributes.copy()
        if self.value:
            attributes['value'] = str(self.value)

        return self.html.format(flatten_attributes(attributes))
Esempio n. 15
0
    def render(self):
        """Render the element as html.

        Does not need to be called directly, as will be called by __str__
        natively.
        """
        attributes = self.attributes.copy()
        if self.value:
            attributes['value'] = str(self.value)

        return self.html.format(flatten_attributes(attributes))
Esempio n. 16
0
 def render(self, **kwargs):
     label = kwargs.pop('label') if 'label' in kwargs else self.label.text
     if self.button_mode:
         attributes = self.attributes.copy()
         attributes.update(kwargs)
         return (
             self.html.format(
                 flatten_attributes(attributes),
                 label)
         )
     return super(Submit, self).render()
Esempio n. 17
0
 def render(self, field=None, **kwargs):
     attrs = self.attributes.copy()
     if 'text' in kwargs:
         self.text = kwargs['text']
         del kwargs['text']
     if 'for_' in kwargs:
         attrs['for'] = kwargs['for_']
         del kwargs['for_']
     attrs.update(kwargs)
     if field and 'id' not in field.attributes and field.name:
         # inject id based on field name
         id = field.name
         field.attributes['id'] = id
         attrs['for'] = id
     return self.html.format(flatten_attributes(attrs), self.text)
Esempio n. 18
0
    def render(self, **kwargs):
        """Render the element as html.

        Does not need to be called directly, as will be called by __str__
        natively.
        """
        attributes = self.attributes.copy()
        if '_class' in kwargs:
            kwargs['class'] = kwargs.get('_class')
            del kwargs['_class']
        attributes.update(kwargs)
        if self.value:
            attributes['value'] = str(self.value)

        return self.html.format(flatten_attributes(attributes))
Esempio n. 19
0
 def render(self, **kwargs):
     multiple_elements = self.has_multiple_elements()
     elements = []
     id = self.attributes.get('id', self.name)
     values = self.values
     for index, label_value_pair in enumerate(values):
         attributes = self.attributes.copy()
         label_text, value = label_value_pair
         if multiple_elements:
             element_id = '{0}_{1}'.format(id, index)
         else:
             element_id = id
         attributes.update({
             'name': self.name,
             'id': element_id
         })
         attributes.update(kwargs)
         if value:
             attributes['value'] = value
         value = str(value)
         checked = False
         if isinstance(self.value, (list, tuple)) and value in (str(val) for val in self.value):
             checked = True
         elif self.value and value == str(self.value):
             checked = True
         elif isinstance(self.value, enum.Enum) and value == self.value.name:
             checked = True
         if checked:
             attributes['checked'] = 'checked'
         flat_attributes = flatten_attributes(attributes)
         element = self.__render_input(
             element_id,
             flat_attributes,
             label_text)
         elements.append(element)
     return ''.join(elements)
Esempio n. 20
0
    def render(self):
        """Overridden to prevent value from being put back into the field.
        """
        attributes = self.attributes.copy()

        return self.html.format(flatten_attributes(attributes))
Esempio n. 21
0
    def render(self):
        """Overridden to prevent value from being put back into the field.
        """
        attributes = self.attributes.copy()

        return self.html.format(flatten_attributes(attributes))
Esempio n. 22
0
 def render(self, **kwargs):
     attributes = self.attributes.copy()
     attributes.update(kwargs)
     value = self.value if self.value else ''
     return self.html.format(flatten_attributes(attributes), value)
Esempio n. 23
0
 def open(self):
     """Render the start tag of the form.
     """
     return '<form {0}>'.format(flatten_attributes(self.attributes))
Esempio n. 24
0
 def render(self):
     attributes = self.attributes.copy()
     value = self.value if self.value else ''
     return self.html.format(flatten_attributes(attributes), value)
Esempio n. 25
0
 def test_flatten_forget_empty(self):
     attrs = {'class': 'menu', 'id': None}
     assert flatten_attributes(attrs) == 'class="menu"'
Esempio n. 26
0
 def test_flatten_keep_empty(self):
     attrs = {'class': 'menu', 'id': None}
     assert flatten_attributes(attrs, True) == 'class="menu" id=""'
Esempio n. 27
0
 def test_flatten(self):
     attrs = {'class': 'menu', 'id': 'MainMenu'}
     assert flatten_attributes(attrs) == 'class="menu" id="MainMenu"'
Esempio n. 28
0
 def test_flatten_keep_empty(self):
     attrs = {'class': 'menu', 'id': None}
     assert flatten_attributes(attrs, True) == 'class="menu" id=""'
Esempio n. 29
0
 def test_flatten_forget_empty(self):
     attrs = {'class': 'menu', 'id': None}
     assert flatten_attributes(attrs) == 'class="menu"'
Esempio n. 30
0
 def render(self):
     attributes = self.attributes.copy()
     value = self.value if self.value else ''
     return self.html.format(flatten_attributes(attributes), value)
Esempio n. 31
0
 def test_flatten(self):
     attrs = {'class': 'menu', 'id': 'MainMenu'}
     assert flatten_attributes(attrs) == 'class="menu" id="MainMenu"'
Esempio n. 32
0
 def open(self):
     """Render the start tag of the form.
     """
     return '<form {0}>'.format(flatten_attributes(self.attributes))