示例#1
0
 def handle_decimal_types(self, column, field_args, **extra):
     places = getattr(column.type, 'scale', 2)
     if places is not None:
         field_args['places'] = places
     return fields.DecimalField(**field_args)
示例#2
0
 def conv_Decimal(self, model, field, kwargs):
     self._number_common(model, field, kwargs)
     return f.DecimalField(**kwargs)
示例#3
0
class OneYearFeedbackForm(FlaskForm):
    numbers_only = 'Only use digits and (optionally) a decimal point, no other punctuation or symbols.'
    #recaptcha = RecaptchaField()
    householders_name = fields.StringField(
        'Householder\'s name*', validators=[DataRequired(),
                                            Length(max=50)])
    address = fields.StringField('Address*',
                                 validators=[DataRequired(),
                                             Length(max=100)])
    #annual_gas_kwh = fields.DecimalField('Annual consumption (kWh)',
    #                                     validators=[Optional()])
    #annual_gas_estimated = fields.BooleanField('(tick for yes) Is the value based on estimated use?',
    #                                           validators=[Optional()])
    #annual_gas_start_date = fields.DateField('Start date (dd/mm/yyyy)',
    #                                         format='%d/%m/%Y',
    #                                         validators=[Optional(),
    #                                         validate_date],
    #                                         widget=DatePickerWidget())
    #annual_gas_end_date = fields.DateField('End date (dd/mm/yyyy)',
    #                                       format='%d/%m/%Y',
    #                                       validators=[Optional(),
    #                                       validate_date],
    #                                       widget=DatePickerWidget())
    #annual_elec_kwh = fields.DecimalField('Annual consumption (kWh)',
    #                                      validators=[Optional()])
    #annual_elec_estimated = fields.BooleanField('(tick for yes) Is the value based on estimated use?',
    #                                            validators=[Optional()])
    #annual_elec_start_date = fields.DateField('Start date (dd/mm/yyyy)',
    #                                          format='%d/%m/%Y',
    #                                          validators=[Optional(),
    #                                          validate_date],
    #                                          widget=DatePickerWidget())
    #annual_elec_end_date = fields.DateField('End date (dd/mm/yyyy)',
    #                                        format='%d/%m/%Y',
    #                                        validators=[Optional(),
    #                                        validate_date],
    #                                        widget=DatePickerWidget())
    #annual_solid_spend = fields.DecimalField('Annual spend on solid fuels (£)',
    #                                         validators=[Optional()])
    #renewable_contrib_kwh = fields.DecimalField('Annual contribution from renewable generation (kWh)',
    #                                            validators=[Optional()])
    any_completed_actions = fields.BooleanField('(tick for yes) Have you taken action since your survey ' \
                                                +'to improve the thermal efficiency of your home?*',
                                                validators=[Optional()])
    diy_work = fields.TextAreaField(
        'What work have you done yourself?*',
        validators=[RequiredIf('any_completed_actions')])
    prof_work = fields.TextAreaField(
        'And, what work, if any, have you paid for to be done professionally?*',
        validators=[RequiredIf('any_completed_actions')])
    contractors_used = fields.TextAreaField(
        'If you had work done professionally, which contractors did you use?',
        description=
        'And were these contractors based in Bristol or from further afield?',
        validators=[Optional('any_completed_actions')])
    total_spent = fields.DecimalField(
        'Approximately how much have you spent in total on energy improvements to your home? (£)',
        description='Only answer this if you feel comfortable to.',
        validators=[Optional()])
    total_spent_diy = fields.DecimalField(
        'Approximately how much did you spend on DIY? (£)',
        validators=[Optional()])
    total_spent_local = fields.DecimalField(
        'Approximately how much did you spend on local contractors? (£)',
        validators=[Optional()])
    non_homeowner_work = fields.TextAreaField('If you are a low-income household or do not own your home, have you asked ' \
                                              +'the council, your housing association or your landlord to make any changes ' \
                                              +'to your home following the survey?  If so, what was their response?',
                                              validators=[Optional()])
    any_planned_work = fields.BooleanField(
        '(tick for yes) Do you have any future work planned?',
        validators=[Optional()])
    planned_work = fields.TextAreaField(
        'If so, what are you planning?*',
        validators=[RequiredIf('any_planned_work')])
    any_wellbeing_improvement = fields.BooleanField(
        '(tick for yes) Have the actions you\'ve taken made your house feel warmer?',
        validators=[Optional()])
    wellbeing_improvement = fields.TextAreaField(
        'If so, then how? (Even if perhaps you haven\'t saved money on your bills.)',
        validators=[RequiredIf('any_wellbeing_improvement')])
    any_behaviour_change = fields.BooleanField(
        '(tick for yes) Has your behaviour changed as a result of your survey?',
        validators=[Optional()])
    behaviour_temperature = fields.TextAreaField(
        'How has the period and temperature you use the heating for changed? (if at all)',
        validators=[RequiredIf('any_behaviour_change')])
    behaviour_space = fields.TextAreaField(
        'How do you use space in your home differently? (if at all)',
        validators=[RequiredIf('any_behaviour_change')])
    behaviour_changes = fields.TextAreaField(
        'In what other ways has your behaviour changed after the survey?',
        validators=[RequiredIf('any_behaviour_change')])
    feedback = fields.TextAreaField(
        'Lastly, do you have any other feedback on the CHEESE Project?',
        description='We would like to hear what you think about:' +
        ' how useful the survey was,' + ' your overall satisfaction,' +
        ' and anything else at all you would like to let us know.',
        validators=[Optional()])
示例#4
0
文件: form.py 项目: chrikin1/blog
 def handle_decimal_types(self, column, field_args, **extra):
     # override default decimal places limit, use database defaults instead
     field_args.setdefault('places', None)
     return fields.DecimalField(**field_args)
示例#5
0
 def conv_Decimal(self, model, field, kwargs):
     self._number_common(model, field, kwargs)
     kwargs["places"] = getattr(field, "precision", None)
     return f.DecimalField(**kwargs)
class PredictForm(FlaskForm):
    """Fields for Predict"""

    latitude = fields.DecimalField('Latitude:',
                                   places=2,
                                   validators=[Required()])
    longitude = fields.DecimalField('Longitude:',
                                    places=2,
                                    validators=[Required()])

    accommodates = SelectField('Accommodates:',
                               choices=[('0', '0'), ('1', '1'), ('2', '2'),
                                        ('3', '3'), ('4', '4'), ('5', '5'),
                                        ('6', '6'), ('7', '7'), ('8', '8'),
                                        ('9', '9'), ('10', '10'), ('11', '11'),
                                        ('12', '12'), ('13', '13'),
                                        ('14', '14'), ('15', '15'),
                                        ('16', '16')])

    bathrooms = SelectField('Bathrooms:',
                            choices=[('0', '0'), ('1', '1'), ('2', '2'),
                                     ('3', '3'), ('4', '4'), ('5', '5'),
                                     ('6', '6'), ('7', '7'), ('8', '8'),
                                     ('9', '9'), ('10', '10'), ('11', '11'),
                                     ('12', '12'), ('13', '13'), ('14', '14'),
                                     ('15', '15'), ('16', '16')])

    bedrooms = SelectField('Bedrooms:',
                           choices=[('0', '0'), ('1', '1'), ('2', '2'),
                                    ('3', '3'), ('4', '4'), ('5', '5'),
                                    ('6', '6'), ('7', '7'), ('8', '8'),
                                    ('9', '9'), ('10', '10'), ('11', '11'),
                                    ('12', '12'), ('13', '13'), ('14', '14')])

    beds = SelectField('Beds:',
                       choices=[('0', '0'), ('1', '1'), ('2', '2'), ('3', '3'),
                                ('4', '4'), ('5', '5'), ('6', '6'), ('7', '7'),
                                ('8', '8'), ('9', '9'), ('10', '10'),
                                ('11', '11'), ('12', '12'), ('13', '13'),
                                ('14', '14'), ('15', '15'), ('16', '16')])

    review_scores_mean = SelectField('Review Scores Mean:',
                                     choices=[
                                         ('0', '0'), ('1', '1'), ('2', '2'),
                                         ('3', '3'), ('4', '4'), ('5', '5'),
                                         ('6', '6'), ('7', '7'), ('8', '8'),
                                         ('9', '9'), ('10', '10')
                                     ])

    room_type = SelectField('Room Type:',
                            choices=[('1', 'Private room'),
                                     ('0', 'Entire home/apt'),
                                     ('2', 'Shared room')])

    property_type = SelectField('Property type:',
                                choices=[
                                    ('0', 'Aparthotel'), ('1', 'Apartment'),
                                    ('2', 'Bed and breakfast'), ('3', 'Boat'),
                                    ('4', 'Boutique hotel'), ('5', 'Bungalow'),
                                    ('6', 'Cabin'), ('7', 'Camper/RV'),
                                    ('8', 'Casa particular (Cuba)'),
                                    ('9', 'Castle'), ('10', 'Cave'),
                                    ('11', 'Chalet'), ('12', 'Condominium'),
                                    ('13', 'Cottage'), ('14', 'Earth house'),
                                    ('15', 'Guest suite'),
                                    ('16', 'Guesthouse'), ('17', 'Hostel'),
                                    ('18', 'Hotel'), ('19', 'House'),
                                    ('20', 'Houseboat'), ('21', 'Island'),
                                    ('22', 'Loft'), ('23', 'Nature lodge'),
                                    ('24', 'Other'), ('25', 'Resort'),
                                    ('26', 'Serviced apartment'),
                                    ('27', 'Tent'), ('28', 'Timeshare'),
                                    ('29', 'Tiny house'), ('30', 'Townhouse'),
                                    ('31', 'Train'), ('32', 'Villa')
                                ])

    submit = fields.SubmitField('Submit')
示例#7
0
class ReceiptItemForm(ModelForm):
    class Meta:
        model = ReceiptItem

    name = fields.StringField("Name", [va.length(min=1)])
    amount = fields.DecimalField("Decimal", [va.NumberRange(min=0)])
示例#8
0
class IncomeSourceForm(NoCsrfForm):
    source = fields.TextField(
        _('Source'), [Optional(), validators.Length(max=64)])
    monthly_amount = fields.DecimalField(_('Monthly amount'),
                                         validators=[Optional()])
示例#9
0
class FieldForm(Form):
    crop = fields.SelectField('Crop', choices=[('rye', 'Rye'), ('oats', 'Oats'), ('canola', 'Canola')])
    size = fields.DecimalField('Size in Acres', places=2)
    geo_data = fields.HiddenField(id='map_input')
示例#10
0
class CreateMatchFrom(Form):
    def __init__(self, *args, **kwargs):
        super(CreateMatchFrom, self).__init__(*args, **kwargs)

        obj = kwargs.get("obj", None)
        team = kwargs.get("team", None)

        if not isinstance(team, Team):
            raise AssertionError("must a team")

        if obj and obj.province:
            province = obj.province

        else:
            province = self.province.choices[0][0]

        if province:
            self.city.choices = ChinaCity.get_cities(province)

    title = f.StringField("比赛名称",
                          description="",
                          validators=[
                              validators.DataRequired(message="必填"),
                              validators.Length(1, 200, message="不能超过200字")
                          ])

    coverfile = FileField("封面",
                          description="建议尺寸:1045x464,仅支持格式:jpg、png, 不能超过10M",
                          validators=[
                              file_required(message="必填"),
                              file_allowed(("jpg", "png", "jpeg"),
                                           message="仅支持格式:jpg、png")
                          ])

    sport_id = ModelSelectField("运动类型", model=Sport, get_label="name")

    type = f.SelectField("比赛类型",
                         description="对战型如:足球、蓝球,非对战型:跑步、自行车",
                         validators=[
                             validators.DataRequired(message="必填"),
                         ],
                         choices=(('0', "对战型"), ('1', "非对战型")))

    province = f.SelectField("省份",
                             validators=[
                                 validators.DataRequired(message="必填"),
                             ],
                             choices=ChinaCity.get_provinces())

    city = WPSelectField("城市",
                         validators=[
                             validators.DataRequired(message="必填"),
                         ],
                         choices=[])

    address = f.StringField("详细地址",
                            description="非场地运动新填写集合地点",
                            validators=[
                                validators.DataRequired(message="必填"),
                            ])

    lat = f.HiddenField("lat")
    lng = f.HiddenField("lng")
    formatted_address = f.HiddenField("address_name")

    start_time = f.DateTimeField(
        "开始时间",
        description="赛事开始时间",
        validators=[validators.DataRequired(message="必填")])

    end_time = f.DateTimeField("结束时间",
                               validators=[
                                   validators.DataRequired(message="必填"),
                                   LaterThan("start_time", message="必须晚于开始时间")
                               ])

    join_start = f.DateTimeField("报名开始时间",
                                 description="限时开始报名,不填赛事上线即可报名",
                                 validators=[validators.Optional()])

    join_end = f.DateTimeField("报名截止时间",
                               description="不填则开始前均可报名",
                               validators=[
                                   validators.Optional(),
                                   BeforeThan("start_time",
                                              message="必须早于开始时间"),
                                   LaterThan("join_start",
                                             message="必须晚于报名开始时间")
                               ])

    contact_person = f.StringField("联系人",
                                   description="",
                                   validators=[
                                       validators.DataRequired(message="必填"),
                                       validators.Length(1,
                                                         200,
                                                         message="不能超过200字")
                                   ])

    contact_phone = f.StringField("联系电话",
                                  description="",
                                  validators=[
                                      validators.DataRequired(message="必填"),
                                      validators.Length(1,
                                                        200,
                                                        message="不能超过200字")
                                  ])

    description = f.TextAreaField(
        "简介",
        description="",
        validators=[validators.DataRequired(message="必填")])

    rules = f.TextAreaField("规程",
                            description="",
                            validators=[validators.DataRequired(message="必填")])

    reward = f.StringField("奖励",
                           description="奖励说明,如:冠军1000元,亚军500元",
                           validators=[
                               validators.Optional(),
                               validators.Length(0, 200, message="不能超过200字")
                           ])

    join_type = f.SelectField("报名类型",
                              validators=[
                                  validators.DataRequired(message="必填"),
                              ],
                              choices=(('0', "个人"), ('1', "团队")))

    refund_type = f.SelectField("退款策略",
                                validators=[
                                    validators.DataRequired(message="必填"),
                                ],
                                choices=(('0', "开始前可以退款"), ('1', "报名截止前可退"),
                                         ('2', "不能退款")))

    max_members = f.IntegerField("人数或团队限制",
                                 description="比赛人数或团队限制,报满则无法继续报名",
                                 default=15,
                                 validators=[
                                     validators.Optional(),
                                     validators.NumberRange(
                                         0, 20000, message="人数限制必须在2到20000人之间")
                                 ])

    price = f.DecimalField("报名费(元)",
                           description="设置分组后将以分组报名费为准",
                           validators=[validators.Optional()])

    group_type = f.SelectField("分组模式",
                               validators=[
                                   validators.DataRequired(message="必填"),
                               ],
                               choices=(('0', "非分组比赛"), ('1', "分组比赛")))

    groups = f.StringField("分组", validators=[validators.Optional()])
示例#11
0
class PaymentForm(Form):
    message = fields.StringField("Message",
                                 [va.length(min=1, max=MAX_MESSAGE_LENGTH)])
    amount = fields.DecimalField("Decimal", [va.NumberRange(min=0.01)])
    to_user = fields.FormField(UserSummaryForm)