Esempio n. 1
0
class ProfileForm(Form):
    fullname = wtforms.TextField('Full name',
                                 validators=[wtforms.validators.Required()])
    email = wtforms.fields.html5.EmailField('Email address',
                                            validators=[
                                                wtforms.validators.Required(),
                                                wtforms.validators.Email(),
                                                ValidEmailDomain()
                                            ])
    username = wtforms.TextField('Username',
                                 validators=[wtforms.validators.Required()])
    description = wtforms.TextAreaField('Bio')
    timezone = wtforms.SelectField('Timezone',
                                   validators=[wtforms.validators.Required()],
                                   choices=timezones)

    def __init__(self, *args, **kwargs):
        super(ProfileForm, self).__init__(*args, **kwargs)
        self.existing_email = None

    def validate_username(self, field):
        ## Usernames are now mandatory. This should be commented out:
        # if not field.data:
        #     field.data = None
        #     return
        field.data = field.data.lower()  # Usernames can only be lowercase
        if not valid_username(field.data):
            raise wtforms.ValidationError(
                "Usernames can only have alphabets, numbers and dashes (except at the ends)"
            )
        if field.data in current_app.config['RESERVED_USERNAMES']:
            raise wtforms.ValidationError("This name is reserved")
        existing = User.query.filter_by(username=field.data).first()
        if existing is not None and existing.id != self.edit_id:
            raise wtforms.ValidationError("This username is taken")
        existing = Organization.query.filter_by(name=field.data).first()
        if existing is not None:
            raise wtforms.ValidationError("This username is taken")

    # TODO: Move to function and place before ValidEmailDomain()
    def validate_email(self, field):
        field.data = field.data.lower()  # Convert to lowercase
        existing = UserEmail.query.filter_by(email=field.data).first()
        if existing is not None and existing.user != self.edit_obj:
            raise wtforms.ValidationError(
                "This email address has been claimed by another user.")
Esempio n. 2
0
class ProfileForm(Form):
    fullname = wtforms.TextField('Full name',
                                 validators=[wtforms.validators.Required()])
    email = wtforms.fields.html5.EmailField('Email address',
                                            validators=[
                                                wtforms.validators.Required(),
                                                wtforms.validators.Email(),
                                                ValidEmailDomain()
                                            ])
    username = AnnotatedNullTextField(
        'Username',
        validators=[wtforms.validators.Required()],
        prefix=u"https://hasgeek.com/…")
    timezone = wtforms.SelectField('Timezone',
                                   validators=[wtforms.validators.Required()],
                                   choices=timezones)

    def validate_username(self, field):
        ## Usernames are now mandatory. This should be commented out:
        # if not field.data:
        #     field.data = None
        #     return
        field.data = field.data.lower()  # Usernames can only be lowercase
        if not valid_username(field.data):
            raise wtforms.ValidationError(
                "Usernames can only have alphabets, numbers and dashes (except at the ends)"
            )
        if field.data in current_app.config.get('RESERVED_USERNAMES', []):
            raise wtforms.ValidationError("This name is reserved")
        if not self.edit_user.is_valid_username(field.data):
            raise wtforms.ValidationError("This username is taken")

    # TODO: Move to function and place before ValidEmailDomain()
    def validate_email(self, field):
        field.data = field.data.lower()  # Convert to lowercase
        existing = UserEmail.get(email=field.data)
        if existing is not None and existing.user != self.edit_obj:
            raise wtforms.ValidationError(
                "This email address has been claimed by another user")
Esempio n. 3
0
class NewEmailAddressForm(Form):
    email = wtforms.fields.html5.EmailField('Email address',
                                            validators=[
                                                wtforms.validators.Required(),
                                                wtforms.validators.Email(),
                                                ValidEmailDomain()
                                            ])

    # TODO: Move to function and place before ValidEmailDomain()
    def validate_email(self, field):
        field.data = field.data.lower()  # Convert to lowercase
        existing = UserEmail.get(email=field.data)
        if existing is not None:
            if existing.user == g.user:
                raise wtforms.ValidationError(
                    "You have already registered this email address.")
            else:
                raise wtforms.ValidationError(
                    "This email address has already been claimed.")
        existing = UserEmailClaim.get(email=field.data, user=g.user)
        if existing is not None:
            raise wtforms.ValidationError(
                "This email address is pending verification.")
Esempio n. 4
0
class ListingForm(Form):
    """Form for new job posts"""
    job_headline = TextField(
        "Headline",
        description=
        "A single-line summary. This goes to the front page and across the network",
        validators=[
            validators.Required("A headline is required"),
            validators.Length(min=1,
                              max=100,
                              message="%(max)d characters maximum")
        ])
    job_type = RadioField(
        "Type",
        coerce=int,
        validators=[validators.Required("The job type must be specified")])
    job_category = RadioField(
        "Category",
        coerce=int,
        validators=[validators.Required("Select a category")])
    job_location = TextField(
        "Location",
        description=
        u'“Bangalore”, “Chennai”, “Pune”, etc or “Anywhere” (without quotes)',
        validators=[
            validators.Required(
                u"If this job doesn’t have a fixed location, use “Anywhere”"),
            validators.Length(min=3,
                              max=80,
                              message="%(max)d characters maximum")
        ])
    job_relocation_assist = BooleanField("Relocation assistance available")
    job_description = RichTextField(
        "Description",
        description=
        u"Don’t just describe the job, tell a compelling story for why someone should work for you",
        validators=[
            validators.Required("A description of the job is required"),
            AllUrlsValid()
        ],
        tinymce_options={'convert_urls': True})
    job_perks = BooleanField("Job perks are available")
    job_perks_description = RichTextField(
        "Describe job perks",
        description=u"Stock options, free lunch, free conference passes, etc",
        validators=[AllUrlsValid()])
    job_how_to_apply = TextAreaField(
        "What should a candidate submit when applying for this job?",
        description=u"Example: “Include your LinkedIn and GitHub profiles.” "
        u"We now require candidates to apply through the job board only. "
        u"Do not include any contact information here. Candidates CANNOT "
        u"attach resumes or other documents, so do not ask for that",
        validators=[
            validators.Required(
                u"HasGeek does not offer screening services. "
                u"Please specify what candidates should submit")
        ])
    company_name = TextField(
        "Name",
        description=u"The name of the organization where the position is. "
        u"No intermediaries or unnamed stealth startups. Use your own real name if the company isn’t named "
        u"yet. We do not accept listings from third parties such as recruitment consultants. Such listings "
        u"may be removed without notice",
        validators=[
            validators.Required(
                u"This is required. Posting any name other than that of the actual organization is a violation of the ToS"
            ),
            validators.Length(
                min=4,
                max=80,
                message="The name must be within %(min)d to %(max)d characters"
            )
        ])
    company_logo = FileField(
        "Logo",
        description=
        u"Optional — Your company logo will appear at the top of your listing. "
        u"170px wide is optimal. We’ll resize automatically if it’s wider",
    )  # validators=[file_allowed(uploaded_logos, "That image type is not supported")])
    company_logo_remove = BooleanField("Remove existing logo")
    company_url = TextField("URL",
                            description=u"Example: http://www.google.com",
                            validators=[optional_url,
                                        AllUrlsValid()])
    hr_contact = RadioField(
        u"Is it okay for recruiters and other "
        u"intermediaries to contact you about this listing?",
        coerce=getbool,
        description=u"We’ll display a notice to this effect on the listing",
        default=0,
        choices=[(0, u"No, it is NOT OK"),
                 (1, u"Yes, recruiters may contact me")])
    # Deprecated 2013-11-20
    # poster_name = TextField("Name",
    #     description=u"This is your name, for our records. Will not be revealed to applicants",
    #     validators=[validators.Required("We need your name")])
    poster_email = EmailField(
        "Email",
        description=
        u"This is where we’ll send your confirmation email and all job applications. "
        u"We recommend using a shared email address such as [email protected]. "
        u"Listings are classified by your email domain. "
        u"Your email address will not be revealed to applicants until you respond",
        validators=[
            validators.Required(
                "We need to confirm your email address before the job can be listed"
            ),
            validators.Length(min=5,
                              max=80,
                              message="%(max)d characters maximum"),
            validators.Email(
                "That does not appear to be a valid email address"),
            ValidEmailDomain()
        ])
    collaborators = HiddenMultiField(
        u"Collaborators",
        description=
        u"If someone is helping you evaluate candidates, type their names here. "
        u"They must have a HasGeek account. They will not receive email notifications "
        u"— use a shared email address above for that — but they will be able to respond "
        u"to candidates who apply")

    def validate_company_name(form, field):
        if len(field.data) > 5:
            caps = len(CAPS_RE.findall(field.data))
            small = len(SMALL_RE.findall(field.data))
            if small == 0 or caps / float(small) > 0.8:
                raise ValidationError(
                    "Surely your company isn't named in uppercase?")

    def validate_company_logo(form, field):
        if not request.files['company_logo']:
            return
        try:
            g.company_logo = process_image(request.files['company_logo'])
        except IOError, e:
            raise ValidationError(e.message)
        except KeyError, e:
            raise ValidationError("Unknown file format")