-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
62 lines (53 loc) · 2.09 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
from flask import Flask, render_template, request
from wtforms import Form, TextField, validators, FieldList, FormField
# App config.
#DEBUG = True
app = Flask(__name__)
app.config.from_object(__name__)
app.config['SECRET_KEY'] = '7d441f27d441f27567d441f2b6176a'
class ReusableForm(Form):
module = TextField('Module Grade:', validators=[validators.required()])
weight = TextField('Weighting:', validators=[validators.required()])
class BusinessForm(Form):
#name = StringField('Business Name')
grades = FieldList(FormField(ReusableForm), min_entries=8, max_entries=10)
def CalcOverall(Weightings, Grades):
if (type(Weightings) != list or type(Grades) != list):
return False
gradewithWeight = []
overallWeighting = 0
gradeWeightInt = 0
# iterate over the Weightings list using integer rather than elements
for i in xrange(len(Weightings)):
# skip element if cannot convert to float
try:
float(Grades[i])
except ValueError:
continue
print Weightings[i]
print Grades[i]
gradeFloat = float(Grades[i])/100
overallWeighting += float(Weightings[i])
gradewithWeight.append(gradeFloat * float(Weightings[i]))
for element in gradewithWeight:
gradeWeightInt += element
print "Overall Weighting" + str(overallWeighting)
print "Weight: " + str(gradeWeightInt)
print "List: " + str(gradewithWeight)
print "Percentage Overall: " + str(gradeWeightInt * 100 / overallWeighting)
OverallPercentage = str(gradeWeightInt * 100 / overallWeighting)
return OverallPercentage
@app.route("/", methods=['GET', 'POST'])
def hello():
form = BusinessForm(request.form)
print form.errors
if request.method == 'POST':
moduledict = dict(request.form)
print moduledict
weightings = moduledict['weight']
grades = moduledict['module']
OverallGrade = CalcOverall(weightings, grades)
return render_template('results.html', results=OverallGrade)
return render_template('grades.html', form=form)
if __name__ == "__main__":
app.run()