Exemple #1
0
  def __init__(self, template=None, widget_mode='dropdown', h24_mode=True, minuteStep=1,
               showSeconds=False, secondStep=1, showInputs=False,
               disableFocus=False, modalBackdrop=False):
    Input.__init__(self)

    if template is not None:
      self.template = template

    self.widget_mode = widget_mode
    self.h24_mode = h24_mode
    self.minuteStep = minuteStep
    self.showSeconds = showSeconds
    self.secondStep = secondStep
    self.showInputs = showInputs
    self.disableFocus = disableFocus
    self.modalBackdrop = modalBackdrop
    self.strptime = u'%H:%M' if self.h24_mode else u'%I:%M %p'
Exemple #2
0
    def __new__(mcs, entity: Entity, skip_attrs=None, custom_validators=None, skip_pk=True, hide_attrs=None):
        if skip_attrs is None:
            skip_attrs = set()
        if custom_validators is None:
            custom_validators = dict()
        if hide_attrs is None:
            hide_attrs = set()

        class Form(FlaskForm):
            pass

        for colum in entity.__table__.columns:
            if colum.name in skip_attrs:
                continue

            if skip_pk and colum.primary_key:
                continue

            kwargs = dict()
            if colum.name in hide_attrs:
                kwargs = dict(widget=Input(input_type='hidden'))

            if not colum.foreign_keys:
                vals = []
                required = not colum.nullable

                if colum.name in custom_validators:
                    vals.extend(custom_validators[colum.name])

                if required and colum.name not in hide_attrs:
                    vals.append(validators.DataRequired())

                if colum.primary_key and type(colum.type) == String:
                    # Just use things that wont mess the uri: Issue: pallets/flask#900
                    vals.append(simple_str_validator)

                t = None

                if isinstance(colum.type, Enum):
                    label = colum.name[0].upper() + colum.name[1:]
                    t = SelectField(
                        " ".join(label.split('_')),
                        validators=vals,
                        choices=colum.type.enum_class.choices(),
                        coerce=colum.type.enum_class.coerce,
                        **kwargs
                    )
                elif isinstance(colum.type, Boolean):
                    t = BooleanField(validators=vals, **kwargs)
                elif isinstance(colum.type, Integer):
                    t = IntegerField(validators=vals if required else [validators.Optional()], **kwargs)
                elif isinstance(colum.type, Date):
                    t = DateField(validators=vals if required else [validators.Optional()], **kwargs)
                elif isinstance(colum.type, String) and colum.type.length:
                    t = StringField(validators=vals, render_kw=dict(maxlength=colum.type.length), **kwargs)
                elif isinstance(colum.type, String):
                    t = TextAreaField(validators=vals, **kwargs)
                elif isinstance(colum.type, Float):
                    t = FloatField(validators=vals, **kwargs)

                if t is not None:
                    setattr(Form, colum.name, t)

        return Form
Exemple #3
0
 def test_input_type(self):
     a = Input()
     self.assertRaises(AttributeError, getattr, a, 'input_type')
     b = Input(input_type='test')
     self.assertEqual(b.input_type, 'test')
Exemple #4
0
 def __call__(self, field, **kwargs):
   kwargs = get_html5_kwargs(field, kwargs)
   return _Input.__call__(self, field, **kwargs)
Exemple #5
0
class TimesheetForm(FlaskForm):
    # def out_time_validator(in_time):
    # 	message = "Out time must be after in time!"

    # 	def _out_time_validator(form, field):
    # 		print(in_time)
    # 		out_time = time.strptime(field, '%H:%M')

    name = TextField('Name:', validators=[validators.required()])
    mcgill_id = IntegerField(
        'McGill ID:',
        validators=[
            validators.required(),
            validators.NumberRange(
                min=260000000,
                max=260999999,
                message="Are you sure that looks like a McGill ID number?")
        ])
    hourly_rate = DecimalField('Hourly rate:',
                               validators=[validators.required()])
    fund_number = IntegerField('Fund number:',
                               validators=[validators.optional()])
    timesheet_template = SelectField(
        'Timesheet template:',
        validators=[validators.required()],
        default='1',
        choices=constants.timesheet_template_choices)

    default_date = datetime.datetime.now()
    default_date_montreal = pytz.timezone('America/Toronto').localize(
        default_date)

    week_of_year = SelectField('Week of:',
                               validators=[validators.required()],
                               default=str(default_date_montreal.year),
                               choices=constants.week_of_year_choices)
    week_of_month = SelectField('Week of:',
                                validators=[validators.required()],
                                default=str(default_date_montreal.month),
                                choices=constants.week_of_month_choices)
    week_of_day = SelectField('Week of:',
                              validators=[validators.required()],
                              default=str(default_date_montreal.day),
                              choices=constants.week_of_day_choices)

    sunday_in = TimeField(
        validators=[validators.optional(),
                    InTimeValidator('sunday_out')],
        widget=Input(input_type='time'))
    sunday_out = TimeField(
        validators=[validators.optional(),
                    OutTimeValidator('sunday_in')],
        widget=Input(input_type='time'))
    monday_in = TimeField(
        validators=[validators.optional(),
                    InTimeValidator('monday_out')],
        widget=Input(input_type='time'))
    monday_out = TimeField(
        validators=[validators.optional(),
                    OutTimeValidator('monday_in')],
        widget=Input(input_type='time'))
    tuesday_in = TimeField(
        validators=[validators.optional(),
                    InTimeValidator('tuesday_out')],
        widget=Input(input_type='time'))
    tuesday_out = TimeField(
        validators=[validators.optional(),
                    OutTimeValidator('tuesday_in')],
        widget=Input(input_type='time'))
    wednesday_in = TimeField(
        validators=[validators.optional(),
                    InTimeValidator('wednesday_out')],
        widget=Input(input_type='time'))
    wednesday_out = TimeField(
        validators=[validators.optional(),
                    OutTimeValidator('wednesday_in')],
        widget=Input(input_type='time'))
    thursday_in = TimeField(
        validators=[validators.optional(),
                    InTimeValidator('thursday_out')],
        widget=Input(input_type='time'))
    thursday_out = TimeField(
        validators=[validators.optional(),
                    OutTimeValidator('thursday_in')],
        widget=Input(input_type='time'))
    friday_in = TimeField(
        validators=[validators.optional(),
                    InTimeValidator('friday_out')],
        widget=Input(input_type='time'))
    friday_out = TimeField(
        validators=[validators.optional(),
                    OutTimeValidator('friday_in')],
        widget=Input(input_type='time'))
    saturday_in = TimeField(
        validators=[validators.optional(),
                    InTimeValidator('saturday_out')],
        widget=Input(input_type='time'))
    saturday_out = TimeField(
        validators=[validators.optional(),
                    OutTimeValidator('saturday_in')],
        widget=Input(input_type='time'))