-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
67 lines (48 loc) · 1.59 KB
/
app.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# -*- coding: utf-8 -*-
import os
import time
from flask import Flask
from flask import render_template
from flask_wtf import FlaskForm
from flask_wtf.csrf import CSRFProtect
from flask_wtf.file import FileField, FileRequired
import schedulingLP
app = Flask(__name__)
app.secret_key = "topsecretlol"
csrf = CSRFProtect(app)
class SchedulingForm(FlaskForm):
xlsxfile = FileField("XLSX file", [FileRequired()])
@app.route("/", methods=["GET", "POST"])
def root():
form = SchedulingForm()
if form.validate_on_submit():
timestamp = time.strftime("%Y-%m-%d %H:%M:%S %Z", time.gmtime())
# get the XLSX file's bytes
data = form.xlsxfile.data
# do the deed!
try:
status, result = schedulingLP.run(xlsx=data)
except:
status = 'Failed'
result = None
# result dict structure, each key is the name of a prof:
# {'profname':{'courses': {'course1': int,
# 'course2': int, ...},
# 'TLC': float,
# 'capacity': int, }
# }
# Create the results page, this time with the result data
response = render_template(
"scheduling.html.j2",
form=form,
filename=form.xlsxfile.data.filename,
timestamp=timestamp,
status=status,
result=result,
)
else:
# invalid submission or fresh reloaded page
response = render_template("scheduling.html.j2", form=form)
return response
if __name__ == "__main__":
app.run(debug=True)