From 94394334f464c29c07e25c38de32185ec67eca08 Mon Sep 17 00:00:00 2001 From: Aaron Lee Date: Fri, 15 Oct 2021 20:29:53 +0800 Subject: [PATCH] Homeroom edit functionality --- manage.py | 10 ++++++++ templates/homeroom.html | 52 ++++++++++++++++++++++++++++++----------- 2 files changed, 48 insertions(+), 14 deletions(-) diff --git a/manage.py b/manage.py index b1bece1..2f9c6f3 100644 --- a/manage.py +++ b/manage.py @@ -269,6 +269,15 @@ def homeroom_abs_publish(): homeroom = request.form['homeroom'].split('^') period = request.form['period'] signature = request.form['signatureData'] + if (request.form['stype'] == 'edit'): + oldData = list(db.child("Homerooms").child(homeroom[0]).child(homeroom[1]).child( + "Absent").child(date).child(period).shallow().get(session['token']).val()) + print(oldData, type(oldData)) + for k in oldData: + if k == 'name' or k == 'teacher': + continue + db.child("Homerooms").child(homeroom[0]).child(homeroom[1]).child( + "Absent").child(date).child(period).child(k).remove(session['token']) formData = request.form.to_dict() notes = "" if "confirm" in db.child("Homerooms").child(homeroom[0]).child(homeroom[1]).child("Absent").child(date).get(session['token']).val(): @@ -288,6 +297,7 @@ def homeroom_abs_publish(): formData.pop('date') formData.pop('homeroom') formData.pop('period') + formData.pop('stype') for i in formData: i = i.split('^') db.child("Homerooms").child(homeroom[0]).child( diff --git a/templates/homeroom.html b/templates/homeroom.html index 2a43805..91cf703 100644 --- a/templates/homeroom.html +++ b/templates/homeroom.html @@ -87,23 +87,23 @@
{{ homeroomData[i]['name'] }}
{{ homeroomData[i]['eng_name'] }}
{% for j in periods %} -
+
{% if 'signature' in absData[currDate][j] %} {% if i in absData[currDate][j] %} {% if absData[currDate][j][i] == 1 %} -

X

+

X

{% else %} -

𝜑

+

𝜑

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

V

+

V

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

V

+

V

{% else %} -

+

{% endif %} {% endif %} {% endif %} @@ -130,14 +130,15 @@
{% for i in periods %} -
- {% if ('signature' in absData[currDate][i] or absData[currDate][i]['name'] == 'GP' or - 'confirm' in absData[currDate]) %} - +
+ {% if (absData[currDate][i]['name'] == 'GP' or 'confirm' in absData[currDate]) %} + + {% elif ('signature' in absData[currDate][i]) %} + {% else %} + onclick="afterSelAbs('{{i|string}}', 'newSubmit')">Confirm
{{absData[currDate][i]['name']}} {% endif %}
{% endfor %} @@ -148,6 +149,7 @@ + {% if 'confirm' in absData[currDate] %} "); + } function homeroomCfrm() { hrCfrm = true; $('.tobeform').attr('disabled', 'disabled');