-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.py
50 lines (40 loc) · 1.29 KB
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# -*- coding: utf-8 -*-
import json
import logging
import colander
from flask import (
flash,
Flask,
redirect,
render_template,
request,
url_for
)
from flask.ext.session import Session
from jsonresume.schema.resume import Resume as ResumeSchema
app = Flask(__name__)
app.secret_key = 'RQtlBBBfHh9QbMSC99Ds' # bad example, we should perhaps put it in an env var
app.config['SESSION_TYPE'] = 'filesystem'
app.debug = True
sess = Session()
sess.init_app(app)
def allowed_file(filename):
return '.' in filename and filename.rsplit('.', 1)[1] == 'json'
@app.route('/', methods=['GET', 'POST'])
def submit_form():
if request.method == 'GET':
return render_template('form.html')
elif request.method == 'POST':
fil = request.files['file']
if fil and allowed_file(fil.filename):
try:
data = json.load(fil)
ResumeSchema().deserialize(data)
flash("Success", category="success")
except colander.Invalid as e:
logging.exception("Invalid JSON resume content")
flash(e, category="error")
else:
# no file detected
flash('Please submit a JSON resume in the form', category="warning")
return redirect(url_for('submit_form'))