Exemple #1
0
class EditUserForm(Form):

    # TODO: NAME字段格式检查的中文支持

    next_page = HiddenField()
    id = IntegerField(widget=HiddenInput())

    email = TextField(u'Email', validators=[UnChanged()])
    username = TextField(u'Username', validators=[UnChanged()])
    name = TextField(u'Name', description=u'Unique',
                     validators=[Required(message=u'Name is required'),
                                 Regexp(u'^[a-zA-Z0-9\_\-\.\ ]{1,20}$', message=u'Incorrect name format'),
                                 Unique(User, User.name, message=u'The current name is already in use')])
    weixin = TextField(u'Weixin OpenID', description=u'Unique, Using the command <code>openid</code> get in WeiXin',
                       validators=[Optional(),
                                   Unique(User, User.weixin, message=u'The current weixin OpenID is already in use')])
    groups = QuerySelectMultipleField(u'Group', description=u'Multiple Choice',
                                      query_factory=Group.query.all, get_label='desc',
                                      validators=[Required(message=u'Group is required')])
    password = TextField(u'Password', description=u'At least five characters',
                         validators=[Optional(),
                                     Regexp(u'^.{5,20}$', message=u'Password are at least five chars')])
    status = BooleanField(u'Status', description=u'Check to enable this user')

    submit = SubmitField(u'Submit', id='submit')
Exemple #2
0
class ChangePasswordForm(Form):

    # TODO: NAME字段格式检查的中文支持

    next_page = HiddenField()
    id = IntegerField(widget=HiddenInput())

    now_password = PasswordField(u'Password')
    new_password = PasswordField(
        u'New Password',
        description=u'At least eight characters',
        validators=[
            Optional(),
            Regexp(u'(^.{8,20}$)|(^$)',
                   message=u'Password are at least eight chars'),
            Depend('now_password',
                   message=u'Password is required when changing password')
        ])
    confirm_password = PasswordField(
        u'Confirm Password',
        description=u'Re-enter the new password',
        validators=[
            Optional(),
            EqualTo('new_password', message=u'New passwords must be the same')
        ])

    submit = SubmitField(u'Submit', id='submit')
Exemple #3
0
class CreateLogin(Form):
    fname = TextField('*First Name', validators=[Required()])
    lname = TextField('Last Name',
                      validators=[Optional(strip_whitespace=True)])
    mobile = TextField(
        'Mobile',
        validators=
        # sets optional entry and strips whitespace
        [
            Optional(strip_whitespace=True),
            v.Length(max=15, message='Mobile exceeds length')
        ])
    zipcode = IntegerField('Zipcode',
                           validators=[Optional(strip_whitespace=True)])
    # v.NumberRange(max=9,
    # message='Zipcode exceeds length')])
    email = TextField('*Email',
                      validators=[
                          Required(),
                          v.Email(),
                          v.EqualTo('confirm_email',
                                    message="Emails must match")
                      ])
    confirm_email = TextField('*Confirm Email')
    bio = TextAreaField('Bio', validators=[Length(min=0, max=140)])
    password = PasswordField('*Password',
                             validators=[
                                 Required(),
                                 v.EqualTo('confirm_password',
                                           message='*Passwords must match')
                             ])
    confirm_password = PasswordField('Confirm Password')
    remember_me = BooleanField('Remember Me', default=False)
    recaptcha = RecaptchaField('*Person Test')
Exemple #4
0
class ProfileForm(Form):
    multipart = True
    next = HiddenField()
    email = EmailField(u'Email', [Required(), Email()])
    # Don't use the same name as model because we are going to use populate_obj().
    avatar_file = FileField(u"Avatar", [Optional()])
    sex_code = RadioField(u"Sex",
                          [AnyOf([str(val) for val in SEX_TYPE.keys()])],
                          choices=[(str(val), label)
                                   for val, label in SEX_TYPE.items()])
    age = IntegerField(u'Age', [Optional(), NumberRange(AGE_MIN, AGE_MAX)])
    phone = TelField(u'Phone', [Length(max=64)])
    url = URLField(u'URL', [Optional(), URL()])
    deposit = DecimalField(
        u'Deposit',
        [Optional(), NumberRange(DEPOSIT_MIN, DEPOSIT_MAX)])
    location = TextField(u'Location', [Length(max=64)])
    bio = TextAreaField(u'Bio', [Length(max=1024)])
    submit = SubmitField(u'Save')

    def validate_name(form, field):
        user = User.get_by_id(current_user.id)
        if not user.check_name(field.data):
            raise ValidationError("Please pick another name.")

    def validate_avatar_file(form, field):
        if field.data and not allowed_file(field.data.filename):
            raise ValidationError("Please upload files with extensions: %s" %
                                  "/".join(ALLOWED_AVATAR_EXTENSIONS))
Exemple #5
0
class PostForm(Form):
    yesno = TextField(validators=[AnyOf(["1","0"])])
    
    text = TextField(validators=[
        Length(min=1, max=140, 
               message="Post must be between 2 and 140 characters"), 
        Required(), does_not_have_bad_words])
    
    author = TextField(validators=[Required(), check_if_user_does_not_exist])
    origin = TextField(validators=[Required(), AnyOf(["web","kiosk","cell"])])
    responseto = TextField(validators=[check_if_post_exists, Optional()])
    
    follow_sms = TextField(validators=[AnyOf(["on","start","yes"]), Optional()])
    follow_email = TextField(validators=[AnyOf(["on","start","yes"]), Optional()])
    
    def get_follow_sms(self):
        return self.follow_sms.data in ["on","start","yes"]
    
    def get_follow_email(self):
        return self.follow_email.data in ["on","start","yes"]
    
    def to_post(self):
        try:
            responseTo = cdw.posts.with_id(self.responseto.data)
        except:
            responseTo = None
            
        return Post(yesNo=int(self.yesno.data), 
                    text=self.text.data, 
                    author=User.objects.with_id(self.author.data),
                    origin=self.origin.data,
                    responseTo=responseTo)
Exemple #6
0
class UserForm(Form):
    first_name = TextField(u'First name', validators=[required()])
    last_name = TextField(u'Last name', validators=[required()])
    email_address = TextField(u'Email address',
                              validators=[required(), Email()])
    password = PasswordField(
        u'New password', validators=[Optional(),
                                     EqualTo('password_confirm')])
    password_confirm = PasswordField(u'Password confirm',
                                     validators=[Optional()])

    def __init__(self, formdata=None, obj=None, prefix='', **kwargs):
        super(UserForm, self).__init__(formdata, obj, prefix, **kwargs)
        if obj:
            self.user = obj
        else:
            self.user = None

    def validate_email_address(self, field):
        user = User.query.filter_by(email_address=field.data) \
                         .filter(User.id != self.user.id).first()
        if user:
            raise ValidationError('That email address is already in use')

    def save(self):
        self.user.first_name = self.first_name.data
        self.user.last_name = self.last_name.data
        self.user.email_address = self.email_address.data

        if len(self.password.data) > 1:
            self.user.password = self.password.data

        db.session.add(self.user)
        db.session.commit()
        return self.user
Exemple #7
0
class SettingForm(BaseForm):
    screen_name = TextField(_('Display Name'), validators=[Length(max=80)])
    website = URLField(_('Website'), validators=[URL(), Optional()])
    city = TextField(_('City'), description=_('Where are you living'))
    description = TextAreaField(_('Description'),
                                validators=[Optional(),
                                            Length(max=400)],
                                description=_('Markdown is supported.'))
Exemple #8
0
class ContentForm(Form):
    name = TextField(u'名称',[Required(u'请输入名称')])
    type = SelectField(u"类型", [AnyOf([str(val) for val in AD_CONTENT_TYPES.keys()])],choices=[(str(val), label) for val, label in AD_CONTENT_TYPES.items()])
    mode = SelectField(u"广告展示形式", [AnyOf([str(val) for val in AD_CONTENT_MODES.keys()])],choices=[(str(val), label) for val, label in AD_CONTENT_MODES.items()])
    img = TextField(u'图片链接地址',[Optional()],default='http://')
    txt = TextField(u'关键字')
    to_url = TextField(u'目标链接地址',default='http://')
    remark = TextAreaField(u'备注',[Optional()])
Exemple #9
0
class TeamForm(Form):
    name = StrippedTextField(u'Team Name', \
            validators=[Unique(), Length(min=0,max=100), Required()])
    tag = StrippedTextField(u'Tag', \
            validators=[Length(min=0,max=20), Required()])
    url = StrippedTextField(u'Web Site', \
            validators=[Length(min=0,max=255), Optional()])
    join_password = TextField(u'Join Password', \
            validators=[Length(min=0,max=255), Optional()])
    time_zone = SelectField(u'Team Time Zone', default="US/Eastern", \
            choices=User.TimeZoneChoices,\
            validators=[Required()])
Exemple #10
0
class StockInForm(Form):
    sku = QuerySelectField(u'商品',query_factory=skus,get_label='name')
    store_id = SelectField(u"仓库", [AnyOf([str(val) for val in STORES.keys()])],choices=[(str(val), label) for val, label in STORES.items()])
    c = SelectField(u"入库方式", [AnyOf([str(val) for val in STOCK_IN_CATEGORIES_IDs])],choices=[(str(val), STOCK_IN_CATEGORIES[val]) for val in STOCK_IN_CATEGORIES_IDs])
    shelf_number = TextField(u'货架号')
    code = TextField(u'入库凭证')
    made_in = TextField(u'产地')
    purchase_price = FloatField(u'进货价',default=0.0)
    mfg_date = DateField(u'生产日期',[Optional()])
    exp_date = DateField(u'有效期至',[Optional()])
    quantity = IntegerField(u'入库数量',[validate_gte_0])
    order_id = TextField(u'关联订单号')
    remark = TextAreaField(u'备注')
Exemple #11
0
class QuestionForm(Form):
    category = SelectField("Category", validators=[
                           Required(), check_if_category_exists])
    
    author = TextField("Author", validators=[
                       check_if_user_does_not_exist, Optional()])
    
    text = TextAreaField("Text", validators=[
        Length(min=1, max=140, 
               message="Question must be between 2 and 256 characters"),
        Required()])
    
    def __init__(self, *args, **kwargs):
        super(QuestionForm, self).__init__(*args, **kwargs)
        cat_choices = [(str(c.id), c.name) for c in cdw.categories.all()]
        self.category.choices = cat_choices
    
    def to_question(self):
        try:
            user = cdw.users.with_id(self.author.data)
        except:
            user = None
        
        return Question(
            category=cdw.categories.with_id(self.category.data),
            author=user,
            text = self.text.data)
Exemple #12
0
class MatchForm(Form):
    team_id = SelectField(u'Team', coerce=int, validators=[Required()])
    opponent_id = SelectField(u'Opponent',
                              coerce=int,
                              choices=[],
                              validators=[Required()])
    competition_id = SelectField(u'Competition',
                                 coerce=int,
                                 validators=[Required()])
    server_id = SelectField(u'Server', coerce=int, validators=[Required()])
    date = MatchDateTimeField(u'Date', validators=[Required()])
    password = TextField(u'Server Password', \
            validators=[Length(min=0,max=100), Optional()])
    comments = TextAreaField(u'Comments', validators=[Optional()])

    players = FieldList(FormField(MatchPlayerForm))
Exemple #13
0
class EditSettingForm(Form):

    # TODO: NAME字段格式检查的中文支持

    next_page = HiddenField()
    id = IntegerField(widget=HiddenInput())

    email = TextField(u'Email', validators=[UnChanged()])
    username = TextField(u'Username', validators=[UnChanged()])
    name = TextField(u'Name',
                     description=u'Unique',
                     validators=[
                         Required(message=u'Name is required'),
                         Regexp(u'^[a-zA-Z0-9\_\-\.\ ]{1,20}$',
                                message=u'Incorrect name format'),
                         Unique(User,
                                User.name,
                                message=u'The current name is already in use')
                     ])
    weixin = TextField(
        u'Weixin OpenID',
        description=
        u'Unique, Using the command <code>openid</code> get in WeiXin',
        validators=[
            Optional(),
            Unique(User,
                   User.weixin,
                   message=u'The current weixin OpenID is already in use')
        ])

    submit = SubmitField(u'Submit', id='submit')
Exemple #14
0
class ThreadCrudForm(Form):
    question_id = HiddenField(validators=[Required(),valid_question])
    
    author_id = SelectMultipleField("Author", 
        validators=[check_if_user_does_not_exist])
     
    yesno = SelectField("Yes or No?", 
        validators=[AnyOf(["1","0"]), Required()],
        choices=[("1",'Yes'),("0",'No')])
    
    text = TextAreaField("Opinion", 
        validators=[
            Length(min=1, max=140, 
                message="Post must be between 2 and 140 characters"), 
            Required(), 
            does_not_have_bad_words])
    
    likes = IntegerField("Likes", validators=[Optional()])
    
    def __init__(self, question_id=None, *args, **kwargs):
        super(ThreadCrudForm, self).__init__(*args, **kwargs)
        if question_id:
            self.question_id.data = question_id
        self.author_id.choices = [(str(u.id),'%s (%s)' % (u.username, u.origin)) \
                                  for u in cdw.users.with_fields(isAdmin=True).order_by("+username")]
Exemple #15
0
class RateEntry(Form):
    entry_id = HiddenField(validators=[Required(), NumberRange(min=1)])
    score_gameplay = IntegerField(
        "Gameplay rating",
        validators=[Required(), NumberRange(min=1, max=10)],
        default=5)
    score_graphics = IntegerField(
        "Graphics rating",
        validators=[Required(), NumberRange(min=1, max=10)],
        default=5)
    score_audio = IntegerField(
        "Audio rating",
        validators=[Required(), NumberRange(min=1, max=10)],
        default=5)
    score_innovation = IntegerField(
        "Innovation rating",
        validators=[Required(), NumberRange(min=1, max=10)],
        default=5)
    score_story = IntegerField(
        "Story rating",
        validators=[Required(), NumberRange(min=1, max=10)],
        default=5)
    score_technical = IntegerField(
        "Technical rating",
        validators=[Required(), NumberRange(min=1, max=10)],
        default=5)
    score_controls = IntegerField(
        "Controls rating",
        validators=[Required(), NumberRange(min=1, max=10)],
        default=5)
    score_overall = IntegerField(
        "Overall rating",
        validators=[Required(), NumberRange(min=1, max=10)],
        default=5)
    note = TextField("Additional notes", validators=[Optional()])
Exemple #16
0
class UploadForm(Form):
  picture = FileField('Image', validators=[
    FileRequired('This field is required.'),
    FileAllowed()
  ])
  category = QuerySelectField(query_factory=lambda: Category.query.order_by(Category.name),
                              allow_blank=True)
  episode = IntegerField('Episode', validators=[Optional(strip_whitespace=False), NumberRange(1)])
Exemple #17
0
class URLForm(Form):
    url = TextField(
        'URL',
        [Required(), Length(max=255), URL()], widget=XXLargeTextInput())
    slug = TextField('Slug',
                     [Optional(), Length(max=30),
                      Regexp(RE_SLUG)],
                     widget=TextInput())
    submit = SubmitField('shorten')
Exemple #18
0
class SettingsForm(Form):
    """Form for modifying build settings."""

    name = TextField(validators=[Length(min=1, max=200)])
    send_email = BooleanField('Send notification emails')
    email_alias = TextField('Mailing list for notifications',
                            validators=[Optional(), Email()])
    build_id = HiddenField(validators=[NumberRange(min=1)])
    save = SubmitField('Save')
Exemple #19
0
class EditProfileForm(Form):
    username = TextField("Username", validators=[
        Regexp('^[a-zA-Z0-9_.-]+$', 
            message="Username contains invalid characters"), 
        Length(min=2, max=16, 
            message="Username must be between 2 and 16 characters"),
        username_same_or_exists, does_not_have_bad_words])
    
    email = TextField("Email Address", validators=[
        Required(message='Email required'),
        Email(message="Invalid email address")])
    
    password = PasswordField("Change Password", validators=[
        Length(min=4, max=32, 
            message="Username must be between 2 and 16 characters"), 
        EqualTo('password2', message='Passwords must match'),
        Optional()])
    
    password2 = PasswordField("Repeat password", validators=[Optional()])
Exemple #20
0
class SettingsForm(Form):
    """Form for modifying build settings."""

    name = TextField(validators=[Length(min=1, max=200)])
    send_email = BooleanField('Send notification emails')
    email_alias = TextField('Mailing list for notifications',
                            validators=[Optional(), Email()])
    build_id = HiddenField(validators=[NumberRange(min=1)])
    teamcityUrl = TextField(
        label=
        "Base TeamCity URL to Notify Upon Successful Testrun Completion (Optional)"
    )
    save = SubmitField('Save')
Exemple #21
0
class SettingsForm(Form):
    username = TextField(
        u'用户名',
        validators=[Required(),
                    Length(min=4, max=32),
                    Regexp(re_username)])
    #nickname = TextField(u'昵称', validators=[Optional(), Length(max=32)])
    city = TextField(u'城市', validators=[Optional(), Length(max=40)])
    province = TextField(u'省份', validators=[Optional(), Length(max=40)])
    birthday = DateField(u'出生年月日',
                         validators=[Optional()],
                         widget=DatePickerWidget(),
                         default=datetime.date(1990, 1, 1))
    blog = TextField(u'博客', validators=[Optional(), URL(), Length(max=100)])
    descp = TextAreaField(u'个人介绍', validators=[Optional(), Length(max=500)])
    signature = TextAreaField(u'签名', validators=[Optional(), Length(max=200)])
    realname = TextField(u'真实姓名', validators=[Optional(), Length(max=80)])
    idcard = TextField(u'身份证', validators=[Optional(), Length(max=32)])
Exemple #22
0
class book_edit_form(Form):
    title = TextField("Title")
    imprint = TextField("Imprint")
    eisbn = TextField("eISBN", validators=[Optional()])
    pisbn = TextField("pISBN", validators=[Optional()])
    language = TextField("Language")
    list_price = DecimalField("List Price", places=2, validators=[Optional()])
    currency = SelectField(
        "Currency",
        choices=[(g, g)
                 for g in ['none', 'USD', 'EUR', 'GBP', 'CAD', 'CNY', 'JPY']])
    release_date = DateField("Release Date",
                             validators=[Optional()],
                             format='%m/%d/%Y')
    publishing_date = DateField("Publishing Date",
                                validators=[Optional()],
                                format='%m/%d/%Y')
    description = TextAreaField("Description")
    bisac = TextField("BISAC")
    bic = TextField("BIC")
    #TODO: Fix this, this needs to be a list.
    territory = SelectField("Countries to sell in",
                            choices=[('none', 'none'), ('US', 'US'),
                                     ('GB', 'GB'), ('FR', 'FR'), ('IT', 'IT'),
                                     ('CN', 'CN'), ('JP', 'JP'), ('ES', 'ES'),
                                     ('IE', 'IE'), ('DE', 'DE')],
                            validators=[Optional()])
    adult = BooleanField("Is this an adult book?")
    edition = TextField("Edition")
    series = SelectField("Series", coerce=int)
    volume = TextField("Volume")
    authors = SelectMultipleField("Authors", coerce=int)
    editors = SelectMultipleField("Editors", coerce=int)
    illustrators = SelectMultipleField("Illustrators", coerce=int)
    contributors = SelectMultipleField("Contributors", coerce=int)
    translators = SelectMultipleField("Translators", coerce=int)

    def validate_publishing_date(self, field):
        if field.data > self.release_date.data:
            raise ValidationError(
                "The publishing date must be before or equal to the release date."
            )

    def is_isbn_valid(self, isbn):
        if not isValid(isbn):
            raise ValidationError("The ISBN entered is not valid.")

    def validate_eisbn(self, field):
        self.is_isbn_valid(field.data)

    def validate_pisbn(self, field):
        self.is_isbn_valid(field.data)
Exemple #23
0
class KioskUserForm(Form):
    username = TextField(validators=[
        Required(message='Username required'),
        Regexp('^[a-zA-Z0-9_.-]+$', 
               message="Username contains invalid characters"), 
        Length(min=2, max=16, 
               message="Username must be between 2 and 16 characters"),
        does_not_have_bad_words
    ])
    
    phonenumber = TextField(validators=[validate_phonenumber, Optional()])
    
    def get_phone(self):
        has_phone = len(self.phonenumber.data) == 10
        return self.phonenumber.data if has_phone else None 
    
    def to_user(self):
        return User(username=self.username.data, 
                    phoneNumber=self.phonenumber.data, 
                    origin="kiosk")
Exemple #24
0
class PostCrudForm(Form):   
    yesno = SelectField("Yes or No?", 
        validators=[AnyOf(["1","0"]), Required()],
        choices=[("1",'Yes'),("0",'No')])
    
    debate_id = HiddenField(validators=[check_if_thread_exists])
    
    text = TextAreaField(validators=[
        Length(min=1, max=140, 
               message="Post must be between 2 and 140 characters"), 
        Required(), does_not_have_bad_words])
    
    author_id = SelectMultipleField("Author", 
        validators=[check_if_user_does_not_exist])
    
    origin = SelectField(validators=[Required(), 
                                     AnyOf(["web","kiosk","cell"]),],
                                     choices=[("web",'Web'),("kiosk",'Kiosk'), ("cel", "Cell")])
    
    likes = IntegerField("Likes", validators=[Optional()])
    
    def __init__(self, debate_id=None, *args, **kwargs):
        super(PostCrudForm, self).__init__(*args, **kwargs)
        if debate_id:
            self.debate_id.data = debate_id
            
        self.author_id.choices = [(str(u.id),'%s (%s)' % (u.username, u.origin)) \
                                  for u in cdw.users.with_fields(isAdmin=True).order_by("+username")]
    
    def to_post(self):
        try:
            responseTo = cdw.posts.with_id(self.responseto.data)
        except:
            responseTo = None
            
        return Post(yesNo=int(self.yesno.data), 
                    text=self.text.data, 
                    author=User.objects.with_id(self.author_id.data[0]),
                    origin=self.origin.data,
                    likes=self.likes.data,
                    responseTo=responseTo) 
Exemple #25
0
class CompletedMatchForm(Form):
    team_id = SelectField(u'Team', coerce=int, validators=[Required()])
    match_id = HiddenIntegerField(u'Corresponding Match',
                                  validators=[NumberRange(min=1),
                                              Required()])
    opponent_id = SelectField(u'Opponent',
                              coerce=int,
                              choices=[],
                              validators=[Required()])
    competition_id = SelectField(u'Competition',
                                 coerce=int,
                                 validators=[Required()])
    server_id = SelectField(u'Server', coerce=int, validators=[Required()])
    date_played = MatchDateTimeField(u'Date', validators=[Required()])
    comments = TextAreaField(u'Comments', validators=[Optional()])

    final_result_method = SelectField(
        u'Final Result',
        coerce=int,
        validators=[Required()],
        choices=CompletedMatch.FinalResultChoices)

    rounds = FieldList(FormField(CompletedMatchRoundForm))
Exemple #26
0
class ProfileForm(Form):
    multipart = True
    next = HiddenField()
    email = EmailField(_('Email'), [Required(), Email()])
    # Don't use the same name as model because we are going to use populate_obj().
    avatar_file = FileField(_("Avatar"), [Optional()])
    sex_code = RadioField(_("Sex"),
                          [AnyOf([str(val) for val in SEX_TYPE.keys()])],
                          choices=[(str(val), label)
                                   for val, label in SEX_TYPE.items()])
    age = IntegerField(_('Age'), [Optional(), NumberRange(AGE_MIN, AGE_MAX)])
    phone = TelField(_('Phone'), [Length(max=64)])
    url = URLField(_('URL'), [Optional(), URL()])
    deposit = DecimalField(
        _('Deposit'),
        [Optional(), NumberRange(DEPOSIT_MIN, DEPOSIT_MAX)])
    location = TextField(_('Location'), [Length(max=64)])
    bio = TextAreaField(_('Bio'), [Length(max=1024)])
    submit = SubmitField(_('Save'))

    def validate_name(form, field):
        user = User.get_by_id(current_user.id)
        if not user.check_name(field.data):
            raise ValidationError(_("Please pick another name."))

    def validate_avatar_file(form, field):
        if field.data and not allowed_file(field.data.filename):
            raise ValidationError(
                _("Please upload files with extensions:") +
                " %s" % "/".join(ALLOWED_AVATAR_EXTENSIONS))

    def create_profile(self, request, user):

        if self.avatar_file.data:
            upload_file = request.files[self.avatar_file.name]
            if upload_file and allowed_file(upload_file.filename):
                # Don't trust any input, we use a random string as filename.
                # or use secure_filename:
                # http://flask.pocoo.org/docs/patterns/fileuploads/

                user_upload_dir = os.path.join(
                    current_app.config['UPLOAD_FOLDER'], "user_%s" % user.id)
                current_app.logger.debug(user_upload_dir)

                make_dir(user_upload_dir)
                root, ext = os.path.splitext(upload_file.filename)
                today = datetime.now().strftime('_%Y-%m-%d')
                # Hash file content as filename.
                hash_filename = hashlib.sha1(
                    upload_file.read()).hexdigest() + "_" + today + ext
                user.avatar = hash_filename

                avatar_ab_path = os.path.join(user_upload_dir, user.avatar)
                # Reset file curso since we used read()
                upload_file.seek(0)
                upload_file.save(avatar_ab_path)

        self.populate_obj(user)
        self.populate_obj(user.user_detail)

        db.session.add(user)
        db.session.commit()
Exemple #27
0
class ADForm(Form):
    name = TextField(u'名称',[Required(u'请输入名称')])
    product = QuerySelectField(u'产品',query_factory=lambda :AD_Product.query.all(), get_label='name')
    place = QuerySelectField(u'媒体广告位',query_factory=lambda :AD_Place.query.order_by(AD_Place.medium_id), get_label='fullname')
    content = QuerySelectField(u'展示内容',query_factory=lambda :AD_Content.query.all(), get_label='fullname')
    remark = TextAreaField(u'备注',[Optional()])
class person_form(Form):
    first_name = TextField("First name")
    last_name = TextField("Last name")
    birthday = DateField("Birthday",
                         validators=[Optional()],
                         format="%m/%d/%Y")
Exemple #29
0
class CreateRepositoryForm(Form):
    title = TextField("Title", validators = [Required()])
    slug = TextField("Slug", validators = [
        Optional(),
        Regexp("[0-9a-zA-Z\-_]", message = "The slug contains invalid characters. Only use alphanumeric characters, dashes and underscores.")])
    clone_from = TextField("Clone from URL", validators = [Optional()])
class edit_series(Form):
    title = TextField("Series title")
    begin_date = DateField("Begin date", validators=[Optional()], format='%m/%d/%Y')
    end_date = DateField("End date", validators=[Optional()], format='%m/%d/%Y')