예제 #1
0
class HomeInputForm(form.Form):
    majors =fields.SelectMultipleField(label="majors", validators=[validators.DataRequired()])
    specs =fields.SelectMultipleField(label="specs")
    firstQuarter = fields.SelectField(label="start quarter for scheduling", default=(0,0))
    quarterCreditDefault = fields.SelectField(label="default maximum credits per quarter" ,validators=[validators.DataRequired()],
                                choices=[(x,x) for x in range(30)], default=(16,16))
    quarterCredits = fields.FieldList(fields.FormField(QuarterCreditForm),
                                      label="maximum credits per quarter", validators=[validators.Optional()],
                                      min_entries=1, max_entries=15)
    next = fields.SubmitField('next')


    def validate_on_submit(self):
        """
        Checks if form has been submitted and if so runs validate. This is
        a shortcut, equivalent to ``form.is_submitted() and form.validate()``
        """
        return self.is_submitted() and self.validate()

    def is_submitted(self):
        """
        Checks if form has been submitted. The default case is if the HTTP
        method is **POST**.
        """
        return request and request.method == "POST"
예제 #2
0
class FixedBannerForm(form.Form):
    name = fields.StringField(u"banner名称", [validators.Required()])
    image = fields.StringField(u"banner图片", [validators.Required()])
    url = fields.StringField(u"跳转链接", [validators.Required()])
    status = fields.SelectField(u"状态", [validators.InputRequired()],
                                coerce=int,
                                choices=FB_STATUS)
    begin_at = TimeStampField(u'开始时间', [validators.Required()])
    expire_at = TimeStampField(u'结束时间', [validators.Required()])
    os = fields.SelectField(u'平台要求', [validators.InputRequired()],
                            choices=[('android', 'Android'), ('ios', 'IOS')],
                            default='Android')
    login = fields.SelectField(u'登录要求', [validators.InputRequired()],
                               choices=[('all', u'全部'), ('login', u'登录')],
                               default='login')
    channels = fields.SelectMultipleField(u'推广渠道', [validators.Optional()])
    group = fields.SelectField(u'用户组', coerce=ObjectId)
    version_code_mix = fields.SelectField(u'版本要求(版本号大于等于)',
                                          [validators.Optional()],
                                          coerce=int)
    version_code_max = fields.SelectField(u'版本要求(版本号小于等于)',
                                          [validators.Optional()],
                                          coerce=int)
    province = fields.SelectMultipleField(u'省份', [validators.Optional()])
    position = fields.SelectField(u"显示位置", [validators.InputRequired()],
                                  coerce=int,
                                  choices=FB_POSITION)
예제 #3
0
class PopupForm(form.Form):
    image = fields.StringField(u'图片', [validators.Required()])
    image_link = fields.StringField(u'图片链接', [validators.Required()])
    image_link_type = fields.SelectField(u'图片链接类型',
                                         [validators.InputRequired()],
                                         choices=[('app', u'app内'),
                                                  ('app_h5', u'H5页面'),
                                                  ('h5', u'外部H5页面')],
                                         default='app')
    begin_at = TimeStampField(u'开始时间', [validators.Required()])
    expire_at = TimeStampField(u'结束时间', [validators.Required()])
    login = fields.SelectField(u'登录要求', [validators.InputRequired()],
                               choices=[('all', u'全部'), ('login', u'登录')],
                               default='login')
    os = fields.SelectField(u'平台要求', [validators.InputRequired()],
                            choices=[('android', 'Android'), ('ios', 'IOS')],
                            default='Android')
    channels = fields.SelectMultipleField(u'推广渠道', [validators.Optional()])
    push_begin_at = HourStampField(u'推送开始时段')
    push_expire_at = HourStampField(u'推送结束时段')
    button_text = fields.StringField(u'按钮文字', [validators.Required()])
    button_link = fields.StringField(u'按钮链接', [validators.Required()])
    show_button = fields.BooleanField(u'是否显示按钮', default=False)
    group = fields.SelectField(u'用户组', coerce=ObjectId)
    province = fields.SelectMultipleField(u'省份', [validators.Optional()])

    version_code_mix = fields.SelectField(u'版本要求(版本号大于等于)',
                                          [validators.Optional()],
                                          coerce=int)
    version_code_max = fields.SelectField(u'版本要求(版本号小于等于)',
                                          [validators.Optional()],
                                          coerce=int)
예제 #4
0
class WatchLiveTaskForm(form.Form):
    name = fields.StringField(u'活动标题', [validators.DataRequired()])
    status = fields.SelectField(u'状态',
                                [validators.InputRequired()],
                                coerce=int,
                                choices=[
                                    (const.ONLINE, u'在线'),
                                    (const.OFFLINE, u'下线')
                                ])
    begin_at = TimeStampField(u'开始时间', [validators.DataRequired()])
    expire_at = TimeStampField(u'结束时间', [validators.DataRequired()])
    duration = fields.IntegerField(u'观看时长要求\n单位:分钟', [validators.InputRequired()], default=5)
    chance = fields.IntegerField(u'每日上限次数', [validators.InputRequired()], default=3)
    icon = fields.StringField(u'按钮图标', [validators.DataRequired()])
    os = fields.SelectField(u'平台要求', [validators.InputRequired()],
                            choices=[
                                ('all', u'全部'),
                                ('android', u'Android'),
                                ('ios', u'IOS')], default=u'全部')
    channels = fields.SelectMultipleField(u'推广渠道', [validators.Optional()])
    group = fields.SelectField(u'用户组', coerce=ObjectId)
    version_code_mix = fields.SelectField(u'版本要求(版本号大于等于)', [validators.Optional()],
                                          coerce=int)
    version_code_max = fields.SelectField(u'版本要求(版本号小于等于)', [validators.Optional()],
                                          coerce=int)
    province = fields.SelectMultipleField(u'省份', [validators.Optional()])
    campaign_id = fields.StringField(u'营销平台活动ID', [validators.InputRequired()])
예제 #5
0
class EditAdminForm(Form):
    newpassword = f.PasswordField(
        "登录密码",
        description="不修改密码请留空",
        validators=[validators.Optional(),
                    validators.Length(5, 32)])

    name = f.StringField("名字",
                         validators=[validators.DataRequired(message="不能为空")])

    mobile = f.StringField("手机", validators=[validators.Optional()])

    email = f.StringField(
        "电子邮箱",
        validators=[validators.Optional(),
                    validators.Email(message="格式不正确")])

    is_super = f.BooleanField("超级管理员")
    roles = f.SelectMultipleField("权限", choices=Admin.ROLES)

    state = f.SelectField("是否启用", choices=[
        ("1", "启用"),
        ("0", "禁用"),
    ])

    manage_provinces = f.SelectMultipleField("管辖省份",
                                             choices=ChinaCity.get_provinces())

    def validate_mobile(self, field):
        if not is_mobile(field.data):
            raise ValidationError('手机号码格式不正确')
예제 #6
0
파일: admin.py 프로젝트: FreeGodCode/social
class RolesForm(form.Form):
    """角色管理表单类"""
    name = fields.StringField('角色名', validators=[DataRequired('角色名不能为空')])
    permissions = fields.SelectMultipleField(
        '权限',
        widget=Select2Widget(multiple=True),
        validators=[DataRequired('权限不能为空')])
예제 #7
0
class SearchForm(Form):
    
    date_choice = fields.SelectField(u"Quelle date",
                                     default="received",
                                    choices=(('sent', u"Date d'envoi"), ('received', u"Date de réception") )
                                    )
    
    start_date = fields.DateField(u"Du : ",
                                  format='%d/%m/%Y',
                                  #widget=BootstrapDatePickerWidget(),
                                  validators=[validators.Optional()])
    
    end_date = fields.DateField(u"Au : ",
                                format='%d/%m/%Y',
                                #widget=BootstrapDatePickerWidget(),
                                validators=[validators.Optional()])
    
    sender = fields.StringField(label=u"Expéditeur")

    rcpt = fields.StringField(label=u"Destinataire")
    
    subject = fields.StringField(label=u"Sujet")

    client_address = fields.StringField(label=u"Adresse IP")
    
    country = fields.SelectMultipleField(label=u"Pays",
                                 #choices=[('',u"Choisissez un pays")] + list(countries.COUNTRIES),
                                 choices=countries.COUNTRIES,
                                 validators=[validators.Optional()])
    
    queue = fields.SelectField(label=u"Queue",
                               coerce=int,
                               choices=constants.MESSAGE_QUEUE_CHOICES,
                               validators=[validators.Optional()])
예제 #8
0
    def convert(self, model, field, field_args):
        kwargs = {
            'label': getattr(field, 'verbose_name', field.name),
            'description': field.help_text or '',
            'validators': getattr(field, 'validators', None) or [],
            'filters': getattr(field, 'filters', None) or [],
            'default': field.default,
        }
        if field_args:
            kwargs.update(field_args)

        if field.required:
            kwargs['validators'].append(validators.Required())
        else:
            kwargs['validators'].append(validators.Optional())

        ftype = type(field).__name__

        if field.choices:
            kwargs['choices'] = field.choices

            if ftype in self.converters:
                kwargs["coerce"] = self.coerce(ftype)
            if kwargs.pop('multiple', False):
                return f.SelectMultipleField(**kwargs)
            return f.SelectField(**kwargs)

        ftype = type(field).__name__

        if hasattr(field, 'to_form_field'):
            return field.to_form_field(model, kwargs)

        if ftype in self.converters:
            return self.converters[ftype](model, field, kwargs)
예제 #9
0
class JobDelUserForm(Form):
    yml_temp_name = fields.TextField('Template Name',
                                     [validators.InputRequired()])
    selected_alias = fields.SelectMultipleField('Select Group / Host',
                                                [validators.InputRequired()])
    remote_user = fields.TextField('Remote User', [validators.InputRequired()])
    username = fields.TextField('Username', [validators.InputRequired()])
class AdminCustomFieldEditForm(CustomFieldEditForm):

    label = ModelFormField(AdminCustomFieldLabelInputForm, label='Field label')
    meeting_type_slugs = fields.SelectMultipleField('Meeting types')

    def __init__(self, *args, **kwargs):
        super(AdminCustomFieldEditForm, self).__init__(*args, **kwargs)
        self.meeting_type_slugs.choices = [
            (m.slug, m.label) for m in MeetingType.query.ignore_def()
        ]
        if self.obj and self.meeting_type_slugs.data is None:
            self.meeting_type_slugs.data = [
                m.slug for m in self.obj.meeting_types
            ]

    def save(self):
        custom_field = self.obj or CustomField()
        self.populate_obj(custom_field)
        custom_field.meeting_types = MeetingType.query.filter(
            MeetingType.slug.in_(self.meeting_type_slugs.data)).all()

        db.session.commit()
        if not custom_field.id:
            last_sort = (CustomField.query.with_entities(
                CustomField.sort).order_by(desc(CustomField.sort)).first())
            if last_sort:
                custom_field.sort = last_sort[0] + 1
            db.session.add(custom_field)
        db.session.commit()
예제 #11
0
class AddPageForm(Form):
    date_added = fields.DateField('Publish On:',format="%m-%d-%Y",widget=DateWidget())
    date_end = fields.DateField('Expire On:',format="%m-%d-%Y",validators=[validators.Optional()],widget=DateWidget())
    name = fields.StringField('Page Name',validators=[validators.InputRequired()])
    description = fields.TextAreaField('Description',validators=[validators.Optional()])
    slug = fields.StringField('Page Slug',validators=[validators.InputRequired()])
    short_url = fields.StringField('Url',validators=[validators.Optional()])
    title = fields.StringField('Page Title',validators=[validators.InputRequired()])
    add_to_nav = fields.BooleanField('Add to Navbar')
    add_sidebar = fields.BooleanField('Add Sidebar')
    visible = fields.SelectField(choices=((1,'Publish'),(0,'Draft')))
    meta_title = fields.StringField('Meta Title',validators=[validators.InputRequired()])
    content = CodeMirrorField('Content',language='xml',config={'lineNumbers':'true'})
    template = fields.FormField(BaseTemplateForm,label="Template",separator='_')
    blocks = fields.SelectMultipleField(label="blocks",choices=[('a','a'),('b','b'),('c','c')])
    category = QuerySelectField('category')
    tags = TagField('Tags')
    use_base_template = fields.BooleanField('Use Base Template')
    base_template =  fields.SelectField(
                        'base template',validators=[
                            validators.InputRequired()
                        ],choices=[
                            (x,x) for x in sorted(get_page_templates()) \
                            if not x.startswith('_') and not \
                            x.startswith('.') and x.endswith('.html')
                        ]
    )
    submit = fields.SubmitField('Save')
예제 #12
0
class GameForm(form.Form):
    name = fields.StringField(u'游戏名', [validators.Required()])
    url = fields.StringField(u'Android下载链接', [validators.Optional()])
    url_ios = fields.StringField(u'IOS跳转链接', [validators.Optional()])
    description = fields.TextAreaField(u'描述', [validators.Required()])
    intro = fields.StringField(u'简介', [validators.Optional()])
    slogan = fields.StringField(u'标语', [validators.Optional()])
    developer = fields.StringField(u'开发者', [validators.Required()])
    package_id = fields.StringField(u'软件包ID', [validators.Required()])
    package_segment = fields.StringField(u'主播工具匹配包名特征',
                                         [validators.Optional()])
    bid = fields.StringField(u'咪咕平台游戏ID', [validators.Optional()])
    bcode = fields.StringField(u'咪咕平台CODE', [validators.Optional()])
    version = fields.StringField(u'版本号', [validators.Required()])
    size = fields.FloatField(u'包大小(M)', [validators.Required()], default=0.0)
    contain_sdk = fields.BooleanField(u'是否包含SDK', default=False)
    cover = fields.StringField(u'封面图片', [validators.Required()])
    icon = fields.StringField(u'图标', [validators.Required()])
    big_icon = fields.StringField(u'大图标', [validators.Required()])
    status = fields.SelectField(u'状态', [validators.InputRequired()],
                                coerce=int,
                                choices=[(const.ONLINE, u'上架'),
                                         (const.OFFLINE, u'下线'),
                                         (const.UNDER_TEST, u'测试'),
                                         (const.OFFSHELF, u'非上架')])
    migu = JsonField(u'咪咕信息', [validators.Optional()])
    is_download = fields.BooleanField(u'是否可下载(Android)', default=False)
    is_subscribe = fields.BooleanField(u'是否可订阅(Android)', default=False)
    is_download_ios = fields.BooleanField(u'是否可下载(IOS)', default=False)
    is_subscribe_ios = fields.BooleanField(u'是否可订阅(IOS)', default=False)
    on_assistant = fields.BooleanField(u'是否在游玩助手上架', default=True)
    categories = fields.SelectMultipleField(u'分类', [validators.Optional()],
                                            coerce=ObjectId)
예제 #13
0
    def convert(self, model, field, field_args, multiple=False):
        kwargs = {
            'label': unicode(field.verbose_name or field.name or ''),
            'description': field.help_text or '',
            'validators': [],
            'filters': [],
            'default': field.default,
        }
        if field_args:
            kwargs.update(field_args)

        if field.required:
            kwargs['validators'].append(validators.Required())

        if field.choices:
            kwargs['choices'] = field.choices
            if isinstance(field, IntField):
                kwargs['coerce'] = int
            if not multiple:
                return f.SelectField(**kwargs)
            else:
                return f.SelectMultipleField(**kwargs)
        ftype = type(field).__name__

        if hasattr(field, 'to_form_field'):
            return field.to_form_field(model, kwargs)

        if ftype in self.converters:
            return self.converters[ftype](model, field, kwargs)
class CategoryDefaultEditForm(CategoryEditBaseForm):

    title = ModelFormField(DefaultCategoryTitleInputForm, label='Title')
    meeting_type_slugs = fields.SelectMultipleField('Meeting types')

    def __init__(self, *args, **kwargs):
        super(CategoryDefaultEditForm, self).__init__(*args, **kwargs)
        self.meeting_type_slugs.choices = [
            (m.slug, m.label) for m in MeetingType.query.ignore_def()
        ]
        if self.obj and self.meeting_type_slugs.data is None:
            self.meeting_type_slugs.data = [
                m.slug for m in self.obj.meeting_types
            ]

    class Meta:
        model = CategoryDefault

    def save(self):
        category = super(CategoryDefaultEditForm, self).save()
        category.meeting_types = MeetingType.query.filter(
            MeetingType.slug.in_(self.meeting_type_slugs.data)).all()

        db.session.commit()
        return category
예제 #15
0
class JobPhpForm(Form):
    yml_temp_name = fields.TextField('Template Name',
                                     [validators.InputRequired()])
    selected_alias = fields.SelectMultipleField('Select Group / Host',
                                                [validators.InputRequired()])
    remote_user = fields.TextField('Remote User', [validators.InputRequired()])
    mysql_data_dir = fields.TextField('MySQL Data Dir',
                                      [validators.InputRequired()])
예제 #16
0
class JobAddUserByPubkeyForm(Form):
    yml_temp_name = fields.TextField('Template Name',
                                     [validators.InputRequired()])
    selected_alias = fields.SelectMultipleField('Select Group / Host',
                                                [validators.InputRequired()])
    remote_user = fields.TextField('Remote User', [validators.InputRequired()])
    username = fields.TextField('Username', [validators.InputRequired()])
    #key = fields.TextAreaField('Key', [validators.InputRequired()])
    key = fields.SelectField('Key', [validators.InputRequired()])
예제 #17
0
class CategoryTagForm(BaseForm):

    category_tags = fields.SelectMultipleField()

    def __init__(self, *args, **kwargs):
        super(CategoryTagForm, self).__init__(*args, **kwargs)
        category_tags_query = CategoryTag.query.order_by(CategoryTag.label)
        self.category_tags.choices = [(tag.id, tag.label)
                                      for tag in category_tags_query]
예제 #18
0
class EventsForm(BaseForm):

    events = fields.SelectMultipleField()

    def __init__(self, *args, **kwargs):
        super(EventsForm, self).__init__(*args, **kwargs)
        events = g.meeting.custom_fields.filter_by(
            field_type=CustomField.EVENT)
        self.events.choices = [(e.id, e.label) for e in events]
예제 #19
0
class CourseForm(FlaskForm):
    name = fields.StringField(
        'Name',
        validators=[validators.InputRequired(),
                    validators.Length(min=3)])
    description = fields.StringField('Description',
                                     validators=[validators.InputRequired()],
                                     widget=widgets.TextArea())
    languages = fields.SelectMultipleField(
        'Languages',
        validators=[validators.InputRequired()],
    )
    contributors = fields.SelectMultipleField('Contributors')

    tags = TagListField(
        'Tags',
        validators=[validators.InputRequired(),
                    validators.Length(min=3)])
예제 #20
0
class FilterResults(FlaskForm):
    """ Search results filtering by stops and areas. """
    class Meta(object):
        """ Disable CSRF as this form uses GET. """
        csrf = False

    group = fields.SelectMultipleField("group")
    area = fields.SelectMultipleField("area")
    page = fields.IntegerField("page", default=1)

    def add_choices(self, groups, areas):
        """ Populate with available choices and selected by arguments passed
            after the form is instantiated.

            :param groups: Dict with groups to select.
            :param areas: Dict with admin areas to select.
        """
        self.group.choices = sorted(groups.items(), key=lambda g: g[1])
        self.area.choices = sorted(areas.items(), key=lambda a: a[1])
예제 #21
0
class MediaCategoriesForm(BaseForm):

    categories = fields.SelectMultipleField()
    flag = fields.SelectField()

    def __init__(self, *args, **kwargs):
        super(MediaCategoriesForm, self).__init__(*args, **kwargs)
        categories = Category.query.filter_by(meeting=g.meeting,
                                              category_type=Category.MEDIA)
        self.categories.choices = [(c.id, c.title) for c in categories]
예제 #22
0
class OAuthTokenForm(AdsWSBaseForm):
    name = fields.TextField(
        description="Name of personal access token.",
        validators=[validators.Required()],
    )
    scopes = fields.SelectMultipleField(
        widget=scopes_multi_checkbox,
        choices=[],  # Must be dynamically provided in view.
        description="Scopes assigns permissions to your personal access token."
        " A personal access token works just like a normal OAuth "
        " access token for authentication against the API.")
예제 #23
0
class ParticipantCategoriesForm(BaseForm):

    categories = fields.SelectMultipleField()
    flag = fields.SelectField()

    def __init__(self, *args, **kwargs):
        super(ParticipantCategoriesForm, self).__init__(*args, **kwargs)
        categories = (Category.query.filter_by(
            meeting=g.meeting,
            category_type=Category.PARTICIPANT).order_by(Category.sort))
        self.categories.choices = [(c.id, c.title) for c in categories]
예제 #24
0
class ConditionForm(BaseForm):

    CHECKBOX_VALUES = [('true', 'True'), ('false', 'False')]

    field = fields.SelectField('Field', coerce=int)
    values = fields.SelectMultipleField('Values', [DataRequired()], choices=[])

    def __init__(self, *args, **kwargs):
        super(ConditionForm, self).__init__(*args, **kwargs)
        query = (CustomField.query.filter_by(
            meeting_id=g.meeting.id).filter_by(
                custom_field_type=g.rule_type).filter(
                    CustomField.field_type.in_([
                        CustomField.CATEGORY, CustomField.COUNTRY,
                        CustomField.RADIO, CustomField.CHECKBOX,
                        CustomField.SELECT
                    ])).filter_by(visible_on_registration_form=True).order_by(
                        CustomField.sort))
        self.field.choices = [(c.id, c) for c in query]

        self.cf = None
        if self.field.data:
            self.cf = (CustomField.query.filter_by(id=int(self.field.data),
                                                   meeting=g.meeting).one())
            dispatch = {
                CustomField.CATEGORY: self._get_query_for_category,
                CustomField.COUNTRY: self._get_query_for_countries,
                CustomField.CHECKBOX: self._get_query_for_checkbox,
                CustomField.SELECT: self._get_query_for_select,
                CustomField.RADIO: self._get_query_for_select,
            }
            self.values.choices = dispatch[self.cf.field_type.code]()

    def _get_query_for_category(self):
        query = Category.get_categories_for_meeting(g.rule_type)
        return [(str(c.id), unicode(c)) for c in query]

    def _get_query_for_countries(self):
        return get_all_countries()

    def _get_query_for_checkbox(self):
        return self.CHECKBOX_VALUES

    def _get_query_for_select(self):
        return [(unicode(i), unicode(i)) for i in self.cf.choices.all()]

    def save(self, rule):
        condition = Condition(rule=rule, field=self.cf)
        db.session.add(condition)
        db.session.flush()
        for value in self.values.data:
            condition_value = ConditionValue(condition=condition, value=value)
            db.session.add(condition_value)
예제 #25
0
    def convert(self, model, prop, field_args):
        """
        Returns a form field for a single model property.

        :param model:
            The ``db.Model`` class that contains the property.
        :param prop:
            The model property: a ``db.Property`` instance.
        :param field_args:
            Optional keyword arguments to construct the field.
        """

        prop_type_name = type(prop).__name__

        # check for generic property
        if (prop_type_name == "GenericProperty"):
            # try to get type from field args
            generic_type = field_args.get("type") if field_args else None

            if generic_type:
                prop_type_name = field_args.get("type")
            # if no type is found, the generic property uses string set in
            # convert_GenericProperty

        kwargs = {
            'label': (prop._verbose_name
                      or prop._code_name.replace('_', ' ').title()),
            'default':
            prop._default,
            'validators': [],
        }
        if field_args:
            kwargs.update(field_args)

        if prop._required and prop_type_name not in self.NO_AUTO_REQUIRED:
            kwargs['validators'].append(validators.DataRequired())

        choices = kwargs.get('choices', None) or prop._choices
        if choices:
            # Use choices in a select field.
            kwargs['choices'] = [(v, v) for v in choices]
            if prop._repeated:
                return f.SelectMultipleField(**kwargs)
            else:
                return f.SelectField(**kwargs)

        else:
            converter = self.converters.get(prop_type_name, None)
            if converter is not None:
                return converter(model, prop, kwargs)
            else:
                return self.fallback_converter(model, prop, kwargs)
예제 #26
0
class BadgeCategories(BaseForm):

    categories = fields.SelectMultipleField()
    flag = fields.SelectField()

    def __init__(self, *args, **kwargs):
        super(BadgeCategories, self).__init__(*args, **kwargs)
        categories = Category.query.filter_by(
            meeting=g.meeting, category_type=Category.PARTICIPANT)
        self.categories.choices = [(c.id, c.title) for c in categories]
        flags = g.meeting.custom_fields.filter_by(
            field_type=CustomField.CHECKBOX, is_primary=True)
        self.flag.choices = [('', '---')] + [(f.slug, f.label) for f in flags]
예제 #27
0
class VideoForm(form.Form):
    author = ObjectIdField(u'创建用户', [validators.Required()])
    url = fields.StringField(u'链接', [validators.Required()])
    title = fields.StringField(u'标题', [validators.Required()])
    cover = fields.StringField(u'背景图', [validators.Required()])
    game = ObjectIdField(u'所属游戏', [validators.Required()])
    ratio = fields.StringField(u'分辨率(宽x高)', [validators.Required()])
    duration = fields.IntegerField(u'视频时长(秒)', [validators.InputRequired()])
    vv = fields.IntegerField(u'播放次数', [validators.InputRequired()], default=0)
    release_time = TimeStampField(u'发布精华时间', [validators.Optional()])
    status = fields.SelectField(u'状态', [validators.InputRequired()], coerce=int,
                                choices=[
                                    (const.ONLINE, u'在线'),
                                    (const.OFFLINE, u'下线'),
                                    (const.ELITE, u'精选'),
                                    (const.UPLOADING, u'上传中')],
                                default=const.ONLINE
                                )
    categories = fields.SelectMultipleField(u'分类', [validators.Optional()],
                                            coerce=ObjectId)
    topics = fields.SelectMultipleField(u'专题', [validators.Optional()],
                                            coerce=ObjectId)
예제 #28
0
파일: form.py 프로젝트: Andrew59-boop/blog
    def convert(self, model, field, field_args):
        # Check if it is overridden field
        if isinstance(field, FieldPlaceholder):
            return form.recreate_field(field.field)

        kwargs = {
            'label': getattr(field, 'verbose_name', None),
            'description': getattr(field, 'help_text', ''),
            'validators': [],
            'filters': [],
            'default': field.default
        }

        if field_args:
            kwargs.update(field_args)

        if kwargs['validators']:
            # Create a copy of the list since we will be modifying it.
            kwargs['validators'] = list(kwargs['validators'])

        if field.required:
            if isinstance(field, ListField):
                kwargs['validators'].append(FieldListInputRequired())
            else:
                kwargs['validators'].append(validators.InputRequired())
        elif not isinstance(field, ListField):
            kwargs['validators'].append(validators.Optional())

        ftype = type(field).__name__

        if field.choices:
            kwargs['choices'] = list(self._convert_choices(field.choices))

            if ftype in self.converters:
                kwargs["coerce"] = self.coerce(ftype)
            if kwargs.pop('multiple', False):
                return fields.SelectMultipleField(**kwargs)
            return fields.SelectField(**kwargs)

        ftype = type(field).__name__

        if hasattr(field, 'to_form_field'):
            return field.to_form_field(model, kwargs)

        override = self._get_field_override(field.name)
        if override:
            return override(**kwargs)

        if ftype in self.converters:
            return self.converters[ftype](model, field, kwargs)
예제 #29
0
class UsersForm(form.Form):
    email = fields.StringField('用户邮箱', validators=[DataRequired('邮箱不能为空'), Email('邮箱格式不正确')])
    username = fields.StringField('昵称', validators=[DataRequired('昵称不能为空')])
    is_active = fields.BooleanField('激活状态')
    is_disabled = fields.BooleanField('禁用')
    is_admin = fields.BooleanField('超级管理员')
    vip = fields.IntegerField('VIP等级')
    avatar = fields.StringField('头像')
    coin = fields.IntegerField('金币')
    description = fields.TextAreaField('签名')
    city = fields.StringField('城市')
    renzheng = fields.StringField('认证信息')
    role_ids = fields.SelectMultipleField('角色', widget=Select2Widget(multiple=True))
    form_columns = ('email', 'username', 'is_active', 'is_admin', 'avatar', 'coin', 'description', 'city')
예제 #30
0
class TokenForm(Form):
    """Token form."""

    name = fields.StringField(
        description=_('Name of personal access token.'),
        validators=[validators.DataRequired()],
    )
    scopes = fields.SelectMultipleField(
        widget=scopes_multi_checkbox,
        choices=[],  # Must be dynamically provided in view.
        description=_(
            'Scopes assign permissions to your personal access token.'
            ' A personal access token works just like a normal OAuth '
            ' access token for authentication against the API.'))