from flask.views import MethodView
from wtforms import Form, StringField, SubmitField
from flask import Flask, render_template, request
from temperature import Temperature
from calorie import Calorie

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 = calories_form.weight.data,
                            height = calories_form.height.data,
                            age = 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 = '92')
    height = StringField("Height:", default = '178')
    age = StringField("Age:", default = "40")

    country = StringField("Country:", default = "spain")
    city = StringField("City:", default = "madrid")

    button = SubmitField("Calculate")
    


app.add_url_rule('/', view_func=HomePage.as_view('home_page'))
app.add_url_rule('/calories', view_func=CaloriesFormPage.as_view('calories_form_page'))


app.run(debug =  True)
from flask.views import MethodView
from wtforms import Form, StringField, SubmitField
from flask import Flask, render_template, request
from temperature import Temperature
from calorie import Calorie

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 = calories_form.weight.data,
                            height = calories_form.height.data,
                            age = 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 = '92')
    height = StringField("Height:", default = '178')
    age = StringField("Age:", default = "40")

    country = StringField("Country:", default = "spain")
    city = StringField("City:", default = "madrid")

    button = SubmitField("Calculate")
    


app.add_url_rule('/', view_func=HomePage.as_view('home_page'))
app.add_url_rule('/calories', view_func=CaloriesFormPage.as_view('calories_form_page'))


app.run(debug =  True)