-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.py
More file actions
57 lines (39 loc) · 1.74 KB
/
main.py
File metadata and controls
57 lines (39 loc) · 1.74 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
from flask.views import MethodView
from wtforms import Form, StringField, SubmitField
from flask import Flask, render_template, request
from calorie import Calorie
from temperature import Temperature
app = Flask(__name__)
class HomePage(MethodView):
def get(self):
return render_template('index.html')
class CaloriesFormPage(MethodView):
def get(self):
calories_form = CaloriesForm()
return render_template('calories_form_page.html',
caloriesform=calories_form)
def post(self):
calories_form = CaloriesForm(request.form)
temperature = Temperature(country=calories_form.country.data,
city=calories_form.city.data).get()
calorie = Calorie(weight=float(calories_form.weight.data),
height=float(calories_form.height.data),
age=float(calories_form.age.data),
temperature=temperature)
calories = calorie.calculate()
return render_template('calories_form_page.html',
caloriesform=calories_form,
calories=calories,
result=True)
class CaloriesForm(Form):
weight = StringField("Weight: ", default=70)
height = StringField("Height: ", default=175)
age = StringField("Age: ", default=32)
country = StringField("Country: ", default='USA')
city = StringField("City: ", default="San Francisco")
button = SubmitField("Calculate")
app.add_url_rule('/',
view_func=HomePage.as_view('home_page'))
app.add_url_rule('/calories_form',
view_func=CaloriesFormPage.as_view('calories_form_page'))
app.run(debug=True)