class LossForm(Form): sku = QuerySelectField(u'商品',query_factory=lambda:Sku.query.all(),get_label='name') quantity = IntegerField(u'报损数量',[validate_gte_0]) channel = SelectField(u"损坏渠道", [AnyOf([str(val) for val in LOSS_CHANNELS.keys()])],choices=[(str(val), label) for val, label in LOSS_CHANNELS.items()]) degree = SelectField(u"损坏情况", [AnyOf([str(val) for val in LOSS_DEGREES.keys()])],choices=[(str(val), label) for val, label in LOSS_DEGREES.items()]) link_order_id = TextField(u'关联订单号') remark = TextAreaField(u'原因备注')
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)
class OperatorForm(Form): next = HiddenField() id = HiddenField(default=0) username = TextField(u'帐号', [Required(u'请输入帐号')]) password = PasswordField(u'密码') nickname = TextField(u'姓名', [Required(u'请输入姓名')]) op_id = TextField(u'工号') email = TextField(u'邮箱地址',[Email(u'邮箱格式不正确')]) team = SelectField(u"所属组", [AnyOf([str(val) for val in TEAMS.keys()+DEPARTMENTS.keys()])],choices=TEAM_CHOICES) role = QuerySelectField(u'角色',query_factory=lambda :Role.query.all(),get_label='name') is_admin = BooleanField(u'设为系统管理员') assign_user_type = SelectField(u"指派客户类型", [AnyOf([str(val) for val in OPEARTOR_ASSIGN_USER_TYPES.keys()])],choices=[(str(val), label) for val, label in OPEARTOR_ASSIGN_USER_TYPES.iteritems()]) store_id = SelectField(u"仓库", [AnyOf([str(val) for val in STORES2.keys()])],choices=[(str(val), label) for val, label in STORES2.items()]) #SelectField(u"角色", [AnyOf([str(val) for val in USER_ROLE.keys()])],choices=[(str(val), label) for val, label in USER_ROLE.items()]) #SelectField(u"角色", [AnyOf([str(val) for val in USER_ROLE.keys()])], # choices=[(str(val), label) for val, label in USER_ROLE.items()]) #is_admin = BooleanField(u'是否设为管理员') def validate_password(self,field): operator_id = int(self.id.data) if not operator_id: if not field.data or len(field.data)<6: raise ValidationError(u'密码为空或小于6位') else: if field.data and len(field.data)<6: raise ValidationError(u'密码必须不小于6位') def validate_username(self, field): operator_id = int(self.id.data) if not operator_id: if Operator.query.filter_by(username=field.data).first() is not None: raise ValidationError(u'用户名已存在')
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()])
class ProfileForm(Form): next = HiddenField() name = TextField( label = _("Username"), validators = [ Required(), Length(USERNAME_LEN_MIN, USERNAME_LEN_MAX), ], description = u"Combination of letters/digits/underscore, at least %s characters." % USERNAME_LEN_MIN, ) email = EmailField( label = _('Email'), validators = [Email()], ) created_time = DateField( label = _('Created time'), ) role_id = RadioField( label = "Role", validators = [AnyOf([str(val) for val in USER_ROLE.keys()])], choices = [(str(val), label) for val, label in USER_ROLE.items()], ) status_id = RadioField( label = "Status", validators = [AnyOf([str(val) for val in USER_STATUS.keys()])], choices = [(str(val), label) for val, label in USER_STATUS.items()], ) real_name = TextField( label = _('Real name'), validators = [ Length(REALNAME_LEN_MIN, REALNAME_LEN_MAX), ] ) age = IntegerField( label = _('Age'), validators = [NumberRange(AGE_MIN, AGE_MAX)], ) phone = TelField( label = _('Phone'), ) url = URLField( label = _('URL'), validators = [URL()], ) deposit = DecimalField( label = _('Deposit'), validators = [NumberRange(DEPOSIT_MIN, DEPOSIT_MAX)], ) location = TextField( label = _('Location'), validators = [Length(max=50)] ) bio = TextAreaField( label = _('Bio'), validators = [Length(max=1024)] ) submit = SubmitField(_('Save'))
class StockOutForm(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_OUT_CATEGORIES_IDs])],choices=[(str(val), STOCK_OUT_CATEGORIES[val]) for val in STOCK_OUT_CATEGORIES_IDs]) code = TextField(u'出库凭证') purchase_price = FloatField(u'进货价',default=0.0) quantity = IntegerField(u'出库数量',[validate_gte_0]) order_id = TextField(u'关联订单号') remark = TextAreaField(u'备注')
class UserForm(Form): next = HiddenField() role_id = RadioField(u"Role", [AnyOf([str(val) for val in USER_ROLE.keys()])], choices=[(str(val), label) for val, label in USER_ROLE.items()]) status_id = RadioField(u"Status", [AnyOf([str(val) for val in USER_STATUS.keys()])], choices=[(str(val), label) for val, label in USER_STATUS.items()]) # A demo of datepicker. created_time = DateField(u'Created time') submit = SubmitField(u'Save')
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'备注')
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))
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")]
class UserForm(Form): user_id = HiddenField(default=0) name = TextField(u'姓名', [Required(u'请输入姓名')]) gender = SelectField(u"性别", [AnyOf([u'保密',u'男',u'女'])],choices=[(label, label) for label in (u'保密',u'男',u'女')]) phone = TextField(u'手机号码',[Required(u'请输入电话号码')]) email = TextField(u'邮箱地址',[Email(u'邮箱格式不正确')]) origin = SelectField(u"客户来源", [AnyOf([str(val) for val in USER_ORIGINS.keys()])],choices=[(str(val), label) for val, label in USER_ORIGINS.items()]) status = SelectField(u"状态", [AnyOf([str(val) for val in USER_STATUS.keys()])],choices=[(str(val), label) for val, label in USER_STATUS.items()]) def validate_phone(self, field): _user_id = int(self.user_id.data) if not _user_id: if User.query.filter(User.phone==field.data).first() is not None: raise ValidationError(u'电话号码已存在') else: if User.query.filter(db.and_(User.phone==field.data,User.user_id!=_user_id)).first() is not None: raise ValidationError(u'电话号码已存在')
class ItemForm(Form): name = TextField(u'商品名称',[Required(u'输入商品名称')]) category_id = SelectField(u"类型", [AnyOf([str(val) for val in ITEM_CATEGORYS.keys()])],choices=[(str(val), label) for val, label in ITEM_CATEGORYS.items()]) desc = TextField(u'描述') def validate_name(self, field): if Item.query.filter_by(name=field.data).first() is not None: raise ValidationError(u'商品已存在')
def get_validators(self, table, field): result = self.get(table) values = [x[field] for x in result] values = sorted(values) return [ Required(), AnyOf( values, message=u'Invalid value, must be one of:' '%(values)s')]
class UserForm(Form): next = HiddenField() role_code = RadioField(u"Role", [AnyOf([str(val) for val in USER_ROLE.keys()])], choices=[(str(val), label) for val, label in USER_ROLE.items()]) status_code = RadioField(u"Status", [AnyOf([str(val) for val in USER_STATUS.keys()])], choices=[(str(val), label) for val, label in USER_STATUS.items()]) # A demo of datepicker. created_time = DateField(u'Created time') submit = SubmitField(u'Save') def save(self, user): self.populate_obj(user) db.session.add(user) db.session.commit()
class EditUserForm(Form): next = HiddenField() role_code = RadioField(_("Role"), [AnyOf([str(val) for val in USER_ROLE.keys()])], choices=[(str(val), label) for val, label in USER_ROLE.items()]) status_code = RadioField(_("Status"), [AnyOf([str(val) for val in USER_STATUS.keys()])], choices=[(str(val), label) for val, label in USER_STATUS.items()]) # A demo of datepicker. vm_quota = IntegerField( _("VM Quota"), [Required(), NumberRange(VM_QUOTA_MIN, VM_QUOTA_MAX)]) created_time = DateField(_('Created time')) submit = SubmitField(_('Save')) def validate_name(self, field): if User.query.filter_by(name=field.data).first() is not None: raise ValidationError(_(u'This username is taken'))
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)
class EditHostForm(Form): next = HiddenField() type_code = RadioField(_(u"Hypervisor Type"), [AnyOf([str(val) for val in HOST_TYPE.keys()])], choices=[(str(val), label) for val, label in HOST_TYPE.items()]) username = TextField(_(u'The Username used by libvirt+ssh connection'), [Required()]) submit = SubmitField(_(u'Save')) def validate_address(self, field): if Host.query.filter_by(address=field.data).first() is not None: raise ValidationError(_(u'This host is added'))
class LoginForm(Form): next = HiddenField() login = TextField(_(u'Username or email'), [Required()]) password = PasswordField( _('Password'), [Required(), Length(PASSWORD_LEN_MIN, PASSWORD_LEN_MAX)]) locale_code = RadioField( _("Language"), [AnyOf([str(val) for val in USER_LOCALE_STRING.keys()])], choices=[(str(val), label) for val, label in USER_LOCALE_STRING.items()], default=USER_LOCALE_ZH_CN) remember = BooleanField(_('Remember me')) submit = SubmitField(_('Login'))
class ContactForm(Form): firstname = TextField(validators=[ Length(min=2, max=16, message="First name must be between 2 and 16 characters"), Required(message='First name is required')]) lastname = TextField(validators=[ Length(min=2, max=16, message="Last name must be between 2 and 16 characters"), Required(message='Last name is required')]) email = TextField("Email Address", validators=[ Required(message='Email is required'), Email(message="Invalid email address")]) feedback = SelectField(validators=[ Required("A feedback type is required"), AnyOf(["question", "comment", "bug"]), Required()], choices=[("question",'Question'),("comment",'Comment'),("bug",'Bug')]) comment = TextAreaField(validators=[ Length(min=1, max=300, message="Please provide some feedback"), Required("A comment is required")]) def __init__(self, *args, **kwargs): super(ContactForm, self).__init__(*args, **kwargs) if self.firstname.data and \ 'first' == self.firstname.data.lower(): self.firstname.data = '' if self.lastname.data and \ 'last' == self.lastname.data.lower(): self.lastname.data = '' if self.email.data and \ 'i.e. ' in self.email.data: self.email.data = '' def to_dict(self): return dict(firstname=self.firstname.data, lastname=self.firstname.data, email=self.email.data, feedback=self.feedback.data, comment=self.comment.data)
class SkuForm(Form): name = TextField(u'SKU名称',[Required(u'输入SKU名称')]) item = QuerySelectField(u'商品',query_factory=lambda :Item.query.filter(Item.status==True), get_label='name') p1 = TextField(SKU_PROPERTIES_NAME['p1']) p2 = TextField(SKU_PROPERTIES_NAME['p2']) p3 = TextField(SKU_PROPERTIES_NAME['p3']) code = TextField(u'商品条码',[Required(u'商品条码不允许为空')]) # price = FloatField(u'零售价',[validate_gte_0]) # market_price = FloatField(u'市场价',[validate_gte_0]) # discount_price = FloatField(u'活动价',[validate_gte_0],default=0) price = FloatField(u'零售价') market_price = FloatField(u'市场价') discount_price = FloatField(u'活动价') allowed_gift = BooleanField(u'是否允许为赠品') unit = SelectField(u"单位", [AnyOf(SKU_UNITS)],choices=[(u, u) for u in SKU_UNITS]) threshold = IntegerField(u'阀值',[validate_gte_0],default=200) warning_threshold = IntegerField(u'警戒值',[validate_gte_0],default=500) status = BooleanField(u'是否启用',default=True)
class ProfileForm(Form): multipart = True next = HiddenField() email = EmailField(_(u'Email'), [Required(), Email()]) vm_quota = IntegerField(_(u'Quota of VirtualMachines')) locale_code = RadioField( _("Language"), [AnyOf([str(val) for val in USER_LOCALE_STRING.keys()])], choices=[(str(val), label) for val, label in USER_LOCALE_STRING.items()]) 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_vm_quota(form, field): if (not current_user.is_admin()) and current_user.vm_quota != int( field.data): raise ValidationError(_("Only admin user can update vm quota."))
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()
class ProductForm(Form): name = TextField(u'产品名称',[Required(u'请输入产品名称')]) type = SelectField(u"分类", [AnyOf([str(val) for val in AD_PRODUCT_TYPES.keys()])],choices=[(str(val), label) for val, label in AD_PRODUCT_TYPES.items()]) remark = TextField(u'备注')