This commit is contained in:
Aaron Lee 2021-09-14 17:49:16 +08:00
parent 63a3ff1346
commit 1c86d3f2d2
3 changed files with 41 additions and 10 deletions

28
app.py
View file

@ -153,6 +153,9 @@ def manageProcess(fCommand, fData):
if not h[0] in absData[p]: if not h[0] in absData[p]:
absData[p][h[0]] = {} absData[p][h[0]] = {}
absData[p][h[0]][h[1]] = {} absData[p][h[0]][h[1]] = {}
if 'notes' in tmpAbsData[currDate][p]:
absData[p][h[0]][h[1]
]['notes'] = tmpAbsData[currDate][p]['notes']
for num in hrData: for num in hrData:
if (cclass['category'] in hrData[num]['GP_Class'] and if (cclass['category'] in hrData[num]['GP_Class'] and
hrData[num]['GP_Class'][cclass['category']] == cclass['class_id']): hrData[num]['GP_Class'][cclass['category']] == cclass['class_id']):
@ -270,6 +273,11 @@ def group_teach_publish():
date = request.form['date'] date = request.form['date']
period = request.form['period'] period = request.form['period']
signature = request.form['signatureData'] signature = request.form['signatureData']
formData = request.form.to_dict()
notes = ""
if 'notes' in request.form:
notes = request.form['notes']
formData.pop('notes')
signature = signature.removeprefix('data:image/png;base64,') signature = signature.removeprefix('data:image/png;base64,')
signature = bytes(signature, 'utf-8') signature = bytes(signature, 'utf-8')
rand = str(randint(100000000000000, 999999999999999)) rand = str(randint(100000000000000, 999999999999999))
@ -278,8 +286,6 @@ def group_teach_publish():
fh.write(base64.decodebytes(signature)) fh.write(base64.decodebytes(signature))
storage.child(os.path.join('signatures', rand) storage.child(os.path.join('signatures', rand)
).put(os.path.join('temp', rand)) ).put(os.path.join('temp', rand))
formData = request.form.to_dict()
formData.pop('signatureData') formData.pop('signatureData')
formData.pop('date') formData.pop('date')
formData.pop('period') formData.pop('period')
@ -291,6 +297,15 @@ def group_teach_publish():
h = h.split('^') h = h.split('^')
db.child("Homerooms").child(h[0]).child(h[1]).child( db.child("Homerooms").child(h[0]).child(h[1]).child(
"Absent").child(date).child(period).child("signature").update({cclass['class_id']: str(storage.child(os.path.join('signatures', rand)).get_url(None))}) "Absent").child(date).child(period).child("signature").update({cclass['class_id']: str(storage.child(os.path.join('signatures', rand)).get_url(None))})
# upload notes
currPeriodData = db.child("Homerooms").child(h[0]).child(h[1]).child(
"Absent").child(date).child(period).get().val()
if 'notes' in currPeriodData:
db.child("Homerooms").child(h[0]).child(h[1]).child(
"Absent").child(date).child(period).update({'notes': currPeriodData['notes']+'; '+notes})
else:
db.child("Homerooms").child(h[0]).child(h[1]).child(
"Absent").child(date).child(period).update({'notes': notes})
os.remove(os.path.join('temp', rand)) os.remove(os.path.join('temp', rand))
return redirect('/manage') return redirect('/manage')
@ -299,11 +314,15 @@ def group_teach_publish():
def homeroom_abs_publish(): def homeroom_abs_publish():
if (check_login_status()): if (check_login_status()):
return redirect('/logout') return redirect('/logout')
date = request.form['date'] date = request.form['date']
homeroom = request.form['homeroom'].split('^') homeroom = request.form['homeroom'].split('^')
period = request.form['period'] period = request.form['period']
signature = request.form['signatureData'] signature = request.form['signatureData']
formData = request.form.to_dict()
notes = ""
if 'notes' in request.form:
notes = request.form['notes']
formData.pop('notes')
signature = signature.removeprefix('data:image/png;base64,') signature = signature.removeprefix('data:image/png;base64,')
signature = bytes(signature, 'utf-8') signature = bytes(signature, 'utf-8')
rand = str(randint(100000000000000, 999999999999999)) rand = str(randint(100000000000000, 999999999999999))
@ -312,7 +331,6 @@ def homeroom_abs_publish():
fh.write(base64.decodebytes(signature)) fh.write(base64.decodebytes(signature))
storage.child(os.path.join('signatures', rand) storage.child(os.path.join('signatures', rand)
).put(os.path.join('temp', rand)) ).put(os.path.join('temp', rand))
formData = request.form.to_dict()
formData.pop('signatureData') formData.pop('signatureData')
formData.pop('date') formData.pop('date')
formData.pop('homeroom') formData.pop('homeroom')
@ -323,6 +341,8 @@ def homeroom_abs_publish():
homeroom[1]).child("Absent").child(date).child(period).update({i[1]: int(i[0])}) homeroom[1]).child("Absent").child(date).child(period).update({i[1]: int(i[0])})
db.child("Homerooms").child(homeroom[0]).child(homeroom[1]).child( db.child("Homerooms").child(homeroom[0]).child(homeroom[1]).child(
"Absent").child(date).child(period).update({'signature': str(storage.child(os.path.join('signatures', rand)).get_url(None))}) "Absent").child(date).child(period).update({'signature': str(storage.child(os.path.join('signatures', rand)).get_url(None))})
db.child("Homerooms").child(homeroom[0]).child(homeroom[1]).child(
"Absent").child(date).child(period).update({'notes': notes})
os.remove(os.path.join('temp', rand)) os.remove(os.path.join('temp', rand))
return redirect('/manage') return redirect('/manage')

View file

@ -29,8 +29,8 @@
{% endfor %} {% endfor %}
</select> </select>
</form> </form>
{% set alr_fill = namespace(found=false) %}
{% for i in absData %} {% for i in absData %}
{% set alr_fill = namespace(found=false) %}
<form action="/manage/group_teach_publish" id="attendanceData^{{i}}" method="post"> <form action="/manage/group_teach_publish" id="attendanceData^{{i}}" method="post">
<input type="hidden" name="date" value="{{currDate}}"> <input type="hidden" name="date" value="{{currDate}}">
<input type="hidden" name="period" value="{{i}}"> <input type="hidden" name="period" value="{{i}}">
@ -105,6 +105,9 @@
</div> </div>
<h3>Please Sign Below</h3> <h3>Please Sign Below</h3>
<div class="forSign"><canvas id="signature_pad^{{i}}"></canvas></div> <div class="forSign"><canvas id="signature_pad^{{i}}"></canvas></div>
<h3>Notes 備註欄</h3>
<input class="form-control" name="notes" id="subjectNotes^{{i}}" placeholder="Enter Notes 請輸入備註"
style="width: 80%; margin-left: 10%;">
<button class="btn btn-secondary" type="button" onclick="signaturePad.clear()">Clear <button class="btn btn-secondary" type="button" onclick="signaturePad.clear()">Clear
Signature</button><button class="btn btn-primary" type="button" Signature</button><button class="btn btn-primary" type="button"
onclick="submitForm()">Submit</button> onclick="submitForm()">Submit</button>

View file

@ -132,6 +132,7 @@
<input type="text" id="HR-date" name="date" value="{{currDate}}"> <input type="text" id="HR-date" name="date" value="{{currDate}}">
<input type="text" id="HR-period" name="period" value=""> <input type="text" id="HR-period" name="period" value="">
<input type="text" id="HR-signatureData" name="signatureData" value=""> <input type="text" id="HR-signatureData" name="signatureData" value="">
<input type="text" id="HR-notes" name="notes" value="">
<input type="text" id="HR-homeroom" name="homeroom" value="{{homeroomCode[0]}}^{{homeroomCode[1]}}"> <input type="text" id="HR-homeroom" name="homeroom" value="{{homeroomCode[0]}}^{{homeroomCode[1]}}">
</form> </form>
{% if 'confirm' in absData[currDate] %} {% if 'confirm' in absData[currDate] %}
@ -146,16 +147,19 @@
<div class="alert alert-warning" id="allPresentWarning" role="alert" hidden="hidden"> <div class="alert alert-warning" id="allPresentWarning" role="alert" hidden="hidden">
<h4 class="alert-heading">請確認是否全班全到Please check if everyone is present!</h4> <h4 class="alert-heading">請確認是否全班全到Please check if everyone is present!</h4>
</div> </div>
<h3>Please Sign Below <br> <h3>Please Sign Below 請在底下簽名<br>
Period: <span id="showSignPeriod"></span> <br> Period: <span id="showSignPeriod"></span> <br>
Subject: <span id="showSignSubjectName"></span> Subject: <span id="showSignSubjectName"></span>
</h3> </h3>
<div class="forSign"><canvas id="signature_pad"></canvas></div> <div class="forSign"><canvas id="signature_pad"></canvas></div>
<h3>Notes 備註欄</h3>
<input type="textarea" class="form-control" name="notes" id="subjectNotes"
placeholder="Enter Notes 請輸入備註" style="width: 80%; margin-left: 10%;" row="3">
<button class="btn btn-secondary" type="button" onclick="signaturePad.clear()">Clear Signature</button> <button class="btn btn-secondary" type="button" onclick="signaturePad.clear()">Clear Signature</button>
<button class="btn btn-primary" type="button" onclick="submitForm()">Submit</button> <button class="btn btn-primary" type="button" onclick="submitForm()">Submit</button>
</div> </div>
{% for c in range(periods|length + 1) %} {% for c in range(periods|length + 1) %}
{% if c % 2 == 0 %} {% if c % 4 == 0 %}
<div class="row signatures"> <div class="row signatures">
{% endif %} {% endif %}
<div class="col half"> <div class="col half">
@ -167,7 +171,8 @@
{% if 'signature' in absData[currDate][periods[c-1]] %} {% if 'signature' in absData[currDate][periods[c-1]] %}
{% for i in absData[currDate][periods[c-1]]['signature'] %} {% for i in absData[currDate][periods[c-1]]['signature'] %}
<div class="row">{{periods[c-1]}}: {{absData[currDate][periods[c-1]]['teacher']}}: {{i}}</div> <div class="row">{{periods[c-1]}}: {{absData[currDate][periods[c-1]]['teacher']}}: {{i}}</div>
<div class="row"><img src="{{absData[currDate][periods[c-1]]['signature'][i]}}" alt=""></div> <div class="row"><img src="{{absData[currDate][periods[c-1]]['signature'][i]}}" alt=""><br>備註:
{{absData[currDate][periods[c-1]]['notes']}}</div>
{% endfor %} {% endfor %}
{% else %} {% else %}
<div class="row">{{periods[c-1]}}: {{absData[currDate][periods[c-1]]['teacher']}}: No Signature <div class="row">{{periods[c-1]}}: {{absData[currDate][periods[c-1]]['teacher']}}: No Signature
@ -178,11 +183,12 @@
<div class="row">{{periods[c-1]}}: {{absData[currDate][periods[c-1]]['name']}}: <div class="row">{{periods[c-1]}}: {{absData[currDate][periods[c-1]]['name']}}:
{{absData[currDate][periods[c-1]]['teacher']}} {{absData[currDate][periods[c-1]]['teacher']}}
</div> </div>
<div class="row"><img src="{{absData[currDate][periods[c-1]]['signature']}}" alt=""></div> <div class="row"><img src="{{absData[currDate][periods[c-1]]['signature']}}" alt=""><br>備註:
{{absData[currDate][periods[c-1]]['notes']}}</div>
{% endif %} {% endif %}
{% endif %} {% endif %}
</div> </div>
{% if c % 2 == 1 %} {% if c % 4 == 3 %}
</div> </div>
{% endif %} {% endif %}
{% endfor %} {% endfor %}
@ -226,7 +232,9 @@
$('#hrCfrm-sign').val(data); $('#hrCfrm-sign').val(data);
document.getElementById('homeroom_confirm').submit() document.getElementById('homeroom_confirm').submit()
} else { } else {
var notes = $('#subjectNotes').val();
document.getElementById('HR-signatureData').value = data; document.getElementById('HR-signatureData').value = data;
document.getElementById('HR-notes').value = notes;
document.getElementById('postHomeroomAbs').submit(); document.getElementById('postHomeroomAbs').submit();
} }
} }