fix resume uploading

This commit is contained in:
Cara Salter 2024-10-31 14:36:07 -04:00
parent 97f072ddb8
commit fb2dd9032b
2 changed files with 12 additions and 4 deletions

View file

@ -1,4 +1,4 @@
from flask import Blueprint, current_app, flash, jsonify, render_template, request from flask import Blueprint, current_app, flash, jsonify, redirect, render_template, request, url_for
from flask_login import current_user, login_required from flask_login import current_user, login_required
from werkzeug.utils import secure_filename from werkzeug.utils import secure_filename
@ -47,9 +47,17 @@ def resume():
filename = current_user.first_name.lower() + '_' + current_user.last_name.lower() + '_' + str( filename = current_user.first_name.lower() + '_' + current_user.last_name.lower() + '_' + str(
current_user.id) + '.' + resume.filename.split('.')[-1].lower() current_user.id) + '.' + resume.filename.split('.')[-1].lower()
filename = secure_filename(filename) filename = secure_filename(filename)
if not os.path.exists(current_app.config['UPLOAD_FOLDER']):
try:
os.makedirs(current_app.config['UPLOAD_FOLDER'])
except Exception:
flash("Error saving resume. Contact acm-sysadmin@wpi.edu")
return redirect(url_for("dashboard.home"))
resume.save(os.path.join(current_app.config['UPLOAD_FOLDER'], filename)) resume.save(os.path.join(current_app.config['UPLOAD_FOLDER'], filename))
return 'Resume uploaded! <a href="/dashboard">Return to dashboard</a>' flash("Resume uploaded!")
return "Something went wrong. If this keeps happening, contact hack@wpi.edu for assistance" return redirect(url_for("dashboard.home"))
flash("Something went wrong. If this keeps happening, contact hack@wpi.edu for assistance")
return redirect(url_for("dashboard.home"))
def allowed_file(filename): def allowed_file(filename):

View file

@ -33,7 +33,7 @@
</div> </div>
<hr/> <hr/>
<div class="row center justify-content-center"> <div class="row center justify-content-center">
<form method="post" action={{url_for('dashboard.resume')}}" <form method="post" action="{{url_for('dashboard.resume')}}"
enctype="multipart/form-data"> enctype="multipart/form-data">
{{ resform.csrf_token() }} {{ resform.csrf_token() }}
<p><b>If you'd like, add your resume to send to <p><b>If you'd like, add your resume to send to