Exemple #1
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 #2
0
class EmailForm(Form):
    """Simple email form."""
    name = TextField("Your Name", validators=[Required()])
    recipient = TextField("Recipient's Email", validators=[Email()])
    email = TextField("Your Email", validators=[Email()])
    message = TextAreaField("Message", validators=[Required()])
    submit = SubmitField("Send Email")
Exemple #3
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 #4
0
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()])
Exemple #5
0
class ProfileForm(Form):
    photo_img = FileField(u'头像', validators=[])
    email = TextField(u'邮箱地址*', validators=[Required(), Email()])
    nickname = TextField(u'昵称*',
                         validators=[Required(),
                                     Regexp('[\w\d-]{2,20}')])
    title = TextField(u'签名*', validators=[Required(), Regexp('.{0,128}')])
    sex = RadioField(u'性别*', coerce=int, choices=[(0, u'男人'), (1, u'女人')])
Exemple #6
0
class LoginForm(Form):
    email = TextField('Email', validators=[Required(), Email()])
    password = PasswordField('Password', validators=[Required()])
    idle_ttl = RadioField('Idle Session Timeout', default='tmp', choices=[
            ('tmp',  '20 minutes'),
            ('day',  '8 hours (a normal business day)'),
            ('week', '8 days (Monday to Monday)'),
            ])
    submit = SubmitField('Login')
Exemple #7
0
class EventForm(Form):
    name = TextField("Name",
                     validators=[Required(), validate_unique_event_name])
    description = TextField("Description")
    registration_opens = DateTimeField('Registration opens',
                                       validators=[Required()],
                                       format='%d.%m.%Y %H:%M:%S')
    registration_closes = DateTimeField('Registration closes',
                                        validators=[Required()],
                                        format='%d.%m.%Y %H:%M:%S')
class UploadForm(Form):
    """A simple form for uploading files to Open Data Boston."""
    name = TextField('Name', validators=[Required()])
    email = TextField('Email', validators=[Email()])
    phone = TextField('Phone Number')
    file = FileField()
    title = TextField('Title')
    url = TextField('Dataset URL')
    description = TextAreaField('Description', validators=[Required()])
    submit = SubmitField('Submit')
Exemple #9
0
class MemberForm(Form):
    given_name = TextField("Given name", validators=[Required()])
    family_name = TextField("Family name", validators=[Required()])
    email = TextField("Email address", validators=[Required()])

    def save(self):
        create_member(None, self.given_name.data, self.family_name.data,
                      self.email.data)
        flash("%s %s have been added" %
              (self.given_name.data, self.family_name.data))
Exemple #10
0
class AuditForm(Form):
    active = BooleanField()
    # event = QuerySelectField('Event', query_factory=lambda: Event.query.all())
    location = QuerySelectField('Location',
                                query_factory=lambda: Location.query.all())
    starts = DateTimeField('Starts',
                           validators=[Required()],
                           format='%d.%m.%Y %H:%M:%S')
    ends = DateTimeField('Ends',
                         validators=[Required()],
                         format='%d.%m.%Y %H:%M:%S')
Exemple #11
0
class DefaultLoginForm(Form):
    """The default login form used by Auth
    """
    username = TextField(
        "Username or Email",
        validators=[Required(message="Username not provided")])
    password = PasswordField(
        "Password", validators=[Required(message="Password not provided")])
    remember = CheckboxInput("Remember Me")
    next = HiddenField()
    submit = SubmitField("Login")
Exemple #12
0
class RegisterForm(Form):
    fullname = TextField('Full name',
                         validators=[Required("Your name is required")])
    email = TextField('Email address',
                      validators=[Required("Your email address is required"),
                      Email()])
    company = TextField('Company name')
    jobtitle = TextField('Job title')
    twitter = TextField('Twitter id')
    referrer = SelectField('How did you hear about this event?',
                           choices=REFERRERS)
Exemple #13
0
class BookOwningForm(Form):
    member = SelectField("Member", validators=[Required()], choices=members())
    book = SelectField("Book", validators=[Required()], choices=books())

    def save(self):
        member = Member.get_by(foaf_givenName=self.member.data).one()
        book = Book.get_by(dcterms_identifier=self.book.data).one()
        member.book_ownsCopyOf.append(book)
        member.update()
        flash("%s now owns %s" %
              (member.foaf_givenName.first, book.dcterms_title.first))
Exemple #14
0
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')
Exemple #15
0
class LoginForm(Form):
    username = TextField('Username', [Required()])
    password = PasswordField('Password', [Required()])

    def password_check(self, user=None):
        """Check the password against a user object (or find it in the db).
        If the password check passes, return True.  Otherwise, return False."""
        if self.validate():
            user = user or User.find_one({'username': self.username.data})
            if user and user.password == md5(self.password.data).hexdigest():
                return True
        return False
Exemple #16
0
class LocationForm(Form):
    name = TextField("Name",
                     validators=[Required(), validate_unique_event_name])
    capacity = TextField("Capacity", validators=[validate_capacity])

    zipcode = TextField("Zipcode", validators=[Required()])
    city = TextField("City", validators=[Required()])
    street = TextField("Street", validators=[Required()])
    country = SelectField("Country",
                          choices=COUNTRIES,
                          validators=[Required()])

    address_additions = TextField("Additions")
    google_maps_url = TextField("Google Maps URL")
Exemple #17
0
class RegisterForm(Form):
    email = TextField(u'邮箱地址*', validators=[Required(), Email()])
    nickname = TextField(u'昵称*',
                         validators=[Required(),
                                     Regexp('[\w\d-]{2,20}')])
    passwd = PasswordField(u'密码*',
                           validators=[Required(),
                                       Regexp('[\w\d-]{5,20}')])
    confirm = PasswordField(
        u'确认密码*', validators=[Required(),
                              EqualTo('passwd', message=u'密码不一致')])
    agree = BooleanField(u'我已经认真阅读并同意',
                         default=True,
                         validators=[BeTrue(u'同意此协议才能注册')])
Exemple #18
0
class FriendForm(Form):
    person1 = SelectField("First person",
                          validators=[Required()],
                          choices=members())
    person2 = SelectField("Seconf person",
                          validators=[Required()],
                          choices=members())

    def save(self):
        p1 = Member.get_by(foaf_givenName=self.person1.data).one()
        p2 = Member.get_by(foaf_givenName=self.person2.data).one()
        p1.foaf_knows.append(p2)
        p1.update()
        flash("%s and %s are now friends" %
              (self.person1.data, self.person2.data))
Exemple #19
0
class RegisterForm(Form):
    fullname = TextField('Full name', validators=[Required()])
    email = TextField('Email address', validators=[Required(), Email()])
    company = TextField('Company name (or school/college)',
                        validators=[Required()])
    jobtitle = TextField('Job title', validators=[])
    twitter = TextField('Twitter id (optional)')
    referrer = SelectField('How did you hear about this event?',
                           validators=[Required()],
                           choices=REFERRERS)
    reason = TextAreaField(
        'Reasons we should pick you',
        validators=[Required()],
        default="Specifics would be good!",
    )
Exemple #20
0
class SignUpForm(Form):
    ID = TextField(u'身份證字號', validators=[check_ID, NoneOf(ExistingUsersID(), u'此身份證字號已存在,請確認是否已註冊')])
    mobile_phone = TextField(u'行動電話', validators=[Regexp(r'^09\d{8}$', message=u'行動電話號碼格式不正確')])
    email = TextField(u'電子郵件', validators=[Email(u'電子郵件位址格式不正確')])
    password = PasswordField(u'密碼', validators=[Required(u'請設定密碼')])
    chk_password = PasswordField(u'確認密碼', validators=[EqualTo('password', u'兩次輸入的密碼不相符')])
    recaptcha = RecaptchaField(u'圖形驗證', validators=[check_recaptcha_filled, Recaptcha(u'輸入錯誤,請再試一遍')])
Exemple #21
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 #22
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 #23
0
class TopicForm(Form):
    
    body = TextAreaField('Body', [Required()])
    excerpt = TextAreaField('Excerpt', [Required()])
    meta_description = TextAreaField('Meta Description')
    category = TextField('Category', [Required()])
    name = TextField('Name', [Required()])
    published = BooleanField('Published')
    login_required = BooleanField('Login Required')
    system = HiddenField()
    
    def __init__(self, *args, **kwargs):
        kwargs['csrf_enabled'] = False
        super(TopicForm, self).__init__(*args, **kwargs)

    def validate_category(form, field):
        return slugify(field.data)
Exemple #24
0
class RegisterForm(Form):
    password = PasswordField('Password',
                             validators=[
                                 Required(),
                                 EqualTo('confirm',
                                         message='Passwords must match')
                             ])
    confirm = PasswordField('Repeat Password')
Exemple #25
0
class ResetPasswordForm(Form):
    new_password = PasswordField("New Password",
                                 validators=[
                                     Required(message='Password required'),
                                     EqualTo('confirm',
                                             message='Passwords must match')
                                 ])
    confirm_password = PasswordField("Confirm passowrd")
Exemple #26
0
class LoanForm(Form):
    owner = SelectField("Book owner",
                        validators=[Required()],
                        choices=members())
    borrower = SelectField("Book borrower",
                           validators=[Required()],
                           choices=members())
    book = SelectField("Book", validators=[Required()], choices=books())
    date = TextField("Date of the loan", validators=[Required()])

    def save(self):
        owner = Member.get_by(foaf_givenName=self.owner.data).one()
        borrower = Member.get_by(foaf_givenName=self.borrower.data).one()
        book = Book.get_by(dcterms_identifier=self.book.data).one()
        create_loan(owner, borrower, book, self.date.data)
        book_title = dict(self.book.choices)[self.book.data]
        flash("%s have successfully borrowed %s" %
              (self.borrower.data, book_title))
Exemple #27
0
class BookForm(Form):
    title = TextField("Title", validators=[Required()])
    authors = TextField("Authors", validators=[Required()])
    publisher = TextField("Publisher", validators=[Required()])
    year = TextField("Publication year")
    subject = TextField("What the book is about ? (separated by commas")
    owner = SelectField("Who owns this book ?", choices=members())

    def save(self):
        book = create_book(None, self.title.data, self.authors.data,
                           self.publisher.data, self.year.data,
                           self.subject.data)

        # get back the member resource
        owner = Member.get_by(foaf_givenName=self.owner.data).one()
        owner.book_ownsCopyOf.append(book)
        owner.update()
        flash("The book %s have been added" % self.title.data)
Exemple #28
0
class LoginForm(Form):
    email = TextField('Email address', validators=[Required(), Email()])
    password = PasswordField('Password', validators=[Required()])

    def getuser(self, name):
        return User.query.filter_by(email=name).first()

    def validate_username(self, field):
        existing = self.getuser(field.data)
        if existing is None:
            raise ValidationError, "No user account for that email address"
        if not existing.active:
            raise ValidationError, "This user account is disabled"

    def validate_password(self, field):
        user = self.getuser(self.email.data)
        if user is None or not user.check_password(field.data):
            raise ValidationError, "Incorrect password"
        self.user = user
Exemple #29
0
class PageAddTagForm(Form):
    tag = TextField(
        'Tag',
        validators=[
            Required(),
            Regexp(regex=r'[a-z0-9]{1,80}',
                   flags=re.IGNORECASE,
                   message='Invalid Tag. Only able to use a-z and 0-9'),
        ])
    submit = SubmitField('Submit')
class RegisterForm(Form):
    email = EmailField('Email Address',
                       validators=[],
                       description="Enter your email address.")
    password = PasswordField('Password',
                             validators=[
                                 Required(),
                                 EqualTo('confirm',
                                         message='Passwords must match')
                             ])
    confirm = PasswordField('Repeat Password')