Ejemplo n.º 1
0
class RegisterForm(Form):
    fullname = wtf.TextField('Full name', validators=[wtf.Required()])
    email = wtf.html5.EmailField('Email address',
                                 validators=[wtf.Required(),
                                             wtf.Email()])
    username = wtf.TextField('Username (optional)',
                             validators=[wtf.Optional()])
    password = wtf.PasswordField('Password', validators=[wtf.Required()])
    confirm_password = wtf.PasswordField(
        'Confirm password',
        validators=[wtf.Required(), wtf.EqualTo('password')])
    recaptcha = wtf.RecaptchaField(
        'Are you human?', description="Type both words into the text box")

    def validate_username(self, field):
        if field.data in RESERVED_USERNAMES:
            raise wtf.ValidationError, "That name is reserved"
        if not valid_username(field.data):
            raise wtf.ValidationError(
                u"Invalid characters in name. Names must be made of ‘a-z’, ‘0-9’ and ‘-’, without trailing dashes"
            )
        existing = User.query.filter_by(username=field.data).first()
        if existing is not None:
            raise wtf.ValidationError("That username is taken")

    def validate_email(self, field):
        existing = UserEmail.query.filter_by(email=field.data).first()
        if existing is not None:
            raise wtf.ValidationError(
                Markup(
                    'This email address is already registered. Do you want to <a href="%s">login</a> instead?'
                    % url_for('login')))
Ejemplo n.º 2
0
class ExpenseForm(Form):
    """
    Create or edit an expense line item.
    """
    id = wtf.IntegerField(u"Id", validators=[wtf.Optional()])
    date = wtf.DateField(u"Date", validators=[wtf.Required()])
    category = wtf.QuerySelectField(u"Category",
                                    validators=[wtf.Required()],
                                    query_factory=sorted_categories,
                                    get_label='title',
                                    allow_blank=True)
    description = wtf.TextField(u"Description", validators=[wtf.Required()])
    amount = wtf.DecimalField(
        u"Amount", validators=[wtf.Required(),
                               wtf.NumberRange(min=0)])

    def validate_id(self, field):
        # Check if user is authorized to edit this expense.
        if field.data:
            expense = Expense.query.get(field.data)
            if not expense:
                raise wtf.ValidationError("Unknown expense")
            if expense.report.user != g.user:
                raise wtf.ValidationError(
                    "You are not authorized to edit this expense")

    def validate_amount(self, field):
        if field.data < Decimal('0.01'):
            raise wtf.ValidationError("Amount should be non-zero")
Ejemplo n.º 3
0
class ContentForm(Form):
    previous_id = wtf.HiddenField(u"Previous revision")
    title = wtf.TextField(u"Title", validators=[wtf.Required()])
    name = wtf.TextField(u"URL name", validators=[wtf.Optional(), valid_name])
    description = wtf.TextAreaField(u"Summary",
                                    description=u"Summary of this page")
    content = RichTextField(u"Page content",
                            linkify=False,
                            buttons1=richtext_buttons1,
                            valid_elements=richtext_valid_elements,
                            sanitize_tags=richtext_sanitize_tags,
                            sanitize_attributes=richtext_sanitize_attributes)
    template = wtf.TextField(
        "Template",
        validators=[wtf.Required()],
        default='page.html',
        description=u"Template with which this page will be rendered.")
    properties = DictField(u"Properties")

    def validate_previous_id(self, field):
        if not field.data:
            field.data = None
        else:
            try:
                field.data = int(field.data)
            except ValueError:
                raise wtf.ValidationError("Unknown previous revision")

    def validate_name(self, field):
        # TODO
        pass
Ejemplo n.º 4
0
class UserRegisterForm(wtf.Form):
    username = wtf.TextField(
        'Username',
        validators=[
            wtf.Required(),
            wtf.Length(min=2, max=50),
            wtf.Regexp(
                '^[a-zA-Z0-9_]*$',
                message=
                ('Username must only contain a to z, 0 to 9, and underscores.'
                 ))
        ],
        description=(
            'Your username is public and used as part of your project name.'))
    email = wtf.TextField('Email',
                          validators=[wtf.Required(),
                                      wtf.validators.Email()])
    password = wtf.PasswordField('Password',
                                 validators=[
                                     wtf.Required(),
                                     wtf.Length(5),
                                     wtf.EqualTo('confirm',
                                                 'Passwords do not match.'),
                                 ])
    confirm = wtf.PasswordField('Confirm Password')

    def validate_username(form, field):
        from notifico.views.account import _reserved

        username = field.data.strip().lower()
        if username in _reserved or User.username_exists(username):
            raise wtf.ValidationError('Sorry, but that username is taken.')
Ejemplo n.º 5
0
class SignUpForm(Form):
    """Sign up form."""

    name = wtf.TextField('Name',
                         validators=[
                             wtf.Required(),
                             wtf.Length(max=100),
                         ],
                         description='e.g. Johnny')
    primary_email = wtf.TextField('E-mail',
                                  validators=[
                                      wtf.Required(),
                                      wtf.Email(),
                                      wtf.Length(max=100),
                                  ])
    password = wtf.PasswordField('Password', validators=[
        wtf.Required(),
    ])
    password_check = wtf.PasswordField('Password once more',
                                       validators=[
                                           wtf.EqualTo(
                                               'password',
                                               message='Passwords must match'),
                                       ],
                                       description='protection against typos')
Ejemplo n.º 6
0
class VenueForm(Form):
    title = wtf.TextField("Name",
                          description="Name of the venue",
                          validators=[wtf.Required()])
    description = RichTextField("Notes",
                                description="Notes about the venue",
                                content_css="/static/css/editor.css")
    address1 = wtf.TextField("Address (line 1)", validators=[wtf.Required()])
    address2 = wtf.TextField("Address (line 2)", validators=[wtf.Optional()])
    city = wtf.TextField("City", validators=[wtf.Required()])
    state = wtf.TextField("State", validators=[wtf.Optional()])
    postcode = wtf.TextField("Post code", validators=[wtf.Optional()])
    country = wtf.SelectField("Country",
                              validators=[wtf.Required()],
                              choices=country_codes,
                              default="IN")
    latitude = wtf.DecimalField(
        "Latitude",
        places=None,
        validators=[wtf.Optional(), wtf.NumberRange(-90, 90)])
    longitude = wtf.DecimalField(
        "Longitude",
        places=None,
        validators=[wtf.Optional(), wtf.NumberRange(-180, 180)])
    profile_id = wtf.SelectField("Owner",
                                 description="The owner of this listing",
                                 coerce=int,
                                 validators=[wtf.Required()])
Ejemplo n.º 7
0
class ResourceActionForm(Form):
    """
    Edit an action associated with a resource
    """
    name = wtf.TextField(
        'Action name',
        validators=[wtf.Required()],
        description="Name of the action as a single word in lower case. "
        "This is provided by applications as part of the scope in the form "
        "'resource/action' when requesting access to a user's resources. "
        "Read actions are implicit when applications request just 'resource' "
        "in the scope and do not need to be specified as an explicit action.")
    title = wtf.TextField(
        'Title',
        validators=[wtf.Required()],
        description='Action title that is displayed to users')
    description = wtf.TextAreaField(
        'Description',
        description='An optional description of what the action is')

    def validate_name(self, field):
        if not valid_username(field.data):
            raise wtf.ValidationError("Name contains invalid characters.")

        existing = ResourceAction.query.filter_by(
            name=field.data, resource=self.edit_resource).first()
        if existing and existing.id != self.edit_id:
            raise wtf.ValidationError(
                "An action with that name already exists for this resource")
Ejemplo n.º 8
0
class UserLoginForm(wtf.Form):
    username = wtf.TextField('Username', validators=[wtf.Required()])
    password = wtf.PasswordField('Password', validators=[wtf.Required()])

    def validate_password(form, field):
        if not User.login(form.username.data, field.data):
            raise wtf.ValidationError('Incorrect username and/or password.')
Ejemplo n.º 9
0
class ParticipantForm(Form):
    skill_levels = [('Beginner', 'Beginner'), ('Intermediate', 'Intermediate'),
                    ('Advanced', 'Advanced')]

    reason_to_join = RichTextField(
        "Reason To Join",
        description="Why would you love to join Hacknight",
        validators=[wtf.Required()],
        content_css="/static/css/editor.css")
    phone_no = wtf.TextField(
        "Telephone No",
        description="Telephone No",
        validators=[wtf.Required(),
                    wtf.validators.length(max=15)])
    email = wtf.html5.EmailField(
        "Email",
        description="Email Address, We will never spam you .",
        validators=[wtf.Required(),
                    wtf.validators.length(max=80)])
    job_title = wtf.TextField(
        "Job Title",
        description="What is your job title? E.G: Senior Software "
        "Engineer at Awesome company",
        validators=[wtf.Required(),
                    wtf.validators.length(max=120)])
    company = wtf.TextField(
        "Company",
        description="Company Name",
        validators=[wtf.Optional(),
                    wtf.validators.length(max=1200)])
    skill_level = wtf.RadioField("Skill Level",
                                 description="What is your skill level?",
                                 choices=skill_levels)
Ejemplo n.º 10
0
class SigninForm(wtf.Form):
    email = wtf.TextField('email',
                          validators=[
                              wtf.Required(message=u'请填写电子邮件'),
                              wtf.Email(message=u'无效的电子邮件')
                          ])
    password = wtf.PasswordField('password',
                                 validators=[
                                     wtf.Required(message=u'请填写密码'),
                                     wtf.Length(min=5,
                                                max=20,
                                                message=u'密应应为5到20位字符')
                                 ])
    next = wtf.HiddenField('next')
    remember = wtf.BooleanField('remember')

    openid_identifier = wtf.HiddenField('openid_identifier')
    openid_provider = wtf.HiddenField('openid_provider')

    def __init__(self, *args, **kargs):
        wtf.Form.__init__(self, *args, **kargs)
        self.user = None

    def validate(self):
        # 验证邮箱是否注册
        if wtf.Form.validate(self):
            user = get_user(email=self.email.data)
            if not user:
                self.email.errors.append(u'该邮箱尚未在本站注册')
            elif not user.check_password(self.password.data):
                self.password.errors.append(u'密码错误')
            else:
                self.user = user

        return len(self.errors) == 0
Ejemplo n.º 11
0
class UserGroupForm(wtf.Form):
    name = wtf.TextField('URL name', validators=[wtf.Required()])
    title = wtf.TextField('Title', validators=[wtf.Required()])
    users = wtf.TextAreaField(
        'Users',
        validators=[wtf.Required()],
        description="Usernames or email addresses, one per line")
Ejemplo n.º 12
0
class FragmentForm(Form):
    """
    A fragment form is like a content form but without a summary or template.
    """
    previous_id = wtf.HiddenField(u"Previous revision")
    title = wtf.TextField(u"Title", validators=[wtf.Required()])
    name = wtf.TextField(u"URL name", validators=[wtf.Required(), valid_name])
    content = RichTextField(u"Page content",
                            linkify=False,
                            tinymce_options=tinymce_options,
                            sanitize_tags=richtext_sanitize_tags,
                            sanitize_attributes=richtext_sanitize_attributes)
    properties = DictField(u"Properties")

    def validate_previous_id(self, field):
        if not field.data:
            field.data = None
        else:
            try:
                field.data = int(field.data)
            except ValueError:
                raise wtf.ValidationError(u"Unknown previous revision")

    def validate_name(self, field):
        # TODO
        pass
Ejemplo n.º 13
0
class TeamForm(Form):
    title = wtf.TextField('Team name', validators=[wtf.Required()])
    users = wtf.QuerySelectMultipleField(
        'Users',
        validators=[wtf.Required()],
        query_factory=sorted_users,
        get_label='pickername',
        description=u"Select users who are part of this team")
Ejemplo n.º 14
0
class RedirectForm(Form):
    name = wtf.TextField(u"URL name", validators=[wtf.Optional(), valid_name])
    title = wtf.TextField(u"Title", validators=[wtf.Required()])
    redirect_url = wtf.TextField(u"Redirect URL", validators=[wtf.Required()])
    properties = DictField(u"Properties")

    def validate_name(self, field):
        # TODO
        pass
Ejemplo n.º 15
0
class SponsorForm(Form):
    title = wtf.TextField("Title", description="Title of the project",
        validators=[wtf.Required("A title is required")])
    description = RichTextField(u"Description",
        description="Detailed description of your project", width="50%",
        content_css="/static/css/editor.css")
    website = wtf.html5.URLField("Home Page",
        description="URL to the home page", validators=[wtf.Optional()])
    image_url = wtf.html5.URLField("Image URL", description="URL to the image",
        validators=[wtf.Required("An image is required.")])
Ejemplo n.º 16
0
class MapForm(Form):
    name = wtf.TextField(u"URL name", validators=[wtf.Required(), valid_name])
    title = wtf.TextField(u"Title", validators=[wtf.Required()])
    list = wtf.TextAreaField(
        'Map markers',
        validators=[wtf.Required()],
        description=u'Enter each row as a JSON object with name, title, url, '
        u'latitude, longitude, zoomlevel and marker. '
        u'The URL, zoomlevel and marker can be null, others cannot.')
    properties = DictField(u"Properties")
Ejemplo n.º 17
0
class ProjectForm(Form):
    title = wtf.TextField("Title", description="Title of the project", validators=[wtf.Required("A title is required"), wtf.validators.length(max=250)])
    blurb = wtf.TextField("Blurb", description="A single-line summary of the project",
        validators=[wtf.Required("A blurb is required"), wtf.validators.length(max=250)])
    description = RichTextField(u"Description",
        description="Detailed description of your project",
        content_css="/static/css/editor.css")
    participating = wtf.RadioField("Will you be participating?", default=1, coerce=getbool,
        choices=[(1,  u"I will be working on this project"),
                 (0, u"I’m proposing an idea for others to take up")])
Ejemplo n.º 18
0
class SignInForm(Form):
    """Sign in form."""

    email = wtf.TextField('E-mail',
                          validators=[
                              wtf.Required(),
                              wtf.Length(max=100),
                          ])
    password = wtf.PasswordField('Password', validators=[
        wtf.Required(),
    ])
Ejemplo n.º 19
0
class PostForm(wtf.Form):

    title = wtf.TextField('Title',
                          validators=[wtf.Required()],
                          description='This will be shown on the list.')
    body = wtf.TextAreaField('Body',
                             validators=[wtf.Required()],
                             description='Markdown format enabled.')
    sticky = wtf.BooleanField('Sticky',
                              description='Show this post always on top.')
    submit = wtf.SubmitField('Submit')
Ejemplo n.º 20
0
class ChangePasswordForm(wtf.Form):

    password = wtf.PasswordField('Password',
                                 validators=[
                                     wtf.Required(),
                                     wtf.EqualTo(
                                         'confirm',
                                         message='Passwords must match.')
                                 ])
    confirm = wtf.PasswordField('Repeat Password', validators=[wtf.Required()])
    submit = wtf.SubmitField('Save')
Ejemplo n.º 21
0
class ListForm(Form):
    name = wtf.TextField(u"URL name", validators=[wtf.Required(), valid_name])
    title = wtf.TextField(u"Title", validators=[wtf.Required()])
    list = wtf.TextAreaField(
        'Items',
        validators=[wtf.Required()],
        description=
        u'Enter each row as a JSON array with ["name", title", "url", "folder/node"]. '
        u'For nodes in the root folder, use "/node". To not include a node, use "".'
    )
    properties = DictField(u"Properties")
Ejemplo n.º 22
0
class ActivityForm(RedirectForm):
    title = wtf.TextField(u'活动标题', validators=[ \
            wtf.Required(message=u'请为活动填写一个标题')])
    content = wtf.TextAreaField(u'活动简介', validators=[ \
            wtf.Length(min=10, max=5000, message=u'简介至少10个字')])
    start_time = wtf.TextField(u'开始时间', validators=[ \
            wtf.Required(message=u'需要指定开始时间')])
    end_time = wtf.TextField(u'结束时间', validators=[ \
            wtf.Required(message=u'需要指定结束时间')])
    address = wtf.TextField(u'活动地点')
    latitude = wtf.HiddenField()
    longitude = wtf.HiddenField()
Ejemplo n.º 23
0
class SendEmailForm(Form):
    subject = wtf.TextField(
        "Subject",
        description="Subject for the email",
        validators=[wtf.Required(),
                    wtf.validators.length(max=250)])
    message = RichTextField(
        "Message",
        description=
        "Email message, only `FULLNAME` will be replaced with participant fullname",
        validators=[wtf.Required()])
    send_to = wtf.RadioField("Send email to", default=2, coerce=int)
Ejemplo n.º 24
0
class PasswordChangeForm(Form):
    old_password = wtf.PasswordField('Current password',
                                     validators=[wtf.Required()])
    password = wtf.PasswordField('New password', validators=[wtf.Required()])
    confirm_password = wtf.PasswordField(
        'Confirm password',
        validators=[wtf.Required(), wtf.EqualTo('password')])

    def validate_old_password(self, field):
        if g.user is None:
            raise wtf.ValidationError, "Not logged in"
        if not g.user.password_is(field.data):
            raise wtf.ValidationError, "Incorrect password"
Ejemplo n.º 25
0
class EventForm(Form):
    title = wtf.TextField(
        "Title",
        description="Name of the Event",
        validators=[wtf.Required(), wtf.NoneOf(values=["new"])])
    name = wtf.TextField(
        "URL name",
        validators=[
            wtf.Optional(),
            ValidName(),
            AvailableName(u"There’s another event with the same name")
        ],
        description="URL identifier, leave blank to autogenerate")
    blurb = wtf.TextField(
        "Blurb", description="Single line blurb introducing the event")
    description = RichTextField(
        "Description",
        description="Detailed description of the event",
        content_css="/static/css/editor.css")
    venue = wtf.QuerySelectField(
        "Venue",
        description=Markup(
            'Venue for this event (<a href="/venue/new">make new</a>)'),
        query_factory=lambda: Venue.query,
        get_label='title',
    )
    start_datetime = DateTimeField(
        "Start date/time",
        description="The date and time at which this event begins",
        validators=[wtf.Required()])
    end_datetime = DateTimeField(
        "End date/time",
        description="The date and time at which this event ends",
        validators=[wtf.Required()])
    ticket_price = wtf.TextField(
        "Ticket price",
        description="Entry fee, if any, to be paid at the venue")
    total_participants = wtf.IntegerField(
        "Venue capacity",
        description=
        "The number of people this venue can accommodate. Registrations will be closed after that. Use 0 to indicate unlimited capacity",
        default=50,
        validators=[wtf.Required()])
    website = wtf.TextField("Website",
                            description="Related Website (Optional)",
                            validators=[wtf.Optional()])

    def validate_end_datetime(self, field):
        if field.data < self.start_datetime.data:
            raise wtf.ValidationError(
                u"Your event can’t end before it starts.")
Ejemplo n.º 26
0
class UserPasswordForm(wtf.Form):
    old = wtf.PasswordField('Old Password', validators=[wtf.Required()])
    password = wtf.PasswordField('Password',
                                 validators=[
                                     wtf.Required(),
                                     wtf.Length(5),
                                     wtf.EqualTo('confirm',
                                                 'Passwords do not match.'),
                                 ])
    confirm = wtf.PasswordField('Confirm Password')

    def validate_old(form, field):
        if not User.login(g.user.username, field.data):
            raise wtf.ValidationError('Old Password is incorrect.')
Ejemplo n.º 27
0
class EditPassForm(RedirectForm):
    old_password = wtf.PasswordField(
        u'当前密码', validators=[wtf.Required(message=u'请提供当前密码')])
    password = wtf.PasswordField(u'新密码', validators=[ \
            wtf.Required(message=u'请填写新密码,不能少与5位字符'), \
            wtf.EqualTo('confirm', message=u'两次输入的密码不一致'), \
            wtf.Length(min=5, max=20, message=u'密码应为5到20位字符')
    ])
    confirm = wtf.PasswordField(u'确认密码',
                                validators=[wtf.Required(message=u'请再次输入新密码')])

    def validate_old_password(form, field):
        if not current_user.user.check_password(field.data):
            raise wtf.ValidationError(u'提供的原始密码不正确')
Ejemplo n.º 28
0
class SignupForm(wtf.Form):
    email = wtf.TextField('email',
                          validators=[
                              wtf.Required(message=u'请填写电子邮件'),
                              wtf.Email(message=u'无效的电子邮件')
                          ])
    nickname = wtf.TextField('nickname',
                             validators=[
                                 wtf.Required(message=u'请填写昵称'),
                                 wtf.Length(min=2,
                                            max=20,
                                            message=u'昵称应为2到20字符')
                             ])
    password = wtf.PasswordField('password',
                                 validators=[
                                     wtf.Required(message=u'请填写密码'),
                                     wtf.Length(min=5,
                                                max=20,
                                                message=u'密码应为5到20位字符')
                                 ])
    repassword = wtf.PasswordField('repassword',
                                   validators=[
                                       wtf.Required(message=u'请填写确认密码'),
                                       wtf.EqualTo('password',
                                                   message=u'两次输入的密码不一致')
                                   ])
    next = wtf.HiddenField('next')

    def __init__(self, *args, **kargs):
        wtf.Form.__init__(self, *args, **kargs)
        self.user = None

    def validate(self):
        wtf.Form.validate(self)

        # 验证邮箱是否注册
        if not self.email.errors:
            user = get_user(email=self.email.data)
            user and self.email.errors.append(u'该邮箱已被注册')

        self.user = User(email=self.email.data,
                         nickname=self.nickname.data,
                         openids=[
                             UserOpenID(provider=session['openid_provider'],
                                        openid=session['current_openid'])
                         ])
        self.user.set_password(self.password.data)
        self.user.info = UserInfo()

        return len(self.errors) == 0
Ejemplo n.º 29
0
class DataForm(Form):
    name = wtf.TextField(u"URL name", validators=[wtf.Required(), valid_name])
    title = wtf.TextField(u"Title", validators=[wtf.Required()])
    data = wtf.TextAreaField(u"Data",
                             validators=[wtf.Required()],
                             description=u"Enter JSON data")
    properties = DictField(u"Properties")

    def validate_data(self, field):
        # Check for exceptions when loading data
        parsed = simplejson.loads(field.data, use_decimal=True)
        if not isinstance(parsed, dict):
            raise wtf.ValidationError(
                u'This is not a valid JSON object. Use {"key": value, ...}')
Ejemplo n.º 30
0
class ProfileNewForm(ProfileFormBase, Form):
    fullname = wtf.TextField('Full name', validators=[wtf.Required()])
    email = wtf.html5.EmailField('Email address',
                                 validators=[wtf.Required(),
                                             wtf.Email()])
    username = wtf.TextField('Username (optional)')
    description = wtf.TextAreaField('Bio')

    def validate_email(self, field):
        existing = UserEmail.query.filter_by(email=field.data).first()
        self.existing_email = existing  # Save for later
        if existing is not None and existing.user != self.edit_obj:
            raise wtf.ValidationError(
                "This email address has been claimed by another user.")