Ejemplo n.º 1
0
def upload_cv_upload(person_id, signature):
    candidate = lookups.lookup_candidate(app.config, person_id)
    if 'error' in candidate:
        flask.flash(candidate['error'], 'danger')
        return error()

    if not identity.check_signature(app.secret_key, person_id, signature):
        flask.flash("Sorry! That web link isn't right. Can you check you copied it properly from your email?", 'warning')
        return error()

    f = flask.request.files['files']
    if not f:
        flask.flash("No files were received. Please try again, or contact us for help.", 'danger')
        return flask.redirect(flask.request.path)

    secure_filename = werkzeug.secure_filename(f.filename)
    data = f.read()
    size = len(data)

    print("saving CV to S3: candidate:", person_id, "uploaded file:", secure_filename, size, "bytes")
    file_url = lookups.add_cv(app.config, person_id, data, secure_filename)

    # force reloading of all data for now, so CV appears in the redirect
    with app.app_context():
        cache.clear()

    flask.flash("Thanks! Your CV has been successfully uploaded. It will take about half an hour to appear on the site.", 'success')
    flask.flash("Friends who are also candidates? Please tell them to upload their CV too!", 'info')
    return flask.redirect("/about")
Ejemplo n.º 2
0
def show_cv(person_id):
    candidate = lookups.lookup_candidate(app.config, person_id)
    if 'error' in candidate:
        flask.flash(candidate['error'], 'danger')
        return error()

    current_cv = lookups.get_current_cv(app.config, candidate['id'])
    if current_cv is None:
        return flask.redirect(flask.url_for('upload_cv', person_id=person_id))

    current_thumb = lookups.get_current_thumb(app.config, candidate['id'])
    og_image = current_thumb['url'] if current_thumb is not None else False
    og_description = "Before you vote, look at CVs like {}'s! This site helps MP candidates share their CV with voters.".format(
        candidate['name']
    )

    # Go back to where we came from if that was our site
    # (e.g. to all page, home page or candidates page)
    # Default to candidates page.
    more_link = flask.url_for("candidates", constituency_id=candidate['constituency_id'])
    refer = flask.request.referrer
    host_url = flask.request.host_url
    if refer and host_url:
        if refer.startswith(host_url):
            more_link = refer

    return flask.render_template("show_cv.html",
            candidate=candidate,
            cv=current_cv,
            og_image=og_image,
            og_description=og_description,
            tw_large_card=True,
            more_link=more_link
        )
Ejemplo n.º 3
0
def upload_cv_upload(person_id, signature):
    candidate = lookups.lookup_candidate(person_id)
    if 'error' in candidate:
        flask.flash(candidate['error'], 'danger')
        return error()

    signed_again = identity.sign_person_id(app.secret_key, person_id)
    if signature != signed_again:
        flask.flash(
            "Sorry! That web link isn't right. Can you check you copied it properly from your email?",
            'warning')
        return error()

    f = flask.request.files['files']
    if not f:
        flask.flash(
            "No files were received. Please try again, or contact us for help.",
            'danger')
        return flask.redirect(flask.request.path)

    secure_filename = werkzeug.secure_filename(f.filename)
    data = f.read()
    size = len(data)

    print("saving CV to S3: candidate:", person_id, "uploaded file:",
          secure_filename, f.content_type, size, "bytes")
    file_url = lookups.add_cv(app.config, person_id, data, secure_filename,
                              f.content_type)

    flask.flash(
        "Thanks! Your CV has been successfully uploaded. You can share this page on social media. We'd love it if you tell any friends who are candidates to upload theirs too!",
        'success')
    successful_link = flask.url_for('show_cv', person_id=person_id)
    return flask.redirect(successful_link)
Ejemplo n.º 4
0
def upload_cv_admin(person_id, admin_key):
    if admin_key != app.config['ADMIN_KEY']:
        flask.flash("Administrator permissions denied.", 'danger')
        return error()

    candidate = lookups.lookup_candidate(app.config, person_id)
    if 'error' in candidate:
        flask.flash(candidate['error'], 'danger')
        return error()

    link = identity.generate_upload_url(app.secret_key, person_id)
    return flask.redirect(link)
Ejemplo n.º 5
0
def upload_cv(person_id):
    candidate = lookups.lookup_candidate(person_id)
    if 'error' in candidate:
        flask.flash(candidate['error'], 'danger')
        return flask.redirect(flask.url_for('error'))

    if flask.request.method == 'POST':
        identity.send_upload_cv_confirmation(app, mail, candidate['id'],
                                             candidate['email'],
                                             candidate['name'])
        return flask.render_template("check_email.html")

    return flask.render_template("upload_cv.html", candidate=candidate)
Ejemplo n.º 6
0
def show_cv(person_id):
    candidate = lookups.lookup_candidate(person_id)
    if 'error' in candidate:
        flask.flash(candidate['error'], 'danger')
        return error()

    cvs = lookups.get_cv_list(app.config, person_id)
    if cvs == []:
        flask.flash("We don't yet have a CV for that candidate", 'danger')
        return flask.redirect('/candidates')

    current_cv = cvs[0]

    return flask.render_template("show_cv.html",
                                 candidate=candidate,
                                 cv=current_cv)
Ejemplo n.º 7
0
def upload_cv(person_id):
    candidate = lookups.lookup_candidate(app.config, person_id)
    if 'error' in candidate:
        flask.flash(candidate['error'], 'danger')
        return error()

    if flask.request.method == 'POST':
        identity.send_upload_cv_confirmation(app, mail, candidate['id'], candidate['email'], candidate['name'])
        return flask.render_template("check_email.html", candidate=candidate)

    already_got = False
    if lookups.get_current_cv(app.config, person_id):
        already_got = True

    return flask.render_template("upload_cv.html", candidate=candidate,
        og_image = flask.url_for('static', filename='what-is-cv.png', _external=True),
        already_got = already_got
    )
Ejemplo n.º 8
0
def upload_cv_confirmed(person_id, signature):
    candidate = lookups.lookup_candidate(app.config, person_id)
    if 'error' in candidate:
        flask.flash(candidate['error'], 'danger')
        return error()

    if not identity.check_signature(app.secret_key, person_id, signature):
        flask.flash("Sorry! That web link isn't right. Can you check you copied it properly from your email?", 'warning')
        return error()

    current_cv = lookups.get_current_cv(app.config, candidate['id'])

    if candidate['email'] is not None:
        # this is their default email now
        flask.session['email'] = candidate['email']

    upload_link = flask.url_for('upload_cv_upload', person_id=person_id, signature=signature)

    return flask.render_template("upload_cv_confirmed.html", candidate=candidate,
         upload_link=upload_link, current_cv=current_cv)
Ejemplo n.º 9
0
def upload_cv_upload(person_id, signature):
    candidate = lookups.lookup_candidate(person_id)
    if 'error' in candidate:
        print("error in candidate", person_id)
        return json.dumps({'error': candidate['error']})

    signed_again = identity.sign_person_id(app.secret_key, person_id)
    if signature != signed_again:
        print("error in signature", person_id, signature)
        return json.dumps({'error': 'Signature token wrong'})

    f = flask.request.files['file']
    if not f:
        print("upload missing", person_id)
        return json.dumps({'error': 'Upload not received'})

    print("filename", f.filename)
    print("content_type", f.content_type)

    return "{ 'moo': 1 }"
Ejemplo n.º 10
0
def upload_cv_confirmed(person_id, signature):
    candidate = lookups.lookup_candidate(person_id)
    if 'error' in candidate:
        flask.flash(candidate['error'], 'danger')
        return flask.redirect(flask.url_for('error'))

    signed_again = identity.sign_person_id(app.secret_key, person_id)
    if signature != signed_again:
        flask.flash(
            "Sorry! That web link isn't right. Can you check you copied it properly from your email?",
            'warning')
        return flask.redirect(flask.url_for('error'))

    upload_link = flask.url_for('upload_cv_upload',
                                person_id=person_id,
                                signature=signature)

    return flask.render_template("upload_cv_confirmed.html",
                                 candidate=candidate,
                                 upload_link=flask.request.path)