Exemplo n.º 1
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()])
Exemplo n.º 2
0
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')
Exemplo n.º 3
0
class AddProjectForm(Form):
    title = TextField('Title', [validators.Required()])
    description = TextAreaField('Description', [validators.Length(min=15)])
    cat = TextField('Tags')
    types = SelectField('Type',
                        choices=[('me', 'Meeting'), ('bu', 'Business'),
                                 ('pa', 'Party')])
    loc = TextField('Location')
    date_end = DateField('Ending Date')
    goal_end = IntegerField('Goal')
    image_link = TextField('Image Link', validators=[URL(), Optional()])
    video_link = TextField('Video Link', validators=[URL(), Optional()])
    httext = TextAreaField('html_text')
    lat = HiddenField(default=0, validators=[Regexp('\d')])
    lng = HiddenField(default=0, validators=[Regexp('\d')])
    mark_location = BooleanField('Choose location on map')
Exemplo n.º 4
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")]
Exemplo n.º 5
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)
Exemplo n.º 6
0
class RegistrationForm(Form):
    username = TextField('Username', [validators.Length(min=4, max=25)])
    email = TextField('Email Address', [validators.Email()])
    password = PasswordField('New Password', [
        validators.Required(),
        validators.EqualTo('confirm', message='Passwords must match')
    ])
    confirm = PasswordField('Repeat Password')
    #accept_tos = BooleanField('I accept the TOS', [validators.Required()])
    image = TextField('Image URL', validators=[URL(), Optional()])
Exemplo n.º 7
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)
Exemplo n.º 8
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)
Exemplo n.º 9
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")