diff --git a/app.py b/app.py index 2b3e758..dd34cca 100644 --- a/app.py +++ b/app.py @@ -1,3 +1,4 @@ +from typing import OrderedDict from flask import * import pyrebase from datetime import datetime @@ -30,6 +31,10 @@ storage = firebase.storage() tz = pytz.timezone('Asia/Taipei') +def next_item(odic, key): + return list(odic)[list(odic.keys()).index(key) + 1] + + def check_login_status(): return ('is_logged_in' not in session or session['is_logged_in'] == False or @@ -167,6 +172,27 @@ def manageProcess(fCommand, fData): session['uid']).child("homeroom").get().val().split('^') homeroomData = db.child("Homerooms").child(homeroom[0]).child( homeroom[1]).get().val() + times = OrderedDict({ + 'm': '00:00', + '1': '08:15', + '2': '09:10', + '3': '10:05', + '4': '11:00', + 'n': '11:55', + '5': '13:10', + '6': '14:05', + '7': '15:00', + '8': '15:53', + '9': '16:43', + 'ph': '23:59' + }) + currPeriod = "" + currTime = datetime.now(tz).strftime("%H:%M") + for i in times: + if (times[i] <= currTime and + currTime <= times[next_item(times, i)]): + currPeriod = i + break absData = homeroomData["Absent"] homeroomData.pop('Absent') homeroomData.pop('placeholder') @@ -178,7 +204,9 @@ def manageProcess(fCommand, fData): currDate = i if i >= datetime.now(tz).strftime("%Y-%m-%d"): break - return render_template('homeroom.html', absData=absData, homeroomCode=homeroom, homeroomData=homeroomData, currDate=currDate, periods=['m', '1', '2', '3', '4', 'n', '5', '6', '7', '8', '9']) + print(currPeriod) + return render_template('homeroom.html', absData=absData, homeroomCode=homeroom, homeroomData=homeroomData, + currDate=currDate, periods=['m', '1', '2', '3', '4', 'n', '5', '6', '7', '8', '9'], currPeriod=currPeriod) else: return redirect('/logout') diff --git a/templates/homeroom.html b/templates/homeroom.html index e17b4b0..d741bbf 100644 --- a/templates/homeroom.html +++ b/templates/homeroom.html @@ -40,25 +40,8 @@
Number
Name
Eng Name
-
Morning
-
1
-
2
-
3
-
4
-
Nap
-
5
-
6
-
7
-
8
-
9
- -
-
-
-
-
{% for i in periods %} -
{{absData[currDate][i]['name']}}
+
{{i}}
{% endfor %}
@@ -67,7 +50,18 @@
{% for i in periods %} -
{{absData[currDate][i]['teacher']}}
+
+ {{absData[currDate][i]['name']}}
+ {% endfor %} +
+
+
+
+
+
+ {% for i in periods %} +
+ {{absData[currDate][i]['teacher']}}
{% endfor %}
{% if data != None %} @@ -78,42 +72,32 @@
{{ homeroomData[i]['name'] }}
{{ homeroomData[i]['eng_name'] }}
{% for j in periods %} - {% if 'signature' in absData[currDate][j] %} - {% if i in absData[currDate][j] %} -
+
+ {% if 'signature' in absData[currDate][j] %} + {% if i in absData[currDate][j] %}

X

-
- {% else %} - {% if absData[currDate][j]['name'] != 'GP' %} -
+ {% else %} + {% if absData[currDate][j]['name'] != 'GP' %}

V

-
- {% else %} - {% if (homeroomData[i]['GP_Class'][absData[currDate][j]['teacher']] in - absData[currDate][j]['signature'])%} -
+ {% else %} + {% if (homeroomData[i]['GP_Class'][absData[currDate][j]['teacher']] in + absData[currDate][j]['signature'])%}

V

-
- {% else %} -
+ {% else %}

-
- {% endif %} - {% endif %} - {% endif %} - {% elif absData[currDate][j]['name'] == 'GP' %} -
+ {% endif %} + {% endif %} + {% endif %} + {% elif absData[currDate][j]['name'] == 'GP' %}

-
- {% else %} -
+ {% else %} {% if 'confirm' in absData[currDate] %}

{% else %} {% endif %} + {% endif %}
- {% endif %} {% endfor %}
{% endfor %} @@ -123,14 +107,14 @@
{% for i in periods %} -
+
{% if ('signature' in absData[currDate][i] or absData[currDate][i]['name'] == 'GP' or 'confirm' in absData[currDate]) %} + onclick="afterSelAbs('{{i|string}}')"> {% else %} + onclick="afterSelAbs('{{i|string}}')">Confirm
{{absData[currDate][i]['name']}} {% endif %}
{% endfor %} @@ -150,7 +134,10 @@ Teacher Confirm {% endif %}