-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
73 lines (55 loc) · 2.67 KB
/
main.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
68
69
70
71
72
73
from flask.views import MethodView
from wtforms import Form, StringField, SubmitField
from flask import Flask, render_template, request
from flatmates_bill import flat
app = Flask(__name__)
class HomePage(MethodView):
def get(self):
return render_template('index.html')
class BillFormPage(MethodView):
def get(self):
bill_form = BillForm()
return render_template('bill_form_page.html',
billform=bill_form)
def post(self):
billform = BillForm(request.form)
the_bill = flat.Bill(float(billform.amount.data), billform.period.data)
flatmate1 = flat.Flatmate(billform.name1.data,
float(billform.days_in_house1.data))
flatmate2 = flat.Flatmate(billform.name2.data,
float(billform.days_in_house2.data))
return render_template('bill_form_page.html',
result=True,
billform=billform,
name1=flatmate1.name,
amount1=flatmate1.pays(the_bill, flatmate2),
name2=flatmate2.name,
amount2=flatmate2.pays(the_bill, flatmate1))
class ResultsPage(MethodView):
def post(self):
billform = BillForm(request.form)
the_bill = flat.Bill(float(billform.amount.data), billform.period.data)
flatmate1 = flat.Flatmate(billform.name1.data,
float(billform.days_in_house1.data))
flatmate2 = flat.Flatmate(billform.name2.data,
float(billform.days_in_house2.data))
return render_template('results.html',
name1=flatmate1.name,
amount1=flatmate1.pays(the_bill, flatmate2),
name2=flatmate2.name,
amount2=flatmate2.pays(the_bill, flatmate1))
class BillForm(Form):
amount = StringField("Bill Amount: ", default="420")
period = StringField("Bill Period: ", default="March 2021")
name1 = StringField("Name: ", default="Peter")
days_in_house1 = StringField("Days in the house: ", default="17")
name2 = StringField("Name: ", default="Marry")
days_in_house2 = StringField("Days in the house: ", default="23")
button = SubmitField("Calculate")
app.add_url_rule('/',
view_func=HomePage.as_view('home_page'))
app.add_url_rule('/bill_form_page',
view_func=BillFormPage.as_view('bill_form_page'))
# app.add_url_rule('/results',
# view_func=ResultsPage.as_view('results_page'))
app.run(debug=True)