diff --git a/911_namelist.csv b/911_namelist.csv deleted file mode 100644 index b79ea46..0000000 --- a/911_namelist.csv +++ /dev/null @@ -1,35 +0,0 @@ -number,name,eng_name -1,朱昱翧,Themis -2,余欣璇,Zoe -3,吳丞育,Audrey -4,吳欣芃,Lisa -5,吳苡瑄,Rachel -6,王怡捷,Audrey -7,林子琳,Emma -8,林思佑,Una -9,林珈年,Jessica -10,姜心唯,Misha -11,張庭暄,Chang -12,許詠淳,Catherine -13,陳宣彤,idk -14,羅子珊,Shannon -15,蘇宜柔,Chloe -16,王邦熹,Wallace -17,李秉謙,Alan -18,劉青懷,idk -19,林稟翔,Wilbert -20,柯喬勳,Joshua -21,馮顗中,idk -22,張睿恩,Brian -23,姜廉竣,idk -24,陳允昊,Jeremy -25,陳宣豪,Demetris -26,陳宥嘉,Joseph -27,陳麟泳,Aaron -28,賀凱強,Jonathan -29,楊上霆,Chase -30,楊承武,Ben -31,廖建瑋,Daniel -32,潘逸,James -33,朱禹安,Iforgot -34,徐敏萱,idk \ No newline at end of file diff --git a/911_simple_gplist.csv b/911_simple_gplist.csv deleted file mode 100644 index e273a55..0000000 --- a/911_simple_gplist.csv +++ /dev/null @@ -1,35 +0,0 @@ -number,3-IG -1,1103-01 -2,1103-01 -3,1103-02 -4,1103-01 -5,1103-01 -6,1103-02 -7,1103-01 -8,1103-01 -9,1103-01 -10,1103-01 -11,1103-01 -12,1103-01 -13,1103-02 -14,1103-01 -15,1103-02 -16,1103-01 -17,1103-02 -18,1103-02 -19,1103-01 -20,1103-02 -21,1103-01 -22,1103-02 -23,1103-01 -24,1103-02 -25,1103-02 -26,1103-02 -27,1103-01 -28,1103-02 -29,1103-01 -30,1103-01 -31,1103-01 -32,1103-01 -33,1103-02 -34,1103-01 \ No newline at end of file diff --git a/912_beforeformat.csv b/912_beforeformat.csv deleted file mode 100644 index 03c53c9..0000000 --- a/912_beforeformat.csv +++ /dev/null @@ -1,35 +0,0 @@ -number,name,eng_name,3-IG -1,王子芯,Heidi,1103-01 -2,朱宸儀,Megan,1103-01 -3,牟奇薇,Summer,1103-02 -4,吳偲梵,Sophia,1103-01 -5,林書誼,Charlotte,1103-01 -6,林葦亭,Chelsea,1103-02 -7,凌孟妍,Iris,1103-01 -8,翁翊婷,Evelyn,1103-01 -9,郭倚熏,Patty,1103-01 -10,陳宣穎,Renee,1103-01 -11,曾若霏,Danielle,1103-01 -12,湯家綺,Joanna,1103-01 -13,黃以甯,Kate,1103-02 -14,黃玄,Cheryl,1103-01 -15,劉煒琪,Winona,1103-02 -16,潘俞希,Alina,1103-01 -17,鄭軒,Jasper,1103-02 -18,吳彥縢,Austin,1103-02 -19,吳昶佑,Eric,1103-01 -20,李翊愷,Aaron Lee,1103-02 -21,李翊誠,Alex,1103-01 -22,曹庭睿,Alvin,1103-02 -23,莊家睿,Gary,1103-01 -24,張馨予,Cindy,1103-02 -25,常有慈,Cindy,1103-02 -26,陳柏元,Michael,1103-02 -27,陳雋喆,Derek,1103-01 -28,曾柏皓,Cory,1103-02 -29,黃獻主,Arthur,1103-01 -30,盧秉漢,Hiro,1103-01 -31,李文,Tom,1103-01 -32,謝承霖,Walter,1103-01 -33,關義,Aaron Kuan,1103-02 -34,謝佾儒,Yi-Ju,1103-01 \ No newline at end of file diff --git a/912_gplist.csv b/912_gplist.csv deleted file mode 100644 index 6ef585f..0000000 --- a/912_gplist.csv +++ /dev/null @@ -1,35 +0,0 @@ -number,3-IG,2-TEST -1,1103-01,1102-5 -2,1103-01,1102-5 -3,1103-02,1102-5 -4,1103-01,1102-5 -5,1103-01,1102-5 -6,1103-02,1102-5 -7,1103-01,1102-5 -8,1103-01,1102-5 -9,1103-01,1102-5 -10,1103-01,1102-5 -11,1103-01,1102-5 -12,1103-01,1102-5 -13,1103-02,1102-5 -14,1103-01,1102-5 -15,1103-02,1102-5 -16,1103-01,1102-5 -17,1103-02,1102-5 -18,1103-02,1102-5 -19,1103-01,1102-5 -20,1103-02,1102-5 -21,1103-01,1102-9 -22,1103-02,1102-9 -23,1103-01,1102-9 -24,1103-02,1102-9 -25,1103-02,1102-9 -26,1103-02,1102-9 -27,1103-01,1102-9 -28,1103-02,1102-9 -29,1103-01,1102-9 -30,1103-01,1102-9 -31,1103-01,1102-9 -32,1103-01,1102-9 -33,1103-02,1102-9 -34,1103-01,1102-9 \ No newline at end of file diff --git a/912_namelist.csv b/912_namelist.csv deleted file mode 100644 index 3d68bd4..0000000 --- a/912_namelist.csv +++ /dev/null @@ -1,35 +0,0 @@ -number,name,eng_name -1,王子芯,Heidi -2,朱宸儀,Megan -3,牟奇薇,Summer -4,吳偲梵,Sophia -5,林書誼,Charlotte -6,林葦亭,Chelsea -7,凌孟妍,Iris -8,翁翊婷,Evelyn -9,郭倚熏,Patty -10,陳宣穎,Renee -11,曾若霏,Danielle -12,湯家綺,Joanna -13,黃以甯,Kate -14,黃玄,Cheryl -15,劉煒琪,Winona -16,潘俞希,Alina -17,鄭軒,Jasper -18,吳彥縢,Austin -19,吳昶佑,Eric -20,李翊愷,Aaron Lee -21,李翊誠,Alex -22,曹庭睿,Alvin -23,莊家睿,Gary -24,張馨予,Cindy -25,常有慈,Cindy -26,陳柏元,Michael -27,陳雋喆,Derek -28,曾柏皓,Cory -29,黃獻主,Arthur -30,盧秉漢,Hiro -31,李文,Tom -32,謝承霖,Walter -33,關義,Aaron Kuan -34,謝佾儒,Yi-Ju \ No newline at end of file diff --git a/912_simple_gplist.csv b/912_simple_gplist.csv deleted file mode 100644 index e273a55..0000000 --- a/912_simple_gplist.csv +++ /dev/null @@ -1,35 +0,0 @@ -number,3-IG -1,1103-01 -2,1103-01 -3,1103-02 -4,1103-01 -5,1103-01 -6,1103-02 -7,1103-01 -8,1103-01 -9,1103-01 -10,1103-01 -11,1103-01 -12,1103-01 -13,1103-02 -14,1103-01 -15,1103-02 -16,1103-01 -17,1103-02 -18,1103-02 -19,1103-01 -20,1103-02 -21,1103-01 -22,1103-02 -23,1103-01 -24,1103-02 -25,1103-02 -26,1103-02 -27,1103-01 -28,1103-02 -29,1103-01 -30,1103-01 -31,1103-01 -32,1103-01 -33,1103-02 -34,1103-01 \ No newline at end of file diff --git a/app.py b/app.py index e7fca03..f28c9bb 100644 --- a/app.py +++ b/app.py @@ -1,12 +1,12 @@ from flask import * import pyrebase from datetime import datetime -import time import pytz -from sendgrid import SendGridAPIClient -from sendgrid.helpers.mail import Mail import csv import os +import pandas as pd +import base64 +from random import randint from dotenv import load_dotenv from pprint import pprint load_dotenv() @@ -26,6 +26,7 @@ config = { firebase = pyrebase.initialize_app(config) db = firebase.database() auth = firebase.auth() +storage = firebase.storage() tz = pytz.timezone('Asia/Taipei') @@ -42,149 +43,138 @@ def manageProcess(fCommand, fData): # end bug fix pl = db.child("Users").child( session['uid']).child("permission").get().val() - print(pl) - print(db.child("Users").child( - 'DRZqqSSpg3OkPSCuWkv417dv0vh1').child("permission").get().val()) - print(fCommand, fData, session['uid'], pl) if pl == 'admin': - return pl + homerooms = db.child("Homerooms").get().val() + currRoom = [] + if fCommand == "admin": + currRoom = fData[0].split("^") + else: + for i in homerooms: + currRoom.append(i) + for j in homerooms[i]: + currRoom.append(j) + break + break + homeroomData = homerooms[currRoom[0]][currRoom[1]] + absData = homeroomData["Absent"] + homeroomData.pop('Absent') + homeroomData.pop('placeholder') + currDate = "" + if fCommand != "": + currDate = fData[1] + else: + for i in absData: + currDate = i + if i >= datetime.now(tz).strftime("%Y-%m-%d"): + break + return render_template('admin.html', homerooms=homerooms, absData=absData, homeroomCode=currRoom, homeroomData=homeroomData, currDate=currDate, periods=['m', '1', '2', '3', '4', 'n', '5', '6', '7', '8', '9']) elif pl == 'group': classes = db.child("Users").child( session['uid']).child("class").get().val() cclass = {} + cateData = {} for i in classes: + cateData = db.child("Classes").child( + "GP_Class").child(i).get().val() cclass = { - "name": db.child("Classes").child(i).child( - "Class").child(classes[i]).child("name").get().val(), + "name": cateData['Class'][classes[i]]['name'], + "teacher": cateData['Class'][classes[i]]['teacher'], + "classroom": cateData['Class'][classes[i]]['classroom'], "category": i, "class_id": classes[i] } print("got class") - students = db.child("Classes").child(cclass['category']).child( - "Class").child(cclass['class_id']).child("Students").get().val() - print(students['9']['11']) - all_stud_list = {} - for grade in students: - print(grade) - all_stud_list[grade] = {} - print(type(students[grade])) - for homeroom in students[grade]: - print(homeroom) - roomData = db.child("Homerooms").child( - grade).child(homeroom).get().val() - all_stud_list[grade][homeroom] = {} - if type(students[grade][homeroom]) == list: - i = 0 - for student in students[grade][homeroom]: - if student == 0: - all_stud_list[grade][homeroom][i] = { - "name": roomData[str(i)]["name"], - "eng_name": roomData[str(i)]["eng_name"] - } - i += 1 - else: - for student in students[grade][homeroom]: - print(student) - all_stud_list[grade][homeroom][student] = { - "name": roomData[student]["name"], - "eng_name": roomData[student]["eng_name"] - } - print("got students") - dates = db.child("Classes").child( - cclass['category']).child("Dates").get().val() - status = 0 - attendance = {} + homerooms = cateData['Homerooms'] + currDate = "" + absData = {} + for h in homerooms: + h = h.split('^') + print(h) + hrData = db.child("Homerooms").child(h[0]).child(h[1]).get().val() + tmpAbsData = hrData['Absent'] + hrData.pop('Absent') + hrData.pop('placeholder') + periods = [] + dow = "" + if currDate == "": + if fCommand == 'date': + currDate = fData + for j in tmpAbsData[currDate]: + if j == "dow": + dow = tmpAbsData[currDate][j] + continue + elif j == "confirm": + continue + if (tmpAbsData[currDate][j]['name'] == 'GP' and + tmpAbsData[currDate][j]['teacher'] == cclass['category']): + periods.append(j) - if fCommand == 'date': - currDate = fData - if cclass['class_id'] in dates[currDate]: - status = 1 - for grade in dates[currDate]['Absent']: - attendance[grade] = {} - for homeroom in dates[currDate]['Absent'][grade]: - attendance[grade][homeroom] = {} - for student in dates[currDate]['Absent'][grade][homeroom]: - attendance[grade][homeroom][student] = 0 - else: - for i in dates: - if i >= datetime.now(tz).strftime("%Y-%m-%d"): - currDate = i - if cclass['class_id'] in dates[currDate]: - status = 1 - for grade in dates[currDate]['Absent']: - attendance[grade] = {} - for homeroom in dates[currDate]['Absent'][grade]: - attendance[grade][homeroom] = {} - for student in dates[currDate]['Absent'][grade][homeroom]: - attendance[grade][homeroom][student] = 0 - break - dates[i].pop('placeholder') - print("got dates") - return render_template('group_teach.html', cclass=cclass, all_stud_list=all_stud_list, dates=dates, currDate=currDate, status=status, attendance=attendance) + else: + for i in tmpAbsData: + currDate = i + if i >= datetime.now(tz).strftime("%Y-%m-%d"): + tmp = False + for j in tmpAbsData[i]: + if j == "dow": + dow = tmpAbsData[i][j] + continue + elif j == "confirm": + continue + if (tmpAbsData[i][j]['name'] == 'GP' and + tmpAbsData[i][j]['teacher'] == cclass['category']): + periods.append(j) + tmp = True + if tmp == True: + break + else: + for j in tmpAbsData[currDate]: + if j == "dow": + dow = tmpAbsData[currDate][j] + continue + elif j == "confirm": + continue + if (tmpAbsData[currDate][j]['name'] == 'GP' and + tmpAbsData[currDate][j]['teacher'] == cclass['category']): + periods.append(j) + for p in periods: + if not p in absData: + absData[p] = {} + for p in periods: + if not h[0] in absData[p]: + absData[p][h[0]] = {} + absData[p][h[0]][h[1]] = {} + for num in hrData: + if (cclass['category'] in hrData[num]['GP_Class'] and + hrData[num]['GP_Class'][cclass['category']] == cclass['class_id']): + for p in periods: + 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']), + "absent": num in tmpAbsData[currDate][p] + } + print(absData) + return render_template('group_teach.html', cclass=cclass, absData=absData, dow=dow, currDate=currDate, tmpAbsData=tmpAbsData) elif pl == 'homeroom': homeroom = db.child("Users").child( - session['uid']).child("homeroom").get().val() - homeroomCode = homeroom.split('^') - homeroom = db.child("Homerooms").child( - homeroomCode[0]).child(homeroomCode[1]).get().val() - categories = homeroom['Categories'].split('^') - currCategory = categories[0] + session['uid']).child("homeroom").get().val().split('^') + homeroomData = db.child("Homerooms").child(homeroom[0]).child( + homeroom[1]).get().val() + absData = homeroomData["Absent"] + homeroomData.pop('Absent') + homeroomData.pop('placeholder') currDate = "" - gpClasses = db.child("Classes").child(currCategory).get().val() - dates = gpClasses['Dates'] - confirmedClasses = [] - status = 0 - if fCommand == 'date': currDate = fData - tmp1 = 0 - tmp2 = 0 - for k in gpClasses['Class']: - if k in dates[currDate]: - confirmedClasses.append(k) - tmp2 += 1 - tmp1 += 1 - if tmp1 == tmp2: - status = 1 else: - for i in dates: + for i in absData: + currDate = i if i >= datetime.now(tz).strftime("%Y-%m-%d"): - currDate = i - tmp1 = 0 - tmp2 = 0 - for k in gpClasses['Class']: - if k in dates[currDate]: - confirmedClasses.append(k) - tmp2 += 1 - tmp1 += 1 - if tmp1 == tmp2: - status = 1 break - print("got dates") - db.child("Classes").child(currCategory).child("Dates") - homeroom.pop('Categories') - all_stud_list = {} - for i in homeroom: - all_stud_list[i] = {} - all_stud_list[i]['name'] = homeroom[i]['name'] - all_stud_list[i]['eng_name'] = homeroom[i]['eng_name'] - all_stud_list[i]['gpClass'] = homeroom[i]['Classes'][currCategory] - if all_stud_list[i]['gpClass'] in confirmedClasses: - if (homeroomCode[0] in gpClasses['Dates'][currDate]['Absent'] and - homeroomCode[1] in gpClasses['Dates'][currDate]['Absent'][homeroomCode[0]] and - i in gpClasses['Dates'][currDate]['Absent'][homeroomCode[0]][homeroomCode[1]]): - # confirmed by teacher and absent - all_stud_list[i]['status'] = 2 - else: - # confirmed by teacher and not absent - all_stud_list[i]['status'] = 1 - else: - all_stud_list[i]['status'] = 0 # not yet confirmed by teacher - return render_template('homeroom.html', all_stud_list=all_stud_list, currDate=currDate, dates=dates, gpClasses=gpClasses, confirmedClasses=confirmedClasses, - currCategory=currCategory, categories=categories, homeroomCode=homeroomCode, status=status) - + 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']) else: - return redirect('/') + return redirect('/logout') @ app.route('/', methods=['GET', 'POST']) @@ -211,17 +201,26 @@ def index(): return redirect('/manage') -@app.route('/manage', methods=['GET']) +@ app.route('/manage', methods=['GET']) def manage(): return manageProcess("", "") -@app.route('/manage/date', methods=['POST']) +@ app.route('/manage/date', methods=['POST']) def manage_date(): return manageProcess("date", request.form['date']) -@app.route('/manage/group_teach_publish', methods=['POST']) +@app.route('/manage/admin', methods=['POST']) +def manage_admin(): + data = [ + request.form['grade'] + '^' + request.form['room'], + request.form['date'] + ] + return manageProcess("admin", data) + + +@ app.route('/manage/group_teach_publish', methods=['POST']) def group_teach_publish(): classes = db.child("Users").child( session['uid']).child("class").get().val() @@ -231,28 +230,83 @@ def group_teach_publish(): "name": db.child("Classes").child(i).child( "Class").child(classes[i]).child("name").get().val(), "category": i, - "class_id": classes[i] + "class_id": classes[i], + "homerooms": db.child("Classes").child( + "GP_Class").child(i).child("Homerooms").get().val() } print("got class") - cDate = "" - for key in request.form.keys(): - print(type(key), key) - if key == 'date': - print('here') - cDate = request.form[key] - db.child("Classes").child(cclass['category']).child( - "Dates").child(request.form[key]).update({'confirmed': 0}) - db.child("Classes").child(cclass['category']).child( - "Dates").child(request.form[key]).update({cclass['class_id']: request.form['signatureData']}) - elif key == 'signatureData': - pass - else: - # spilt string - id = key.split('^') - print(id) - db.child("Classes").child(cclass['category']).child("Dates").child( - cDate).child("Absent").child(id[0]).child(id[1]).update({id[2]: 1}) - return "Success!" + date = request.form['date'] + period = request.form['period'] + signature = request.form['signatureData'] + signature = signature.removeprefix('data:image/png;base64,') + signature = bytes(signature, 'utf-8') + rand = str(randint(100000000000000, 999999999999999)) + rand += ".png" + with open(os.path.join('temp', rand), "wb") as fh: + fh.write(base64.decodebytes(signature)) + storage.child(os.path.join('signatures', rand) + ).put(os.path.join('temp', rand)) + + formData = request.form.to_dict() + formData.pop('signatureData') + formData.pop('date') + formData.pop('period') + for i in formData: + i = i.split('^') + db.child("Homerooms").child(i[0]).child(i[1]).child( + "Absent").child(date).child(period).update({i[2]: 0}) + for h in cclass['homerooms']: + h = h.split('^') + 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))}) + os.remove(os.path.join('temp', rand)) + return redirect('/manage') + + +@ app.route('/manage/homeroom_abs', methods=['POST']) +def homeroom_abs_publish(): + date = request.form['date'] + homeroom = request.form['homeroom'].split('^') + period = request.form['period'] + signature = request.form['signatureData'] + signature = signature.removeprefix('data:image/png;base64,') + signature = bytes(signature, 'utf-8') + rand = str(randint(100000000000000, 999999999999999)) + rand += ".png" + with open(os.path.join('temp', rand), "wb") as fh: + fh.write(base64.decodebytes(signature)) + storage.child(os.path.join('signatures', rand) + ).put(os.path.join('temp', rand)) + formData = request.form.to_dict() + formData.pop('signatureData') + formData.pop('date') + formData.pop('homeroom') + formData.pop('period') + for i in formData: + db.child("Homerooms").child(homeroom[0]).child( + homeroom[1]).child("Absent").child(date).child(period).update({i: 0}) + 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))}) + os.remove(os.path.join('temp', rand)) + return redirect('/manage') + + +@app.route('/manage/homeroom_confirm', methods=['POST']) +def homeroom_confirm(): + date = request.form['date'] + homeroom = request.form['homeroom'].split('^') + signature = request.form['signatureData'] + signature = signature.removeprefix('data:image/png;base64,') + signature = bytes(signature, 'utf-8') + rand = str(randint(100000000000000, 999999999999999)) + rand += ".png" + with open(os.path.join('temp', rand), "wb") as fh: + fh.write(base64.decodebytes(signature)) + storage.child(os.path.join('signatures', rand) + ).put(os.path.join('temp', rand)) + db.child("Homerooms").child(homeroom[0]).child(homeroom[1]).child("Absent").child(date).update( + {"confirm": str(storage.child(os.path.join('signatures', rand)).get_url(None))}) + return redirect('/manage') @ app.route('/upload/homeroom', methods=['GET', 'POST']) @@ -280,6 +334,36 @@ def upload_homeroom(): return "Successfully uploaded " + gradec + "-" + classc +@ app.route('/upload/gp_classes', methods=['GET', 'POST']) +def upload_gp_classes(): + if request.method == 'GET': + return render_template('uploadcsv.html', title="Group Classes", url="/upload/gp_classes") + elif request.method == 'POST': + try: + csv_file = request.files['csv'] + filepath = os.path.join('./temp', csv_file.filename) + csv_file.save(filepath) + csv_dict = pd.read_csv(filepath) + category_cnt = csv_dict.shape[1] - 1 + for i in range(category_cnt): + tmp_csv = csv_dict[csv_dict.columns[i+1]].tolist() + for j in range(len(tmp_csv)): + if type(tmp_csv[j]) == float: + break + if j % 4 == 0: + db.child("Classes").child("GP_Class").child(csv_dict.columns[i+1]).child("Class").child( + tmp_csv[j]).child("name").set(tmp_csv[j+1]) + db.child("Classes").child("GP_Class").child(csv_dict.columns[i+1]).child("Class").child( + tmp_csv[j]).child("teacher").set(tmp_csv[j+2]) + db.child("Classes").child("GP_Class").child(csv_dict.columns[i+1]).child("Class").child( + tmp_csv[j]).child("classroom").set(tmp_csv[j+3]) + os.remove(filepath) + except Exception as e: + os.remove(filepath) + return "Error. Please try again\n("+str(e)+")" + return "Successfully uploaded" + + @ app.route('/upload/stud_in_group', methods=['GET', 'POST']) def upload_stud_in_group(): if request.method == 'GET': @@ -295,13 +379,13 @@ def upload_stud_in_group(): csv_dict = csv.DictReader(file) headers = csv_dict.fieldnames headers = headers[1:] + for h in headers: + db.child("Classes").child("GP_Class").child( + h).child("Homerooms").update({gradec+'^'+classc: 0}) for row in csv_dict: for h in headers: db.child("Homerooms").child(gradec).child(classc).child( - row['number']).child("Classes").child(h).set(row[h]) - db.child("Classes").child(h).child("Class").child(row[h]).child( - "Students").child(gradec).child(classc).update({str(row['number']): 0}) - + row['number']).child("GP_Class").update({h: row[h]}) os.remove(filepath) except Exception as e: os.remove(filepath) @@ -309,6 +393,76 @@ def upload_stud_in_group(): return "Successfully uploaded " + gradec + "-" + classc +@ app.route('/upload/period_list', methods=['GET', 'POST']) +def upload_period_list(): + if request.method == 'GET': + return render_template('uploadcsv.html', title="Period List", url="/upload/period_list") + elif request.method == 'POST': + try: + # get csv + gradec = request.form['gradeCode'] + classc = request.form['classcode'] + csv_file = request.files['csv'] + filepath = os.path.join('./temp', csv_file.filename) + csv_file.save(filepath) + csv_dict = pd.read_csv(filepath) + periodCodes = csv_dict['Period Day'].tolist() + for i in range(5): + tmp_csv = csv_dict[str(i+1)].tolist() + print(tmp_csv) + for j in range(len(tmp_csv)): + if not (periodCodes[j].endswith('-t')): + if type(tmp_csv[j]) == float: + db.child("Classes").child("Homeroom").child(gradec).child(classc).child( + str(i+1)).child(periodCodes[j]).update({'name': '--'}) + else: + db.child("Classes").child("Homeroom").child(gradec).child(classc).child( + str(i+1)).child(periodCodes[j]).update({'name': tmp_csv[j]}) + if not(periodCodes[j] == 'm' or periodCodes[j] == 'n'): + j += 1 + db.child("Classes").child("Homeroom").child(gradec).child(classc).child( + str(i+1)).child(periodCodes[j-1]).update({'teacher': tmp_csv[j]}) + os.remove(filepath) + except Exception as e: + os.remove(filepath) + return "Error. Please try again\n("+str(e)+")" + return "Successfully uploaded " + gradec + "-" + classc + + +@ app.route('/upload/dates', methods=['GET', 'POST']) +def upload_dates(): + if request.method == 'GET': + return render_template('uploadcsv.html', title="School Days", url="/upload/dates") + elif request.method == 'POST': + try: + csv_file = request.files['csv'] + filepath = os.path.join('./temp', csv_file.filename) + csv_file.save(filepath) + with open(filepath) as file: + csv_dict = csv.DictReader(file) + headers = csv_dict.fieldnames + temp = db.child("Homerooms").get().val() + for row in csv_dict: + for h in headers: + for t in temp: + for i in temp[t]: + periodData = db.child("Classes").child( + "Homeroom").child(t).child(i).get().val() + print(type(t), t) + print(type(i), i) + db.child("Homerooms").child(t).child(i).child( + "Absent").child(h).update({"dow": row[h]}) + db.child("Homerooms").child(t).child(i).child( + "Absent").child(h).update( + periodData[int(row[h])] + ) + os.remove(filepath) + except Exception as e: + os.remove(filepath) + return "Error. Please try again\n("+str(e)+")" + return "Successfully uploaded dates" + + # @ app.route('/upload/rm_all_data_of_class', methods=['GET', "POST"]) # def rm_all_data_of_class(): # if request.method == 'GET': @@ -322,7 +476,7 @@ def upload_stud_in_group(): # return "Successfully removed " + classc -@app.route('/logout', methods=['GET']) +@ app.route('/logout', methods=['GET']) def logout(): session.clear() return redirect('/') diff --git a/requirements.txt b/requirements.txt index ac87e83..a38c6ca 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,13 +7,13 @@ Flask == 2.0.1 # Attendance/test.py: 1 Pyrebase == 3.0.27 -# Attendance/app.py: 9 +# Attendance/app.py: 7 +pandas == 1.1.3 + +# Attendance/app.py: 10 # Attendance/test.py: 3 python_dotenv == 0.19.0 # Attendance/app.py: 4 pytz == 2020.1 - -# Attendance/app.py: 5,6 -sendgrid == 6.7.1 gunicorn == 20.1.0 \ No newline at end of file diff --git a/static/allpages.css b/static/allpages.css index 2486ace..93cd24a 100644 --- a/static/allpages.css +++ b/static/allpages.css @@ -30,6 +30,14 @@ div.forSign canvas { height: 100%; } +.margin-bottom { + margin-bottom: 50px; +} + +div.signDiv { + margin-bottom: 50px; +} + p.highlightAbs { margin-bottom: 0; } @@ -42,6 +50,6 @@ p.highlightAbs.n-2 { color: red; } -div.classlist { - text-align: left; +.margin-top { + margin-top: 20px; } \ No newline at end of file diff --git a/static/homeroom.css b/static/homeroom.css new file mode 100644 index 0000000..9bb9ba8 --- /dev/null +++ b/static/homeroom.css @@ -0,0 +1,22 @@ +div.container { + max-width: 90%; +} + +.btn.afterSelButton { + padding: .200rem .50rem; +} + + +body { + text-align: center; +} + +.viewSignatures .col .row .col { + border: 1px solid; + margin-bottom: 10px; + text-align: center; +} + +.row { + --bs-gutter-x: 0; +} \ No newline at end of file diff --git a/templates/admin.html b/templates/admin.html index e69de29..8f08de5 100644 --- a/templates/admin.html +++ b/templates/admin.html @@ -0,0 +1,221 @@ + + + +
+ + + +X
+V
+V
+- {% if all_stud_list[i]['status'] == 1 %} - V - {% elif all_stud_list[i]['status'] == 2 %} - X - {% endif %} -
+X
V
+V
+If you are not the adminstrator, please do not click "upload" This might make the system + unuseable.
+非管理員請勿點選! 可能會讓系統無法使用!
+