From 8f74c87df5a08451d98d0c2b595d0f7561a49440 Mon Sep 17 00:00:00 2001 From: okalintu Date: Sun, 29 Oct 2017 23:46:20 +0200 Subject: [PATCH 01/14] Reimplement serverside coffee scale --- coffee_scale/apps.py | 23 --- coffee_scale/mqtt.py | 58 -------- coffee_scale/static/js/coffee.js | 231 +++++++++++++++-------------- coffee_scale/templates/coffee.html | 2 + coffee_scale/tests.py | 28 ---- coffee_scale/urls.py | 4 +- coffee_scale/views.py | 16 -- requirements.txt | 1 - sikweb/base.py | 2 +- 9 files changed, 124 insertions(+), 241 deletions(-) delete mode 100644 coffee_scale/apps.py delete mode 100644 coffee_scale/mqtt.py diff --git a/coffee_scale/apps.py b/coffee_scale/apps.py deleted file mode 100644 index 57c4c5b..0000000 --- a/coffee_scale/apps.py +++ /dev/null @@ -1,23 +0,0 @@ -from django.apps import AppConfig - -import logging -import sys - -from coffee_scale import mqtt - - -class CoffeeScaleConfig(AppConfig): - name = 'coffee_scale' - - def ready(self): - if ('makemigrations' in sys.argv or 'migrate' in sys.argv): - return - - try: - logging.info('Connecting to MQTT (coffee scale) at {}...'.format(mqtt.HOST)) - logging.info('If there is no confirmation, the MQTT connection has probably failed.') - mqtt.client.connect_async(mqtt.HOST, mqtt.PORT, 60) - mqtt.client.loop_start() - except Exception as ex: - logging.error(ex) - logging.error('Failed to connect to MQTT at {}'.format(mqtt.HOST)) diff --git a/coffee_scale/mqtt.py b/coffee_scale/mqtt.py deleted file mode 100644 index 47a4592..0000000 --- a/coffee_scale/mqtt.py +++ /dev/null @@ -1,58 +0,0 @@ -import paho.mqtt.client as mqtt -import logging -import datetime -from collections import deque - -from django.conf import settings - -HOST = settings.MQTT_SETTINGS['HOST'] -PORT = settings.MQTT_SETTINGS['PORT'] -TOPICS = settings.MQTT_SETTINGS['TOPICS'] -latest = {} - - -def on_connect(client, userdata, flags, rc): - logging.info('Connected successfully to MQTT.') - logging.info('Subscribing to all topics on {}.'.format(HOST)) - client.subscribe('sik/kiltahuone/kahvivaaka/#') - - -def update_latest(msg): - payload = msg.payload.decode('utf-8') - if msg.topic == TOPICS['WEIGHT']: - weight = float(payload) - latest['weight'] = weight - elif msg.topic == TOPICS['CUPS']: - cups = float(payload) - latest['cups'] = cups - elif msg.topic == TOPICS['BREWING']: - brewing = bool(int(payload)) - latest['brewing'] = brewing - elif msg.topic == TOPICS['BREW_TIME']: - brew_time = datetime.datetime.fromtimestamp(float(payload)) - latest['brew_time'] = brew_time - - -def on_message(client, userdata, msg): - try: - update_latest(msg) - except Exception as ex: - logging.exception('Failed to parse MQTT payload.') - - -def on_disconnect(client, userdata, rc): - if rc != 0: - logging.warning('MQTT unexpectedly disconnected.') - else: - client.loop_stop(force=False) - logging.warning('MQTT disconnected.') - - -def get_latest(): - return latest - - -client = mqtt.Client() -client.on_connect = on_connect -client.on_message = on_message -client.on_disconnect = on_disconnect diff --git a/coffee_scale/static/js/coffee.js b/coffee_scale/static/js/coffee.js index 6b9b4a6..95f338b 100644 --- a/coffee_scale/static/js/coffee.js +++ b/coffee_scale/static/js/coffee.js @@ -1,130 +1,139 @@ -var len = 0; -var lastBrew = "∞"; -var brewtext = ""; +//Inner state +var lastBrew = new Date(0); +var brewing = false; +var backoff = 2000; -$(document).ready(function(){ - $('#text').bind("DOMSubtreeModified", resize); - updateTime(); - setInterval(updateTime,1000); - formatBrewTime(); - setInterval(formatBrewTime,10000); -}); +//MQTT client config +var username = "coffee-user-"+ Math.random(); +var client = new Paho.MQTT.Client("sika.sahkoinsinoorikilta.fi", 9001, username); +client.onMessageArrived = function (message) { + console.log("Topic: "+message.destinationName+" msg: "+message.payloadString); + var ev = new CustomEvent(message.destinationName, {'detail': message.payloadString}); + window.dispatchEvent(ev); +} -$(window).resize(resize); - -function fetchdata(data, status){ - if (typeof status !== 'undefined'){ - if (status == "success"){ - parseData(data); +function reconnect(responseObject){ + if (responseObject.errorCode !== 0) { + console.log("connection lost! Reason: "+responseObject.errorMessage); + setTimeout(function(){ + client.connect({onSuccess:onConnect, useSSL:true, onFailure: reconnect}); + }, backoff); } - else if (status == "error"){ - handleError(); - } - } } -$.getJSON("/coffee/cups", fetchdata); -setInterval(function() { - $.getJSON("/coffee/cups", fetchdata); -}, 2000); - -function formatBrewTime(){ - if (!brewtext && lastBrew instanceof Date){ - var now = new Date(); - var timeDiff = Math.max(now.getTime() - lastBrew.getTime(), 0); - var tmp = (timeDiff < 3600000) - ? Math.round(timeDiff / 60000) + ' min' - : '~' + Math.round(timeDiff / 3600000 * 2) / 2 + ' h'; - - $("#brewtime").html(tmp); - } else { - $("#brewtime").html(brewtext); +function onConnect() { + console.log("MQTT connected"); + //set and reset reconnector + client.onConnectionLost = reconnect + // subscribe to topics + client.subscribe("sik/kiltahuone/kahvivaaka/cups"); + client.subscribe("sik/kiltahuone/kahvivaaka/brewing"); + client.subscribe("sik/kiltahuone/kahvivaaka/brewtime"); } + +// data update and parse functions +function parseCups(ev){ + var cups = parseFloat(ev.detail).toFixed(1) + var cupsEvent = new CustomEvent("cupsChanged", {'detail': cups}); + window.dispatchEvent(cupsEvent); +} +function updateCups(ev){ + $("#text").text(ev.detail); +} +function updateScale(ev){ + $("#scale2").css({width: Math.min(ev.detail/9*100,100) + '%'}); } -function handleError() { - setData("?", 0, 0, Number.MAX_VALUE, Number.MAX_VALUE); +function tick(){ + var ev = new CustomEvent("tick", {'detail': new Date()}); + window.dispatchEvent(ev); } -function parseData(data) { - if (data) { - var date = new Date(data.date); - lastBrew = new Date(data.last_brew); - var now = new Date(); - var cups = data.cups; - var brewing = data.brewing; - var timeDiff = Math.max(now.getTime() - lastBrew.getTime(),0); - var opa = Math.max(100 - timeDiff / 90000,0); - setData(cups, data.temp, opa,now.getTime()-date.getTime(), timeDiff, brewing); - } - else{ - handleError(); - } -} - -function setData(cups, temp, opa, timeFromUpdate, timeFromBrew, brewing){ - if (cups == 0) { - opa = 0; - } - brewtext = ""; - $("#upper").css({opacity: opa/100}); - $("#scale2").css({width: Math.min(cups/9*100,100) + '%'}); - $("#text,body").removeClass(); - - cups = Number(cups).toFixed(1); - - if(timeFromUpdate > 600000){ - cups = "?"; - brewtext = "∞"; - $("#text").addClass("unknown"); - } - else if(brewing){ - cups = "+"; - brewtext = ":)"; - $("#text").addClass("brewing"); - } - else if(cups <= 2){ - $("#text").addClass("hurry"); - } - formatBrewTime(); - if($("#text").html() == "+" && !brewing) - $("body").addClass("coffeeready"); - - var cupsString = cups.toString(); - len = cupsString.length; - $("#text").html(cups); -} - -function updateTime(){ - var now = new Date(); +function updateTime(ev){ + var now = ev.detail; $("#time").html(formatTime(now.getHours(),now.getMinutes(),now.getSeconds())); } -function formatTime(hours, minutes, seconds){ - var str = ""; - - if(hours < 10) - str += "0"; - str += hours; - - str += ":"; - - if(minutes < 10) - str += "0"; - str += minutes; - - str += ":"; - - if(seconds < 10) - str += "0"; - str += seconds; - - return str; +function coffeeLowEffect(ev){ + ev.detail <= 2 ? $("#text").addClass("hurry") : $("#text").removeClass("hurry"); } +function coffeeReadyEffect(ev){ + $("body").addClass("coffeeready"); + // autoclear animation class in 10s + setTimeout(() => {$("body").removeClass("coffeeready");}, 10000); +} +function brewAnimStart(ev){ + $("#text").addClass("brewing"); +} +function brewAnimEnd(ev){ + $("#text").removeClass("brewing"); +} +function brewNotifier(ev){ + var new_brewing = parseInt(ev.detail); + if (new_brewing == 1 && brewing == 0){ + window.dispatchEvent(new Event("brewStart")); + } else if (new_brewing == 0 && brewing == 1){ + window.dispatchEvent(new Event("brewEnd")); + } + brewing = new_brewing; +} +function brewTimeParser(ev){ + lastBrew = new Date(parseInt(ev.detail)*1000.0); +} +function updateBrewDiff(ev){ + var now = new Date(); + var timeDiff = Math.max(now.getTime() - lastBrew.getTime(), 0); + var timeStr = (timeDiff < 3600000) + ? Math.round(timeDiff / 60000) + ' min' + : '~' + Math.round(timeDiff / 3600000 * 2) / 2 + ' h'; + + $("#brewtime").html(timeStr); +} + +// Helpers + +function nToS(num){ + return num < 10 ? "0" + num : "" + num; +} + +function formatTime(hours, minutes, seconds){ + return nToS(hours)+":"+nToS(minutes)+":"+nToS(seconds) +} + function resize(){ var w = $("#container").width(); var h = $("#container").height(); var s = w > h ? h : w; - var font = s*0.8*0.38/Math.sqrt(len); - $("#text").css({ top: s*0.16-font/2 + 'px', fontSize: font + 'px', marginLeft: -font*len*3/10 + 'px'}); + var font = s * 0.8 * 0.38/Math.sqrt(3); + $("#text").css({ top: s*0.16-font/2 + 'px', + fontSize: font + 'px', + marginLeft: -font*3*3/10 + 'px'}); } + +// Init everything + +$(document).ready(function(){ + client.connect({onSuccess:onConnect, useSSL:true, onFailure:reconnect}); + + //connect MQTT event listeners + window.addEventListener("sik/kiltahuone/kahvivaaka/cups", parseCups); + window.addEventListener("sik/kiltahuone/kahvivaaka/brewing", brewNotifier); + window.addEventListener("sik/kiltahuone/kahvivaaka/brewtime", brewTimeParser); + + //connect other event listeners + window.addEventListener("cupsChanged", updateCups); + window.addEventListener("cupsChanged", coffeeLowEffect); + window.addEventListener("cupsChanged", updateScale); + window.addEventListener("cupsChanged", resize); + window.addEventListener("brewStart", brewAnimStart); + window.addEventListener("brewEnd", brewAnimEnd); + window.addEventListener("brewEnd", coffeeReadyEffect); + window.addEventListener("tick", updateTime); + window.addEventListener("tick", updateBrewDiff); + + //start time based events + setInterval(tick, 100); + tick(); + +}); +$(window).resize(resize); diff --git a/coffee_scale/templates/coffee.html b/coffee_scale/templates/coffee.html index 1c2fec9..faf215c 100644 --- a/coffee_scale/templates/coffee.html +++ b/coffee_scale/templates/coffee.html @@ -10,6 +10,8 @@ + diff --git a/coffee_scale/tests.py b/coffee_scale/tests.py index b1e5f9b..f9c051b 100644 --- a/coffee_scale/tests.py +++ b/coffee_scale/tests.py @@ -1,30 +1,2 @@ from django.test import TestCase, Client from django.conf import settings - -from coffee_scale.mqtt import on_message - -HOST = settings.MQTT_SETTINGS['HOST'] -PORT = settings.MQTT_SETTINGS['PORT'] -TOPICS = settings.MQTT_SETTINGS['TOPICS'] - - -class MQTTTestCase(TestCase): - """Tests MQTT functionality""" - - class MockMessage: - def __init__(self, payload, topic): - self.payload = payload - self.topic = topic - - def setUp(self): - payload = '10'.encode('utf-8') - topic = TOPICS['CUPS'] - msg = MQTTTestCase.MockMessage(payload, topic) - - on_message(None, None, msg) - self.c = Client() - - def test_receive_cups(self): - response = self.c.get('/coffee/cups') - payload = response.json() - self.assertEquals(payload['cups'], 10) diff --git a/coffee_scale/urls.py b/coffee_scale/urls.py index b9c54e6..f750576 100644 --- a/coffee_scale/urls.py +++ b/coffee_scale/urls.py @@ -1,7 +1,7 @@ from django.conf.urls import url from django.views.generic.base import RedirectView -from .views import coffee_view, cups_view +from .views import coffee_view favicon_view = RedirectView.as_view(url='static/img/favicon.ico', permanent=True) @@ -9,6 +9,4 @@ urlpatterns = [ # landing page url(r'^$', coffee_view), - url(r'^cups', cups_view), - ] diff --git a/coffee_scale/views.py b/coffee_scale/views.py index 9b8ae08..b973641 100644 --- a/coffee_scale/views.py +++ b/coffee_scale/views.py @@ -3,25 +3,9 @@ from django.http import JsonResponse from django.utils import timezone -from .mqtt import get_latest -import coffee_scale.mqtt # somehow this is needed - import logging from django.conf import settings def coffee_view(request): return render(request, 'coffee.html') - - -def cups_view(request): - now = timezone.now() - latest = get_latest() - data = { - 'date': now, - 'cups': latest.get('cups'), - 'last_brew': latest.get('brew_time'), - 'brewing': latest.get('brewing'), - 'weight': latest.get('weight') - } - return JsonResponse(data) diff --git a/requirements.txt b/requirements.txt index ef7a2fd..5e52874 100644 --- a/requirements.txt +++ b/requirements.txt @@ -25,7 +25,6 @@ dealer==2.0.5 django-modeltranslation==0.12.1 django-auditlog==0.4.3 django-phonenumber-field==1.3.0 -paho-mqtt==1.3.0 django-autocomplete-light==3.2.10 six==1.10.0 django-suit==0.2.25 diff --git a/sikweb/base.py b/sikweb/base.py index c094344..527c645 100644 --- a/sikweb/base.py +++ b/sikweb/base.py @@ -78,7 +78,7 @@ INSTALLED_APPS = [ 'webapp', 'members', 'infoscreen', - 'coffee_scale.apps.CoffeeScaleConfig', + 'coffee_scale', 'rest_framework', 'django_nose', 'bootstrap3', From 68f2b1199a683232225bbc2197d1f3f34739e21f Mon Sep 17 00:00:00 2001 From: henu Date: Tue, 31 Oct 2017 17:49:15 +0200 Subject: [PATCH 02/14] Fix base to use only bootstrap --- webapp/templates/base.html | 48 +++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/webapp/templates/base.html b/webapp/templates/base.html index 3fe75d4..97506a5 100644 --- a/webapp/templates/base.html +++ b/webapp/templates/base.html @@ -10,7 +10,7 @@ - + {% trans "Aalto-yliopiston Sähköinsinöörikilta ry" %} @@ -29,24 +29,34 @@ - {% block header %} -
- {% include "sik_header.html" %} -
- {% endblock %} - -
- {% block navigation %} - {% include "navigation.html" %} - {% endblock %} - - {% block content %} - {% endblock %} -
- From b8fd237918acc7d2f2c7481b5f8ace3a0ea6c40d Mon Sep 17 00:00:00 2001 From: Ilkka Oksanen Date: Tue, 31 Oct 2017 18:10:08 +0200 Subject: [PATCH 04/14] Mute a few eslint bloopers --- coffee_scale/static/js/coffee.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/coffee_scale/static/js/coffee.js b/coffee_scale/static/js/coffee.js index a0f3269..32134a0 100644 --- a/coffee_scale/static/js/coffee.js +++ b/coffee_scale/static/js/coffee.js @@ -5,8 +5,10 @@ var backoff = 2000; //MQTT client config var username = "coffee-user-"+ Math.random(); +// eslint-disable-next-line no-undef var client = new Paho.MQTT.Client("sika.sahkoinsinoorikilta.fi", 9001, username); client.onMessageArrived = function (message) { + // eslint-disable-next-line no-console console.log("Topic: "+message.destinationName+" msg: "+message.payloadString); var ev = new CustomEvent(message.destinationName, {'detail': message.payloadString}); window.dispatchEvent(ev); @@ -14,7 +16,7 @@ client.onMessageArrived = function (message) { function reconnect(responseObject){ if (responseObject.errorCode !== 0) { - console.log("connection lost! Reason: "+responseObject.errorMessage); + console.log("connection lost! Reason: "+responseObject.errorMessage); // eslint-disable-line no-console setTimeout(function(){ client.connect({onSuccess:onConnect, useSSL:true, onFailure: reconnect}); }, backoff); @@ -22,7 +24,7 @@ function reconnect(responseObject){ } function onConnect() { - console.log("MQTT connected"); + console.log("MQTT connected"); // eslint-disable-line no-console //set and reset reconnector client.onConnectionLost = reconnect // subscribe to topics From eec2d27504264c2d973aece82a9633015a0199f2 Mon Sep 17 00:00:00 2001 From: henu Date: Tue, 31 Oct 2017 19:30:23 +0200 Subject: [PATCH 05/14] Update bootstrap version --- webapp/templates/base.html | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/webapp/templates/base.html b/webapp/templates/base.html index 97506a5..755fb30 100644 --- a/webapp/templates/base.html +++ b/webapp/templates/base.html @@ -10,16 +10,19 @@ - + {% trans "Aalto-yliopiston Sähköinsinöörikilta ry" %} - - - + + + + + + + + + + + + + + + {% block header %} +
+ {% include "sik_header.html" %} +
+ {% endblock %} + +
+ {% block content %} + {% endblock %} +
+ + + + \ No newline at end of file diff --git a/templates/password_reset/base.html b/templates/password_reset/base.html new file mode 100644 index 0000000..75aebfd --- /dev/null +++ b/templates/password_reset/base.html @@ -0,0 +1 @@ +{% extends "login_base.html" %} \ No newline at end of file diff --git a/templates/password_reset/recovery_done.html b/templates/password_reset/recovery_done.html new file mode 100644 index 0000000..164b8ff --- /dev/null +++ b/templates/password_reset/recovery_done.html @@ -0,0 +1,8 @@ +{% extends "password_reset/base.html" %}{% load i18n %} + +{% block title %}{% trans "New password set" %}{% endblock %} + +{% block content %} +

{% trans "Your password has successfully been reset. You can use it right now on the login page." %}

+

Log in

+{% endblock %} \ No newline at end of file diff --git a/templates/password_reset/recovery_form.html b/templates/password_reset/recovery_form.html new file mode 100644 index 0000000..1dec151 --- /dev/null +++ b/templates/password_reset/recovery_form.html @@ -0,0 +1,12 @@ +{% extends "password_reset/base.html" %} +{% load i18n %} + +{% block title %}{% trans "Password recovery" %}{% endblock %} + +{% block content %} +
+ {% csrf_token %} + {{ form.as_p }} +

+
+{% endblock %} \ No newline at end of file diff --git a/templates/password_reset/reset.html b/templates/password_reset/reset.html new file mode 100644 index 0000000..ab1cd5c --- /dev/null +++ b/templates/password_reset/reset.html @@ -0,0 +1,14 @@ +{% extends "password_reset/base.html" %}{% load i18n %} + +{% block content %} + {% if invalid %}{% url "password_reset_recover" as recovery_url %} +

{% blocktrans %}Sorry, this password reset link is invalid. You can still request a new one.{% endblocktrans %}

+ {% else %} +

{% blocktrans %}Hi, {{ username }}. Please choose your new password.{% endblocktrans %}

+
+ {% csrf_token %} + {{ form.as_p }} +

+
+ {% endif %} +{% endblock %} \ No newline at end of file diff --git a/templates/password_reset/reset_mail.html b/templates/password_reset/reset_mail.html new file mode 100644 index 0000000..c1ef31f --- /dev/null +++ b/templates/password_reset/reset_mail.html @@ -0,0 +1,15 @@ +{% autoescape off %} +You're receiving this e-mail because you requested a password reset for your user account at {{ site_name }}. + +Please go to the following page and choose a new password: +{% block reset_link %} +{{ protocol }}://{{ domain }}{% url django.contrib.auth.views.password_reset_confirm uidb36=uid, token=token %} +{% endblock %} + +Your username, in case you've forgotten: {{ user.username }} + +Thanks for using our site! + +The {{ site_name }} team. + +{% endautoescape %} \ No newline at end of file diff --git a/templates/password_reset/reset_sent.html b/templates/password_reset/reset_sent.html new file mode 100644 index 0000000..15d12d7 --- /dev/null +++ b/templates/password_reset/reset_sent.html @@ -0,0 +1,8 @@ +{% extends "password_reset/base.html" %} +{% load i18n %} + +{% block title %}{% trans "Password recovery sent" %}{% endblock %} + +{% block content %} +

{% blocktrans with ago=timestamp|timesince %}An email was sent to {{ email }} {{ ago }} ago. Use the link in it to set a new password.{% endblocktrans %}

+{% endblock %} \ No newline at end of file diff --git a/webapp/templates/login.html b/webapp/templates/login.html deleted file mode 100644 index 7d2d763..0000000 --- a/webapp/templates/login.html +++ /dev/null @@ -1,49 +0,0 @@ - - -{% load i18n %} -{% load static %} - - - - SIK - Login - - - - - - - - - - - - -
-

SIK Admin

-
{% csrf_token %} -
- -
- -
-
-
- -
- -
-
-
-
-
{{ error }}
-
-
-
-
- -
-
-
-
- - From 4221be8c64adc5b18bb95790763de138a71c35b3 Mon Sep 17 00:00:00 2001 From: Aarni Halinen Date: Tue, 31 Oct 2017 20:25:37 +0200 Subject: [PATCH 10/14] Update requirements.txt --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index bc58902..eb71118 100644 --- a/requirements.txt +++ b/requirements.txt @@ -30,3 +30,4 @@ django-autocomplete-light==3.2.10 six==1.10.0 django-suit==0.2.25 telepot==12.3 +django-password-reset==1.0 From fe14f7600ab7c4eaf7fdc193941dc7e3e6ba3253 Mon Sep 17 00:00:00 2001 From: henu Date: Tue, 31 Oct 2017 20:39:19 +0200 Subject: [PATCH 11/14] Create common base for all apps --- static/css/footer.css | 2 ++ {webapp/templates => templates}/base.html | 40 ++--------------------- webapp/templates/admin_index.html | 2 +- webapp/templates/contact.html | 2 +- webapp/templates/event_calendar.html | 2 +- webapp/templates/freshmen.html | 2 +- webapp/templates/guild.html | 2 +- webapp/templates/international.html | 2 +- webapp/templates/jobs.html | 2 +- webapp/templates/main_index.html | 8 +++-- webapp/templates/ohlhafv.html | 2 +- webapp/templates/ohlhafv_list.html | 2 +- webapp/templates/sosso.html | 2 +- webapp/templates/webapp_base.html | 36 ++++++++++++++++++++ 14 files changed, 56 insertions(+), 50 deletions(-) rename {webapp/templates => templates}/base.html (62%) create mode 100644 webapp/templates/webapp_base.html diff --git a/static/css/footer.css b/static/css/footer.css index 23fbc04..61bca94 100644 --- a/static/css/footer.css +++ b/static/css/footer.css @@ -1,4 +1,6 @@ footer { + position: absolute; + bottom: 0; background-color: #f5f5f5; } diff --git a/webapp/templates/base.html b/templates/base.html similarity index 62% rename from webapp/templates/base.html rename to templates/base.html index 755fb30..88ac035 100644 --- a/webapp/templates/base.html +++ b/templates/base.html @@ -1,16 +1,10 @@ - -{% load i18n %} -{% load static %} -{% load staticfiles %} - - + - {% trans "Aalto-yliopiston Sähköinsinöörikilta ry" %} @@ -30,36 +24,8 @@ }) - -
-
-
- {% block header %} - {% include "sik_header.html" %} - {% endblock %} -
-
-
-
- {% block navigation %} - {% include "navigation.html" %} - {% endblock %} -
-
-
-
- {% block content %} - {% endblock %} -
-
-
-
- {% block footer %} - {% include "footer.html" %} - {% endblock footer %} -
-
-
+ {% block body %} + {% endblock %} diff --git a/webapp/templates/admin_index.html b/webapp/templates/admin_index.html index 1af227e..0453ff1 100644 --- a/webapp/templates/admin_index.html +++ b/webapp/templates/admin_index.html @@ -1,4 +1,4 @@ -{% extends "base.html" %} +{% extends "webapp_base.html" %} {% load i18n %} {% block content %} diff --git a/webapp/templates/contact.html b/webapp/templates/contact.html index 01a5d0b..1be617e 100644 --- a/webapp/templates/contact.html +++ b/webapp/templates/contact.html @@ -1,4 +1,4 @@ -{% extends "base.html" %} +{% extends "webapp_base.html" %} {% block content %} {% load i18n %} diff --git a/webapp/templates/event_calendar.html b/webapp/templates/event_calendar.html index a2e99be..f6e1fc6 100644 --- a/webapp/templates/event_calendar.html +++ b/webapp/templates/event_calendar.html @@ -1,4 +1,4 @@ -{% extends "base.html" %} +{% extends "webapp_base.html" %} {% block content %} {% load i18n %} diff --git a/webapp/templates/freshmen.html b/webapp/templates/freshmen.html index 2702258..baaebc5 100644 --- a/webapp/templates/freshmen.html +++ b/webapp/templates/freshmen.html @@ -1,4 +1,4 @@ -{% extends "base.html" %} +{% extends "webapp_base.html" %} {% block content %} {% load i18n %} diff --git a/webapp/templates/guild.html b/webapp/templates/guild.html index adc37db..10c7e93 100644 --- a/webapp/templates/guild.html +++ b/webapp/templates/guild.html @@ -1,4 +1,4 @@ -{% extends "base.html" %} +{% extends "webapp_base.html" %} {% block content %} {% load i18n %} diff --git a/webapp/templates/international.html b/webapp/templates/international.html index f07c322..982f227 100644 --- a/webapp/templates/international.html +++ b/webapp/templates/international.html @@ -1,4 +1,4 @@ -{% extends "base.html" %} +{% extends "webapp_base.html" %} {% block content %} {% load i18n %} diff --git a/webapp/templates/jobs.html b/webapp/templates/jobs.html index d07cd96..de2a7b7 100644 --- a/webapp/templates/jobs.html +++ b/webapp/templates/jobs.html @@ -1,4 +1,4 @@ -{% extends "base.html" %} +{% extends "webapp_base.html" %} {% block content %} {% load i18n %} diff --git a/webapp/templates/main_index.html b/webapp/templates/main_index.html index bb4ee80..b75df86 100644 --- a/webapp/templates/main_index.html +++ b/webapp/templates/main_index.html @@ -1,4 +1,4 @@ -{% extends "base.html" %} +{% extends "webapp_base.html" %} {% load i18n %} {% block content %} @@ -6,11 +6,13 @@
-

{% trans "Copyright Aalto-yliopiston Sähköinsinöörikilta ry" %}

+

{% trans "Aalto-yliopiston Sähköinsinöörikilta ry" %}

-
Lisää vain vesi
+
+
Lisää vain vesi
+
diff --git a/webapp/templates/ohlhafv.html b/webapp/templates/ohlhafv.html index 05decc5..c4f658b 100644 --- a/webapp/templates/ohlhafv.html +++ b/webapp/templates/ohlhafv.html @@ -1,4 +1,4 @@ -{% extends "base.html" %} +{% extends "webapp_base.html" %} {% load bootstrap3 %} {% load i18n %} diff --git a/webapp/templates/ohlhafv_list.html b/webapp/templates/ohlhafv_list.html index 057ce06..a693237 100644 --- a/webapp/templates/ohlhafv_list.html +++ b/webapp/templates/ohlhafv_list.html @@ -1,4 +1,4 @@ -{% extends "base.html" %} +{% extends "webapp_base.html" %} {% load static %} {% load i18n %} diff --git a/webapp/templates/sosso.html b/webapp/templates/sosso.html index f96a7ff..cd3bdea 100644 --- a/webapp/templates/sosso.html +++ b/webapp/templates/sosso.html @@ -1,4 +1,4 @@ -{% extends "base.html" %} +{% extends "webapp_base.html" %} {% block content %} {% load i18n %} diff --git a/webapp/templates/webapp_base.html b/webapp/templates/webapp_base.html new file mode 100644 index 0000000..6e9dfd7 --- /dev/null +++ b/webapp/templates/webapp_base.html @@ -0,0 +1,36 @@ +{% extends "base.html" %} + +{% load i18n %} +{% load static %} +{% load staticfiles %} + + +
+
+
+ {% block header %} + {% include "sik_header.html" %} + {% endblock %} +
+
+
+
+ {% block navigation %} + {% include "navigation.html" %} + {% endblock %} +
+
+
+
+ {% block content %} + {% endblock %} +
+
+
+
+ {% block footer %} + {% include "footer.html" %} + {% endblock footer %} +
+
+
From 6d18e4043100048f1dd3ef69ec4d379fdbf0cdbe Mon Sep 17 00:00:00 2001 From: henu Date: Tue, 31 Oct 2017 21:01:22 +0200 Subject: [PATCH 12/14] Fix login form styles --- static/css/footer.css | 2 -- templates/base.html | 5 +++ templates/login.html | 52 ++++++++++++++----------------- templates/login_base.html | 50 ++++++++++------------------- webapp/templates/webapp_base.html | 2 ++ 5 files changed, 48 insertions(+), 63 deletions(-) diff --git a/static/css/footer.css b/static/css/footer.css index 61bca94..23fbc04 100644 --- a/static/css/footer.css +++ b/static/css/footer.css @@ -1,6 +1,4 @@ footer { - position: absolute; - bottom: 0; background-color: #f5f5f5; } diff --git a/templates/base.html b/templates/base.html index 88ac035..5307718 100644 --- a/templates/base.html +++ b/templates/base.html @@ -1,4 +1,9 @@ + +{% load i18n %} +{% load static %} +{% load staticfiles %} + diff --git a/templates/login.html b/templates/login.html index 948c0f8..463ea05 100644 --- a/templates/login.html +++ b/templates/login.html @@ -2,34 +2,30 @@ {% load i18n %} {% block content %} -

SIK Admin

-
{% csrf_token %} -
- -
- -
+
+
+

SIK Admin

-
- -
- -
+
+ {% csrf_token %} +
+ + +
+
+ + +
+ +
+
{{ error }}
+
+
+ +
+
- -
-
-
{{ error }}
-
-
-
-
- -
-
- +
{% endblock content %} diff --git a/templates/login_base.html b/templates/login_base.html index 1aa3b9e..d0b0a8f 100644 --- a/templates/login_base.html +++ b/templates/login_base.html @@ -1,38 +1,22 @@ - +{% extends "base.html" %} {% load i18n %} {% load static %} - - - SIK - Login - +{% block body %} +{% block header %} +
+ {% include "sik_header.html" %} +
+{% endblock %} - - - - - - - - - - - {% block header %} -
- {% include "sik_header.html" %} -
- {% endblock %} - -
- {% block content %} - {% endblock %} -
- - - - \ No newline at end of file +
+ {% block content %} + {% endblock %} +
+ +{% endblock %} diff --git a/webapp/templates/webapp_base.html b/webapp/templates/webapp_base.html index 6e9dfd7..1744f55 100644 --- a/webapp/templates/webapp_base.html +++ b/webapp/templates/webapp_base.html @@ -4,6 +4,7 @@ {% load static %} {% load staticfiles %} +{% block body %}
@@ -34,3 +35,4 @@
+{% endblock %} From e63f8d54182ad357c7133cea605b1adcacfed193 Mon Sep 17 00:00:00 2001 From: Juhana Luomanen Date: Tue, 31 Oct 2017 22:34:39 +0200 Subject: [PATCH 13/14] Fix #91 bug with HSL timetable sorting --- infoscreen/hsl_fetcher.py | 3 ++- infoscreen/static/html/hsl.html | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/infoscreen/hsl_fetcher.py b/infoscreen/hsl_fetcher.py index 9df913a..6a3835c 100644 --- a/infoscreen/hsl_fetcher.py +++ b/infoscreen/hsl_fetcher.py @@ -47,7 +47,7 @@ def fetch(): route = place['pattern']['route']['shortName'] stop_times = place['_stoptimes'] for stop_time in stop_times: - timestamp = stop_time['serviceDay'] + stop_time['realtimeArrival'] + timestamp = time_utc = stop_time['serviceDay'] + stop_time['realtimeArrival'] headsign = stop_time['stopHeadsign'] stop_name = stop_time['stop']['name'] time_diff = (timestamp - timezone.now().timestamp()) / 60 # minutes @@ -64,6 +64,7 @@ def fetch(): 'headsign': headsign, 'timestamp': time, 'stop': stop_name, + 'utc': time_utc, }) return schedule diff --git a/infoscreen/static/html/hsl.html b/infoscreen/static/html/hsl.html index bbc128e..288fa4c 100644 --- a/infoscreen/static/html/hsl.html +++ b/infoscreen/static/html/hsl.html @@ -25,7 +25,7 @@ - + {{x.timestamp}} From e0e73976dbd6b97ef362d4922bdeae1ff1f478c9 Mon Sep 17 00:00:00 2001 From: Ilkka Oksanen Date: Wed, 1 Nov 2017 13:39:46 +0200 Subject: [PATCH 14/14] Add question marks to coffee in case of few errors --- coffee_scale/static/js/coffee.js | 12 ++++++++---- coffee_scale/templates/coffee.html | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/coffee_scale/static/js/coffee.js b/coffee_scale/static/js/coffee.js index 32134a0..f885408 100644 --- a/coffee_scale/static/js/coffee.js +++ b/coffee_scale/static/js/coffee.js @@ -99,10 +99,14 @@ function updateBrewDiff(){ } function updateBrewTime(ev){ var timeDiff = ev.detail; - var timeStr = (timeDiff < 3600000) - ? Math.round(timeDiff / 60000) + ' min' - : '~' + Math.round(timeDiff / 3600000 * 2) / 2 + ' h'; - + var timeStr; + if (timeDiff < 3600000){ + timeStr = Math.round(timeDiff / 60000) + ' min' + } else if (timeDiff < 10000* 3600 * 1000){ // 1000h + timeStr = '~' + Math.round(timeDiff / 3600000 * 2) / 2 + ' h'; + } else { + timeStr = "???" + } $("#brewtime").html(timeStr); } diff --git a/coffee_scale/templates/coffee.html b/coffee_scale/templates/coffee.html index 5484f97..b09a25d 100644 --- a/coffee_scale/templates/coffee.html +++ b/coffee_scale/templates/coffee.html @@ -29,7 +29,7 @@
-
+
???
 +