diff --git a/server.py b/server.py index 91bcd4c..10b06cc 100644 --- a/server.py +++ b/server.py @@ -35,7 +35,14 @@ def help(): @app.route('/status') @requires_auth def status(): - return render_template('status.html') + locked = False + t = 0 + with open('locked_till.txt', 'rb') as f: + txt = f.read() + t = float(txt) + locked = time.time() < t + timestring = time.strftime('%Y-%m-%d %H:%M:%S %Z', time.localtime(t)) + return render_template('status.html', locked=locked, timestring=timestring) @app.route('/lock-fridge/') @requires_auth @@ -49,7 +56,7 @@ def lock_fridge(duration): def unlock_fridge(): with open('locked_till.txt', 'wb') as f: f.write('0') - return '{"success":true}' + return redirect(url_for('status')) @app.route('/open/') @requires_auth diff --git a/static/script.js b/static/script.js index 7b3199f..4275a77 100644 --- a/static/script.js +++ b/static/script.js @@ -139,6 +139,6 @@ function lock_fridge() { if (isNaN(period)) return; $.getJSON('http://130.237.3.207/lock-fridge/' + period, function(data) { - + location.reload() }); } diff --git a/static/style.css b/static/style.css index e350836..3701392 100644 --- a/static/style.css +++ b/static/style.css @@ -242,6 +242,14 @@ p { color: #013A3A; } +.locked_till { + color: #f48158; + font-size: 10pt; + padding: 0; + text-align: center; + width: 100%; +} + ul.mail-list { padding-left: 50pt; } diff --git a/templates/status.html b/templates/status.html index 45a4d85..968059d 100644 --- a/templates/status.html +++ b/templates/status.html @@ -26,8 +26,9 @@
Open tools

-
Lock
+
{% if locked %}Unlock{% else %}Lock{% endif %}
+ {% if locked %}

The fridge will be locked until {{ timestring }}

{% endif %}