Exemplo n.º 1
0
    def input(self, *args, **kwargs):
        "required attributes: 'name' and 'type'"
        name, type, attrs = _attrs_from_args(('name', 'type'), *args, **kwargs)
        self._fields.add(name)
        if type in ('text', 'password', 'hidden', 'search', 'email', 'url',
                    'number', 'range', 'date', 'datetime', 'datetime-local',
                    'month', 'week', 'time', 'color'):
            self.asis(
                self.__class__.SimpleInput(name, type, attrs).render(
                    self.defaults, self.errors, self.error_wrapper))
            return
        if type == 'radio':
            if name not in self.radios:
                self.radios[name] = self.radio_group_class(name)
            checkable_group = self.radios[name]
        elif type == 'checkbox':
            if name not in self.checkboxes:
                self.checkboxes[name] = self.checkbox_group_class(name)
            checkable_group = self.checkboxes[name]
        else:
            if type == 'submit':
                raise DocError(
                    "Unhandled input type: submit. Use doc.stag('input', type = 'submit', value='whatever') instead."
                )
            else:
                raise DocError("Unknown input type: %s" % type)

        self._append(
            checkable_group.input(attrs).render(self.defaults, self.errors,
                                                self.error_wrapper))
Exemplo n.º 2
0
 def option(self, *args, **kwargs):
     "required attribute: 'value'"
     if self.current_select:
         value, attrs = _attrs_from_args(('value',), *args, **kwargs)
         return self.__class__.OptionTag(self, self.current_select, value, attrs)
     else:
         raise DocError("No <select> tag opened. Can't put an <option> here.")