示例#1
0
文件: fields.py 项目: enigma/watson
 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)
     )
示例#2
0
文件: fields.py 项目: enigma/watson
 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)
示例#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)
示例#4
0
文件: fields.py 项目: enigma/watson
 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)
示例#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)
示例#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)
示例#7
0
文件: fields.py 项目: enigma/watson
 def render(self):
     attributes = self.attributes.copy()
     return (
         self.html.format(
             flatten_attributes(attributes),
             self._options_render())
     )
示例#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)
示例#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)
示例#10
0
 def render(self, **kwargs):
     attributes = self.attributes.copy()
     attributes.update(kwargs)
     return (
         self.html.format(
             flatten_attributes(attributes),
             self._options_render())
     )
示例#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))
示例#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))
示例#13
0
文件: fields.py 项目: enigma/watson
 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()
示例#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))
示例#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))
示例#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()
示例#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)
示例#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))
示例#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)
示例#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))
示例#21
0
文件: fields.py 项目: enigma/watson
    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))
示例#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)
示例#23
0
 def open(self):
     """Render the start tag of the form.
     """
     return '<form {0}>'.format(flatten_attributes(self.attributes))
示例#24
0
 def render(self):
     attributes = self.attributes.copy()
     value = self.value if self.value else ''
     return self.html.format(flatten_attributes(attributes), value)
示例#25
0
 def test_flatten_forget_empty(self):
     attrs = {'class': 'menu', 'id': None}
     assert flatten_attributes(attrs) == 'class="menu"'
示例#26
0
 def test_flatten_keep_empty(self):
     attrs = {'class': 'menu', 'id': None}
     assert flatten_attributes(attrs, True) == 'class="menu" id=""'
示例#27
0
 def test_flatten(self):
     attrs = {'class': 'menu', 'id': 'MainMenu'}
     assert flatten_attributes(attrs) == 'class="menu" id="MainMenu"'
示例#28
0
 def test_flatten_keep_empty(self):
     attrs = {'class': 'menu', 'id': None}
     assert flatten_attributes(attrs, True) == 'class="menu" id=""'
示例#29
0
 def test_flatten_forget_empty(self):
     attrs = {'class': 'menu', 'id': None}
     assert flatten_attributes(attrs) == 'class="menu"'
示例#30
0
 def render(self):
     attributes = self.attributes.copy()
     value = self.value if self.value else ''
     return self.html.format(flatten_attributes(attributes), value)
示例#31
0
 def test_flatten(self):
     attrs = {'class': 'menu', 'id': 'MainMenu'}
     assert flatten_attributes(attrs) == 'class="menu" id="MainMenu"'
示例#32
0
 def open(self):
     """Render the start tag of the form.
     """
     return '<form {0}>'.format(flatten_attributes(self.attributes))