diff --git a/.gitignore b/.gitignore index 02ebca1..8ed1e58 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,4 @@ *.DS_Store *.env -test.py -demoData/* -dummyData/* -users.txt +test*.* __pycache__/* \ No newline at end of file diff --git a/functions.py b/functions.py index c918d56..2be0eb9 100644 --- a/functions.py +++ b/functions.py @@ -76,3 +76,10 @@ def addZeroesUntil(str, number): else: str = str + '0' return addZeroesUntil(str, number) + + +# MANAGE +def removeprefix(s, prefix): + if s.startswith(prefix): + return s[len(prefix):] + return s diff --git a/manage.py b/manage.py index e5d60b4..12f6b95 100644 --- a/manage.py +++ b/manage.py @@ -3,12 +3,6 @@ from functions import * manage = Blueprint('manage', __name__) -def removeprefix(s, prefix): - if s.startswith(prefix): - return s[len(prefix):] - return s - - def manageProcess(fCommand, fData): if (check_login_status()): return redirect('/logout') @@ -134,8 +128,8 @@ def manageProcess(fCommand, fData): absData[p][h[0]][h[1]][num] = { "name": hrData[num]['name'], "eng_name": hrData[num]['eng_name'], - "alr_fill": ('signature' in tmpAbsData[currDate][p] and - cclass['class_id'] in tmpAbsData[currDate][p]['signature']), + "alr_fill": (('signature' in tmpAbsData[currDate][p]) and + (cclass['class_id'] in tmpAbsData[currDate][p]['signature'] or 'STUD_AFFAIR_OFFICE' in tmpAbsData[currDate][p]['signature'])), "absent": False if not num in tmpAbsData[currDate][p] else tmpAbsData[currDate][p][num] } return render_template('group_teach.html', dateKeys=sorted(tmpAbsData.keys()), cclass=cclass, absData=absData, dow=dow, currDate=currDate, tmpAbsData=tmpAbsData, confirmed=confirmed) @@ -254,8 +248,6 @@ def group_teach_publish(): else: db.child("Homerooms").child(h[0]).child(h[1]).child( "Absent").child(date).child(period).update({'notes': notes}, session['token']) - - # upload notes os.remove(os.path.join('temp', rand)) return redirect('/manage') @@ -269,15 +261,6 @@ 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(): @@ -310,6 +293,52 @@ def homeroom_abs_publish(): return redirect('/manage') +@manage.route('/manage/edit_abs', methods=['POST']) +def edit_abs(): + if (check_login_status() or not check_permission()): + return redirect('/logout') + refresh_token() + date = request.form['date'] + homeroom = request.form['homeroom'].split('^') + period = request.form['period'] + signature = "https://firebasestorage.googleapis.com/v0/b/attendance-be176.appspot.com/o/stud_affairs.png?alt=media" + formData = request.form.to_dict() + notes = "" + oldData = list(db.child("Homerooms").child(homeroom[0]).child(homeroom[1]).child( + "Absent").child(date).child(period).shallow().get(session['token']).val()) + 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']) + cfrmstatus = db.child("Homerooms").child(homeroom[0]).child( + homeroom[1]).child("Absent").child(date).get(session['token']).val() + if "confirm" in cfrmstatus: + db.child("Homerooms").child(homeroom[0]).child(homeroom[1]).child( + "Absent").child(date).update({'notes': cfrmstatus['notes'] + '; (確認後學務處有更改)'}, session['token']) + if 'notes' in request.form: + notes = request.form['notes'] + formData.pop('notes') + formData.pop('date') + formData.pop('homeroom') + formData.pop('period') + for i in formData: + i = i.split('^') + db.child("Homerooms").child(homeroom[0]).child( + homeroom[1]).child("Absent").child(date).child(period).update({i[1]: int(i[0])}, session['token']) + db.child("Homerooms").child(homeroom[0]).child(homeroom[1]).child( + "Absent").child(date).child(period).update({'notes': notes}, session['token']) + if cfrmstatus[period]['name'] == 'GP': + db.child("Homerooms").child(homeroom[0]).child( + homeroom[1]).child("Absent").child(date).child(period).child("signature").set({'STUD_AFFAIR_OFFICE': signature}, session['token']) + db.child("Homerooms").child(homeroom[0]).child( + homeroom[1]).child("Absent").child(date).child(period).child("names").set({'STUD_AFFAIR_OFFICE': "學務處已編輯"}, session['token']) + else: + db.child("Homerooms").child(homeroom[0]).child( + homeroom[1]).child("Absent").child(date).child(period).child("signature").set(signature, session['token']) + return redirect('/manage/admin/'+homeroom[0]+'/'+homeroom[1]+'/'+date) + + @manage.route('/manage/homeroom_confirm', methods=['POST']) def homeroom_confirm(): if (check_login_status()): diff --git a/static/pagejs/admin.js b/static/pagejs/admin.js index 4ca9ea8..67f68ef 100644 --- a/static/pagejs/admin.js +++ b/static/pagejs/admin.js @@ -24,3 +24,55 @@ function redirAdmin() { $('.container').hide(); $('#loading').show(); } + +function edit(string) { + $('.view-' + string).each(function (i, obj) { + var num = $(this.firstElementChild).attr('class').split(' ')[2].replace('view-n-', ''); + if ($(this.firstElementChild).attr('class').split(' ')[1] == "n-1") { + $(this).html("") + $(this).append(""); + $(this).append("\n"); + } else if ($(this.firstElementChild).attr('class').split(' ')[1] == "n-2") { + $(this).html("") + $(this).append(""); + $(this).append("\n"); + } else if ($(this.firstElementChild).attr('class').split(' ')[1] == "n-3") { + $(this).html("") + $(this).append(""); + $(this).append("\n"); + } + }); + $('#btns-' + string).html("") + $('.afterSelButton').attr('disabled', 'disabled'); + $('#btns-' + string).append(""); +} + +function unCheckLate(string) { + document.getElementById('late^' + string).checked = false; +} +function unCheckAbs(string) { + document.getElementById('absent^' + string).checked = false; +} + +function afterSelAbs(period) { + $('#postHomeroomAbs #HR-period').attr('value', period); + $('.tobeform').attr('disabled', 'disabled'); + $('.afterSelButton').attr('disabled', 'disabled'); + $('.tobeform').each(function (i, obj) { + if ($(this).attr('class').split(' ')[1].split('^')[1] == period && + $(this).is(":checked")) { + $('#postHomeroomAbs').append(''); + } + }); + $('#finalCheck').modal('show'); +} + +function submitForm() { + $('#HR-notes').attr('value', $('#subjectNotes').val()); + $('#postHomeroomAbs').submit(); + $('#finalCheck').modal('hide'); + $('.container').hide(); + $('#loading').show(); +} \ No newline at end of file diff --git a/static/pagejs/homeroom.js b/static/pagejs/homeroom.js index 3394142..5a8de85 100644 --- a/static/pagejs/homeroom.js +++ b/static/pagejs/homeroom.js @@ -57,7 +57,6 @@ function showSignaturePad() { resizeCanvas(); } function afterSelAbs(period) { - var tobeformArr = []; $('#postHomeroomAbs #HR-period').attr('value', period); $('.tobeform').attr('disabled', 'disabled'); $('.afterSelButton').attr('disabled', 'disabled'); diff --git a/static/stud_affairs.png b/static/stud_affairs.png new file mode 100644 index 0000000..106f40a Binary files /dev/null and b/static/stud_affairs.png differ diff --git a/static/stud_affairs.xcf b/static/stud_affairs.xcf new file mode 100644 index 0000000..402f419 Binary files /dev/null and b/static/stud_affairs.xcf differ diff --git a/templates/admin.html b/templates/admin.html index b2b4db8..693ddb8 100644 --- a/templates/admin.html +++ b/templates/admin.html @@ -60,14 +60,14 @@
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
+ absData[currDate][j]['signature'] or 'STUD_AFFAIR_OFFICE' in absData[currDate][j]['signature'])%} +V
{% else %} - + {% endif %} {% endif %} {% endif %} @@ -135,7 +131,28 @@ {% endfor %}