Esempio n. 1
0
    def __init__(self, name, static=False, **kwargs):
        HtmlAttributeHolder.__init__(self, **kwargs)
        ElementRegistrar.__init__(self, self)

        self.elements = LazyOrderedDict()
        self.els = self.elements

        self._name = name
        # include a hidden field so we can check if this form was submitted
        self._form_ident_field = '%s-submit-flag' % name
        # registered element types
        self._registered_types = {}
        # our renderer
        self._renderer = None
        # this string is used to generate the HTML id attribute for each
        # rendering element
        self._element_id_formatter = '%(form_name)s-%(element_id)s'
        # our validators
        self._validators = []
        # file upload translator
        self._fu_translator = WerkzeugTranslator
        # form errors
        self._errors = []
        # exception handlers
        self._exception_handlers = []
        # is the form static?
        self._static = static

        # init actions
        self.register_elements(form_elements)
        self.add_hidden(self._form_ident_field, value='submitted')
Esempio n. 2
0
    def __init__(self, form, eid, label=NotGiven, defaultval=NotGiven, **kwargs):
        # settings to overide the form's settings
        self.settings = kwargs.pop('settings', {})
        self.label_after = kwargs.pop('label_after', False)

        HtmlAttributeHolder.__init__(self, **kwargs)

        self._defaultval = NotGiven
        self._displayval = NotGiven

        self.id = eid
        self.label = Label(self, label)
        self.form = form

        #: a list of user messages for this field (C{str})
        self.notes = []

        self.defaultval = defaultval
        self.set_attr('id', self.getidattr())

        # characteristics of this element
        self.is_defaultable = True
        self.is_renderable = True
        self.is_submittable = True
        self.is_returning = True
        self.renders_in_group = False
Esempio n. 3
0
    def test_set_attr(self):
        ah = HtmlAttributeHolder()
        ah.set_attr('src', 'src')
        ah.set_attr('class_', 'class')
        assert ah.attributes['src'] == 'src'
        assert ah.attributes['class'] == 'class'

        ah.set_attr('class_', 'class2')
        assert ah.attributes['class'] == 'class2'
Esempio n. 4
0
 def begin(self):
     attrs = HtmlAttributeHolder(**self.element.attributes)
     attrs.add_attr('class', 'static-form')
     for attr in ('enctype', 'method', 'action'):
         try:
             attrs.del_attr(attr)
         except KeyError:
             pass
     self.output.inc(HTML.div(None, _closed=False, **attrs.attributes))
Esempio n. 5
0
 def test_get_attr(self):
     ah = HtmlAttributeHolder(src='src', class_='class')
     assert ah.get_attr('src') == 'src'
     assert ah.get_attr('class') == 'class'
     assert ah.get_attr('class_') == 'class'
Esempio n. 6
0
 def test_set_attrs(self):
     ah = HtmlAttributeHolder()
     ah.set_attrs(src='src', class_='class')
     assert ah.attributes['src'] == 'src'
     assert ah.attributes['class'] == 'class'
Esempio n. 7
0
 def test_init(self):
     ah = HtmlAttributeHolder(src='src', class_='class')
     assert ah.attributes['src'] == 'src'
     assert ah.attributes['class'] == 'class'
Esempio n. 8
0
 def test_add_attr(self):
     ah = HtmlAttributeHolder(src='src', class_='class')
     ah.add_attr('class_', 'class2')
     assert ah.attributes['src'] == 'src'
     assert ah.attributes['class'] == 'class class2'
Esempio n. 9
0
 def test_del_attr(self):
     ah = HtmlAttributeHolder(src='src', class_='class')
     ah.del_attr('src')
     ah.del_attr('class')
     assert 'src' not in ah.attributes
     assert 'class' not in ah.attributes