Beispiel #1
0
class EditMatchFrom(CreateMatchFrom):

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

    type = f.SelectField("类型",
                         default="1",
                         choices=[
                             ("1", "赛事主办"),
                             ("0", "俱乐部"),
                         ])

    name = f.StringField("名称",
                         description="",
                         validators=[
                             validators.DataRequired(message="必填"),
                             validators.Length(2, 64)
                         ])

    iconfile = FileField(
        "微标",
        description="仅支持格式:jpg、png, 不能超过10M",
        validators=[
            # file_required(message="必填"),
            file_allowed(("jpg", "png", 'jpeg'), message="仅支持格式:jpg、png")
        ])

    sport = ModelSelectMultipleField("运动类型", model=Sport, get_label="name")

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

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

    description = f.TextAreaField("介绍",
                                  description="",
                                  validators=[
                                      validators.DataRequired(message="必填"),
                                      validators.Length(5, 2000)
                                  ])

    open_type = f.SelectField(
        "加入验证",
        choices=[
            ("0", "允许任何人加入"),
            ("1", "需要验证"),
            # ("2", "交会费加入"),
            ("3", "不允许任何人加入")
        ])
class ProfileFrom(Form):
    name = f.StringField("昵称",
                         description="",
                         validators=[
                             validators.DataRequired(message="必填项"),
                             validators.Length(2, 32, message="长度不能少于两位")
                         ])

    gender = f.SelectField("性别", choices=[("m", "男"), ("f", "女")])

    avatarfile = FileField(
        "头像",
        description="仅支持格式:jpg、png, 不能超过10M",
        validators=[file_allowed(('jpg', "png", "jpeg"), message="格式不支持")])
def convert_text_to_file(form_cls, model_cls, field_names_list):
    """
    将 form 中指定的 field 转化为 file 类型的
    自动生成的时候顺序会发生改变
    """
    for field_name in field_names_list:
        model_field = getattr(model_cls, field_name, None)
        file_field = FileField(model_field.verbose_name,
                               description=model_field.help_text,
                               validators=[
                                   file_allowed(("jpg", "png", 'jpeg'),
                                                message="仅支持格式:jpg、png")
                               ])
        setattr(form_cls, field_name, file_field)
Beispiel #5
0
class CreateCoverForm(Form):

    position = f.SelectField("显示位置",
                             validators=[
                                 validators.DataRequired(message="必填"),
                             ],
                             choices=(('description', "赛事详情"),
                                      ('rules', '赛事规程'), ('rounds', '赛事赛程')))

    coverfile = FileField("海报",
                          description="建议尺寸:1125x500, 支持格式:jpg、png, 不能超过20M",
                          validators=[
                              file_required(message="必填"),
                              file_allowed(("jpg", "png", "jpeg"),
                                           message="仅支持格式:jpg、png")
                          ])
Beispiel #6
0
class CreateActivityFrom(Form):
    def __init__(self, *args, **kwargs):
        super(CreateActivityFrom, 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)

        leaders = team.get_members(role="leader")
        leaders.insert(0, User.get_or_none(id=team.owner_id))

        if leaders:
            self.leader.choices = [(str(user.id), user.name or user.mobile)
                                   for user in leaders]

        groups = team.groups
        if groups:
            self.allow_groups.choices = [(str(group.id), group.name)
                                         for group in groups]

    title = f.StringField("活动标题",
                          description="",
                          validators=[
                              validators.DataRequired(message="必填"),
                              validators.Length(2, 32)
                          ])

    cover = FileField("活动图片",
                      description="仅支持格式:jpg、png, 不能超过2M",
                      validators=[
                          file_allowed(("jpg", "png", "jpeg"),
                                       message="仅支持格式:jpg、png")
                      ])

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

    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="必须晚于活动开始时间")
                               ])

    repeat_type = f.SelectField(
        "循环活动",
        description="活动结算后系统自动生成下期活动",
        choices=[
            ("", "不循环"),
            #  ("day", "每天"),
            ("week", "每周"),
            #  ("month", "每月")
        ])

    repeat_end = f.DateTimeField("结束循环",
                                 description="超过此时间活动将不能自动循环",
                                 validators=[
                                     validators.Optional(),
                                     LaterThan("start_time",
                                               message="必须晚于活动开始时间")
                                 ])

    join_end = f.DateTimeField("报名截止时间",
                               description="",
                               validators=[validators.Optional()])

    description = f.TextAreaField("活动说明",
                                  description="",
                                  validators=[
                                      validators.DataRequired(message="必填"),
                                      validators.Length(1,
                                                        5000,
                                                        message="不能超过5000字")
                                  ])

    max_members = f.IntegerField("人数限制",
                                 description="活动限制人数",
                                 default=15,
                                 validators=[
                                     validators.Optional(),
                                     validators.NumberRange(
                                         2, 20000, message="人数限制必须在2到20000人之间")
                                 ])

    allow_agents = f.IntegerField("允许代报人数",
                                  description="代报人数不包含报名人自己",
                                  default=0,
                                  validators=[
                                      validators.Optional(),
                                      validators.NumberRange(
                                          0,
                                          200,
                                          message="允许代报人数限制必须在0到200人之间")
                                  ])

    payment_type = f.SelectField(
        "支付方式",
        default="",
        choices=[("0", "在线支付"), ("1", "线下支付")],
        validators=[validators.DataRequired(message="必填")])

    price = f.DecimalField("价格(人/次)", description="")
    # female_price = f.DecimalField("女成员价格")
    vip_price = f.DecimalField("VIP价格(人/次)", description="VIP会员专享价格")

    allow_free_times = f.BooleanField("允许使用次卡")

    visible = f.SelectField("允许报名",
                            default="",
                            choices=[("0", "所有人"), ("1", "仅成员")],
                            validators=[validators.Optional()])

    allow_groups = f.SelectMultipleField("允许分组",
                                         default="",
                                         description="例如:限制只能高级组会员可以报名,默认不限",
                                         choices=[],
                                         validators=[validators.Optional()])

    leader = f.SelectField("组织者", choices=[])

    need_fields = f.SelectMultipleField(
        "需要填写的报名信息",
        description="您希望报名人员填写哪些信息",
        default=['need_nickname', 'need_gender', 'need_mobile'],
        choices=[("need_nickname", "昵称"), ("need_mobile", "手机"),
                 ("need_gender", "性别"), ("need_name", "姓名"),
                 ("need_identification", "身份证明"),
                 ("need_emergency_contact", "紧急联系人")])

    need_ext1_name = f.StringField("信息名称", description="不需要请留空")
    need_ext1_type = f.SelectField("类型",
                                   choices=(('text', '文本'), ('photo', '照片')))

    need_ext2_name = f.StringField("信息名称")
    need_ext2_type = f.SelectField("类型",
                                   choices=(('text', '文本'), ('photo', '照片')))

    need_ext3_name = f.StringField("信息名称")
    need_ext3_type = f.SelectField("类型",
                                   choices=(('text', '文本'), ('photo', '照片')))
Beispiel #7
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()])
Beispiel #8
0
class TeamBasicFrom(Form):

    name = f.StringField("名称",
                         description="俱乐部或赛事主办机构名称",
                         validators=[
                             validators.DataRequired(message="必填项"),
                             validators.Length(2, 64)
                         ])

    iconfile = FileField("徽标",
                         description="仅支持格式:jpg、png, 不能超过10M",
                         validators=[
                             file_allowed(("jpg", "png", "jpeg"),
                                          message="仅支持格式:jpg、png")
                         ])

    sport = ModelSelectMultipleField("运动类型",
                                     model=Sport,
                                     get_label="name"
                                     )

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

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

    address = f.StringField("联系地址",
                            description="",
                            validators=[
                                validators.Optional(),
                                validators.Length(3, 128)
                            ])

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

    contact_person = f.StringField("联系人",
                                   description="",
                                   validators=[
                                       validators.Optional(),
                                       validators.Length(2, 32)
                                   ])

    contact_phone = f.StringField("联系电话",
                                  description="",
                                  validators=[
                                      validators.Optional(),
                                      validators.Length(3, 32)
                                  ])

    description = f.TextAreaField("介绍",
                                  description="",
                                  validators=[
                                      validators.DataRequired(message="必填"),
                                      validators.Length(5, 2000)
                                  ])