Пример #1
0
def get_waiver_name(email):
    uid = auth_utils.get_user_id(email)
    query = """ SELECT waiver_path FROM caltech_waiver WHERE user_id = %s"""
    with flask.g.pymysql_db.cursor() as cursor:
        cursor.execute(query, [uid])
        res = cursor.fetchone()
    return res.get('waiver_path', "")
Пример #2
0
def update_waiver_status(waiver_type, user_id):
    if not auth_utils.check_login() or not auth_utils.check_admin(
            flask.session['username']):
        return flask.redirect(flask.url_for("home"))
    helpers.update_waiver_status(
        user_id, flask.request.form.get('new_status'),
        auth_utils.get_user_id(flask.session['username']), waiver_type)
    flask.flash('Status has been updated')
    return flask.redirect(
        flask.url_for('.view_caltech_waiver', user_id=user_id))
Пример #3
0
def waivers():
    if not auth_utils.check_login():
        return auth_utils.login_redirect()
    email = flask.session['username']
    user_id = auth_utils.get_user_id(email)
    return flask.render_template(
        "waivers.html",
        RSVPed=(judging_helpers.get_status(user_id)['status'] == "RSVPed"),
        caltech_waiver=helpers.get_waiver_status(user_id, "caltech_waiver"),
        medical_info=helpers.get_waiver_status(user_id, "medical_info"))
Пример #4
0
def uploaded_waiver_file(filename, waiver_type):
    ''' 
    This function should be collapsed with the function below
    '''
    if not auth_utils.check_login():
        return flask.redirect(flask.url_for("home"))

    cur_user_waiver = helpers.get_waiver(
        auth_utils.get_user_id(flask.session['username']), waiver_type)

    if cur_user_waiver != filename and not auth_utils.check_admin(
            flask.session['username']):
        return flask.redirect(flask.url_for("home"))

    folder_path = "WAIVERS" if waiver_type == "caltech_waiver" else "MEDICAL"
    uploads = os.path.join(flask.current_app.root_path,
                           flask.current_app.config[folder_path])
    return flask.send_from_directory(uploads, filename, as_attachment=False)
Пример #5
0
def general_waiver(waiver_type, link, title):
    if not auth_utils.check_login():
        return auth_utils.login_redirect()
    email = flask.session['username']
    # TODO: implement
    #status = helpers.submitted_caltech_waiver(email, waiver_type)
    form_info = judging_helpers.get_waiver(auth_utils.get_user_id(email),
                                           waiver_type)
    form_info['waiver_name'] = form_info[waiver_type + '_url'].split("/")[-1]
    form_info['waiver_url'] = form_info[waiver_type + '_url']
    form_info['waiver_update'] = flask.url_for(
        ".update_{0}".format(waiver_type))
    form_info['waiver_type'] = waiver_type
    return flask.render_template("caltech_waiver.html",
                                 form_info=form_info,
                                 waiver_type=waiver_type,
                                 link=link,
                                 title=title)
Пример #6
0
def save_info(email, waiver_file, app_folder, waiver_type):
    uid = auth_utils.get_user_id(email)
    first_name, last_name = get_full_name(uid)
    waiver_file_name = last_name + "_" + first_name + "_" + str(uid) + ".pdf"
    waiver_root_path = os.path.join(flask.current_app.root_path,
                                    flask.current_app.config[app_folder])
    waiver_path = os.path.join(waiver_root_path, waiver_file_name)
    print(waiver_file, allowed_file(waiver_file))
    if waiver_file and allowed_file(waiver_file):
        if os.path.exists(waiver_path):
            os.remove(waiver_path)
        waiver_file.save(waiver_path)
        query = "INSERT INTO {0}(user_id, {0}_path, {0}_status, submitted_time) VALUES (%s, %s, 'Submitted', NOW()) ON DUPLICATE KEY UPDATE {0}_status =  'Submitted', submitted_time = NOW()".format(
            waiver_type)

        with flask.g.pymysql_db.cursor() as cursor:
            cursor.execute(query, [uid, waiver_file_name])
        return waiver_path
    return ""