-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.py
More file actions
59 lines (39 loc) · 1.82 KB
/
main.py
File metadata and controls
59 lines (39 loc) · 1.82 KB
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
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)
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="100")
period = StringField("Bill Period: ", default="December 2020")
name1 = StringField("Name: ", default="John")
days_in_house1 = StringField("Days in the house: ", default=20)
name2 = StringField("Name: ", default="Marry")
days_in_house2 = StringField("Days in the house: ", default=12)
button = SubmitField("Calculate")
app.add_url_rule('/',
view_func=HomePage.as_view('home_page'))
app.add_url_rule('/bill_form',
view_func=BillFormPage.as_view('bill_form_page'))
app.add_url_rule('/results',
view_func=ResultsPage.as_view('results_page'))
app.run(debug=True)