Exemplo n.º 1
0
class MultiCheckboxField(SelectMultipleField):
    """
    A multiple-select, except displays a list of checkboxes.

    Iterating the field will produce subfields, allowing custom rendering of
    the enclosed checkbox fields.
    """
    widget = widgets.TableWidget(with_table_tag=True)
    option_widget = widgets.CheckboxInput()
Exemplo n.º 2
0
 def _interface_elements(self):
     """See superclass documentation
     """
     choices = [(i, v) for i, v in enumerate(self.responses)
                if v != 'Unspecified']
     return ([0], [
         SelectMultipleField(self.id,
                             choices=choices,
                             widget=widgets.TableWidget(),
                             option_widget=widgets.CheckboxInput(),
                             coerce=lambda x: x)
     ])
Exemplo n.º 3
0
class boatsearchform(FlaskForm):
    sitename = RadioField('Site',
                          choices=[('YW', 'Yachtworld'),
                                   ('SBL', 'SailboatListings'),
                                   ('both', 'Both')],
                          widget=widgets.TableWidget(with_table_tag=True),
                          default='YW')
    inputcurr = StringField('inputcurr')
    minprice = StringField('minprice')
    maxprice = StringField('maxprice')
    minlength = StringField('minlength',
                            validators=[DataRequired(),
                                        Length(min=2, max=3)])
    maxlength = StringField('maxlength')
    sortparam = StringField('inputsearch')
    submit = SubmitField('Begin Search')
Exemplo n.º 4
0
class UserInfoForm(FlaskForm):
    """
    Edit user form

    Fields:

    - username (string field)
    - is_admin (checkbox)
    - organizations (select multiple field)
    """
    username = StringField('Username', validators=[DataRequired()])
    is_admin = BooleanField('Is Admin', default=False)
    organizations = SelectMultipleField(
        'Organizations',
        widget=widgets.TableWidget(with_table_tag=True),
        option_widget=widgets.CheckboxInput(),
        coerce=int)
    submit = SubmitField('Update')
Exemplo n.º 5
0
class OrgInfoForm(FlaskForm):
    """
    Edit Organization information form

    Field:

    - name (string field)
    - data directory (string field)
    - users (select multiple field)
    - submit button
    """
    name = StringField('Organization Name', validators=[DataRequired()])
    data_dir = StringField('Data directory', validators=[DataRequired()])
    users = SelectMultipleField(
        'Users',
        widget=widgets.TableWidget(with_table_tag=True),
        option_widget=widgets.CheckboxInput(),
        coerce=int)
    submit = SubmitField('Save')
Exemplo n.º 6
0
class FormField(Field):
    """
    Encapsulate a form as a field in another form.

    :param form_class:
        A subclass of Form that will be encapsulated.
    :param separator:
        A string which will be suffixed to this field's name to create the
        prefix to enclosed fields. The default is fine for most uses.
    """
    widget = widgets.TableWidget()

    def __init__(self, form_class, label=None, validators=None, separator='-', **kwargs):
        super(FormField, self).__init__(label, validators, **kwargs)
        self.form_class = form_class
        self.separator = separator
        self._obj = None
        if self.filters:
            raise TypeError('FormField cannot take filters, as the encapsulated data is not mutable.')
        if validators:
            raise TypeError('FormField does not accept any validators. Instead, define them on the enclosed form.')

    def process(self, formdata, data=unset_value):
        if data is unset_value:
            try:
                data = self.default()
            except TypeError:
                data = self.default
            self._obj = data

        self.object_data = data

        prefix = self.name + self.separator
        if isinstance(data, dict):
            self.form = self.form_class(formdata=formdata, prefix=prefix, **data)
        else:
            self.form = self.form_class(formdata=formdata, obj=data, prefix=prefix)

    def validate(self, form, extra_validators=tuple()):
        if extra_validators:
            raise TypeError('FormField does not accept in-line validators, as it gets errors from the enclosed form.')
        return self.form.validate()

    def populate_obj(self, obj, name):
        candidate = getattr(obj, name, None)
        if candidate is None:
            if self._obj is None:
                raise TypeError('populate_obj: cannot find a value to populate from the provided obj or input data/defaults')
            candidate = self._obj
            setattr(obj, name, candidate)

        self.form.populate_obj(candidate)

    def __iter__(self):
        return iter(self.form)

    def __getitem__(self, name):
        return self.form[name]

    def __getattr__(self, name):
        return getattr(self.form, name)

    @property
    def data(self):
        return self.form.data

    @property
    def errors(self):
        return self.form.errors
Exemplo n.º 7
0
class MultiCheckboxField(SelectMultipleField):
    widget = widgets.TableWidget()
    option_widget = widgets.CheckboxInput()
Exemplo n.º 8
0
class CheckBoxField(SelectMultipleField):
    widget = widgets.TableWidget(with_table_tag=False)
    option_widget = widgets.CheckboxInput()
Exemplo n.º 9
0
class MultiCheckboxField(SelectMultipleField):
    widget = widgets.TableWidget(with_table_tag=True)
    option_widget = widgets.CheckboxInput()
    coerce = str
Exemplo n.º 10
0
class CompleteForm(FlaskForm):
    habits = SelectMultipleField('Habits', coerce=int,
                                 widget=widgets.TableWidget(),
                                 option_widget=widgets.CheckboxInput())
    submit = SubmitField('Submit Completed Habits')
Exemplo n.º 11
0
class ArrayField(FieldList):
    widget = widgets.TableWidget()
Exemplo n.º 12
0
class AttributesField(FieldList):
    widget = widgets.TableWidget()
Exemplo n.º 13
0
class MultiCheckboxField(SelectMultipleField):
    widget = widgets.TableWidget()
    # widget = widgets.ListWidget(prefix_label=False) #alternative format
    option_widget = widgets.CheckboxInput()