Esempio n. 1
0
def info_check(parent, request, ob):
    """
    Receive and check what the user entered; save the name & email on
    the newly created object.
    """

    errors = {}
    required = info_required(parent, request)

    # check Captcha/reCaptcha
    if required['captcha']:
        contact_word = request.form.get('contact_word', '')
        captcha_errors = parent.validateCaptcha(contact_word, request)
        if captcha_errors:
            errors['captcha'] = captcha_errors

    # check name/email, if they are required
    if required['name_and_email']:
        info = {
            'name': request.form.get('submitter-name', ''),
            'email': request.form.get('submitter-email', ''),
        }

        request.SESSION['submitter-info'] = info

        name_and_email_errors = {}
        if not info['name']:
            name_and_email_errors['submitter-name'] = (
                    ["Submitter name is mandatory"])
        if not info['email']:
            name_and_email_errors['submitter-email'] = (
                    ["Submitter email is mandatory"])
        elif not is_valid_email(info['email']):
            name_and_email_errors['submitter-email'] = (
                    ["Invalid email address"])

        if name_and_email_errors:
            errors.update(name_and_email_errors)
        else:
            ob.submitter_info = info

    return errors
Esempio n. 2
0
 def is_valid_email(self, email_str):
     """ Check validity of email address """
     return is_valid_email(email_str)