Commit 72c3c168 authored by Kristian Tan's avatar Kristian Tan

Display new device form when link clicked

parent e583e2cc
......@@ -154,10 +154,24 @@ def add_new_device():
'pins': pins,
'daily_total': daily_total,
'todays_cost': todays_cost,
'cost_per_kWh': os.environ['cost_per_kWh']
'cost_per_kWh': os.environ['cost_per_kWh'],
'display_form': True
}
return render_template('main.html', **template_data)
@app.route('/handle_new_device', methods=['POST'])
def handle_new_device():
new_name = request.form['new_device_name']
new_wattage = request.form['new_device_wattage']
print(new_name)
print(new_wattage)
template_data = {
'pins': pins,
'daily_total': daily_total,
'todays_cost': todays_cost,
'cost_per_kWh': os.environ['cost_per_kWh'],
}
return render_template('main.html', **template_data)
if __name__ == '__main__':
app.run(host='0.0.0.0', port=8090)
......@@ -11,7 +11,7 @@ body {
.inputs {
display: flex;
flex-direction: row;
flex-direction: column;
margin-right: 5%;
margin-left: 5%;
margin-bottom: 2%;
......
......@@ -52,6 +52,16 @@
Change cost per kWh: <input type="text" name="kWhprice">
<input type="submit">
</form>
<div class=".add_new_device_form">
{% if display_form == True %}
<form action="{{ url_for('handle_new_device') }}" method="post">
New device name: <input type="text" name="new_device_name">
New device wattage: <input type="number" name="new_device_wattage">
<input type="submit">
</form>
{% endif %}
</div>
</div>
</body>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment