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()])
class RegisterForm(Form): nickname = TextField(u'昵称', [Required(), Length(min=3, max=12)]) email = TextField(u'邮件地址', [Length(min=6, max=30), Email(), email_unique]) password = PasswordField(u'密码', [Length(min=6, max=12), Required()]) password_confirm = PasswordField( u'密码确认', [Required(), EqualTo('password', message=u'密码必须相同')]) captcha = TextField(u'验证码', [Required()])
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 TicketForm(Form): def bind_runtime_fields(self, g, ticket=None): self.product.queryset = Product.get_all_products(g.organization._id) self.owner.queryset = User.get_all_users(g.organization._id) if ticket is not None: self.tid.data = ticket.id else: self.owner.default = unicode(g.user.id) tid = HiddenField('id', validators=[Length(max=24)]) title = TextField('Title') body = TextAreaField('Body') priority = SelectField('Priority', choices=[(x, PRIORITIES[x]) for x in\ xrange(len(PRIORITIES))], coerce=int) product = QSSelectField('Product', label_attr='name') tags = TagsField('Tags', description='Comma separated (e.g., auth,crash,login)') owner = QSSelectField('Owner', label_attr=('name.first', 'name.last')) new_comment = TextAreaField('Comment') status = SelectField('Status', choices=[(x, STATUSES[x]) for x in xrange(len(STATUSES))], coerce=int, default=0) submit = SubmitField('Submit')
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 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)
class ProfileForm(Form): password = PasswordField('New Password', validators=[ Optional(), Length(min=8, max=80), EqualTo('confirm', message='Passwords must match') ]) confirm = PasswordField('Repeat Password') default_ipv4_mask = IntegerField( label='IPv4 Mask', validators=[ Optional(), NumberRange(min=0, max=32, message='IPv4 Mask must between %(min)s and %(max)s'), ]) default_ipv6_mask = IntegerField( label='IPv6 Mask', validators=[ Optional(), NumberRange(min=0, max=128, message='IPv6 Mask must between %(min)s and %(max)s'), ]) timezone = QuerySelectField(get_label='name', allow_blank=True) submit = SubmitField('Update Profile')
class RegisterForm(Form): email = TextField('Email Address', validators = [Email()]) password = PasswordField('New Password', validators=[ Required(), Length(min=8, max=80), EqualTo('confirm', message='Passwords must match') ]) confirm = PasswordField('Repeat Password') accept_tos = BooleanField('I accept the TOS', validators = [Required()]) timezone = QuerySelectField(get_label='name', allow_blank=True) submit = SubmitField('Register')
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 SystemForm(Form): name = TextField('Name', [Required()]) description = TextAreaField('Description', [Required()]) meta_description = TextAreaField('Meta Description', [Required(), Length(min=90, max=170)]) icon_url = TextField('Icon URL') def __init__(self, *args, **kwargs): kwargs['csrf_enabled'] = False super(SystemForm, self).__init__(*args, **kwargs) # def validate_icon_url(form, field): # if field.data: # print 'herefasdfasd' # import urllib2 # try: # req = urllib2.Request(field.data, None, None) # urllib2.urlopen(req) # except Exception, e: # logging.info("exception %s" % e) # raise ValidationError('Invalid URL')
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")
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 SuggestQuestionForm(Form): question = TextField(validators=[ Required(), Length(min=10, max=200, message='Question must be between 10 and 200 characters') ]) category = SelectField(validators=[existing_category, Required()]) def __init__(self, *args, **kwargs): super(SuggestQuestionForm, 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: category = cdw.categories.with_id(self.category.data) except: category = None return SuggestedQuestion(author=cdw.users.with_id( current_user.get_id()), category=category, text=self.question.data)
class UserRegistrationForm(Form): username = TextField( "Create a Username...", validators=[ Required(message='Username required'), Regexp('^[a-zA-Z0-9_.-]+$', message="Username contains invalid characters"), Length(min=2, max=18, message="Username must be between 2 and 18 characters"), does_not_have_bad_words ]) email = TextField("Email Address:", validators=[ Required(message='Email required'), Email(message="Invalid email address"), email_is_unique ]) password = PasswordField( "Password", validators=[Required(message='Password required')]) """
class LoginForm(Form): email = TextField(u'邮件地址', [Required(), Length(min=6, max=30), Email()]) password = PasswordField(u'密码', [Length(min=6, max=12), Required()]) captcha = TextField(u'验证码', [Required()])