diff --git a/.gitignore b/.gitignore index 8ed1e58..4591ab2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ *.DS_Store *.env test*.* -__pycache__/* \ No newline at end of file +__pycache__/* +excel/* \ No newline at end of file diff --git a/app.py b/app.py index 8349ebd..4104c90 100644 --- a/app.py +++ b/app.py @@ -1,5 +1,5 @@ from functions import * -from manage import manage +from manage.manage import manage from upload import upload from login import login load_dotenv() @@ -20,6 +20,7 @@ class DefaultModelView(ModelView): restricted = True def __init__(self, model, session, restricted=True, name=None, category=None, endpoint=None, url=None, **kwargs): self.restricted = restricted + self.column_default_sort = ('id', True) for k, v in kwargs.items(): setattr(self, k, v) setattr(self, 'can_export', True) @@ -145,4 +146,4 @@ admin.add_link(MenuLink(name='Back to Home 返回一般管理', category='', url admin.add_link(MenuLink(name='Logout 登出', category='', url='/logout')) if __name__ == '__main__': - app.run(debug=True, host='0.0.0.0', port=5000) + app.run(debug=True, host='0.0.0.0', port=5050) diff --git a/export.py b/export.py new file mode 100644 index 0000000..facb606 --- /dev/null +++ b/export.py @@ -0,0 +1,333 @@ +from functions import * +from openpyxl import Workbook +from openpyxl.styles import Font, Alignment, Border, Side +import io + +center = Alignment(horizontal="center", vertical="center") +std_font = Font(name="Calibri", size=13) +side = Side(border_style='thin') +border = Border(left=side, right=side, top=side, bottom=side) +bold_bottom = Border(left=side, right=side, top=side, bottom=Side(border_style='medium', color='FF000000')) + +def create_period_sheets(workbook, class_code): + ws = workbook.create_sheet(class_code[0] + class_code[1]) + ws.merge_cells('A1:F1') + ws['A1'] = '台北市私立復興實驗高級中學班級課表' + ws['A1'].font = Font(name="DFKai-SB", size=15, bold=True) + ws['A1'].alignment = center + # loop over A:F + for i in range(0, 6): + ws[str(chr(ord('A') + i)) + '1'].border = border + ws['G1'] = class_code[0] + class_code[1] + ws['G1'].font = Font(name='Courier New', size=20, bold=True) + ws['G1'].alignment = center + ws['G1'].border = border + + ws.row_dimensions[1].height = 40 + ws.row_dimensions[2].height = 25 + ws.column_dimensions['A'].width = 3 + ws.column_dimensions['B'].width = 10 + + ws.merge_cells('A2:B2') + ws['A2'] = '時間' + ws['C2'] = '星期一' + ws['D2'] = '星期二' + ws['E2'] = '星期三' + ws['F2'] = '星期四' + ws['G2'] = '星期五' + + # loop over A2:G2 + for i in range(1, 8): + ws.cell(row=2, column=i).font = Font(size=14, bold=True) + ws.cell(row=2, column=i).alignment = center + ws.cell(row=2, column=i).border = border + + # loop over C:G + for i in range(2, 8): + ws.column_dimensions[str(chr(ord('A') + i))].width = 13 + + # get data + db = refresh_db() + cursor = db.cursor() + cursor.execute("SELECT dow,period,subject,teacher FROM schedule WHERE grade=%s AND class_=%s", (class_code[0], class_code[1])) + sql = cursor.fetchall() + data = {} + subject_teacher = {} + # loop over data + for i in sql: + if i[0] not in data: + data[i[0]] = {} + data[i[0]][i[1]] = { + 'subject': i[2], + 'teacher': i[3] + } + if i[2] != 'GP' and i[2] != '--' and i[3] != '--' and i[2] not in subject_teacher: + subject_teacher[i[2]] = i[3] + + periods=['m', '1', '2', '3', '4', 'n', '5', '6', '7', '8', '9'] + times = { + 'm': ['7:30', '8:10'], + '1': ['8:20', '9:05'], + '2': ['9:15', '10:00'], + '3': ['10:10', '10:55'], + '4': ['11:05', '11:50'], + 'n': ['11:50', '13:05'], + '5': ['13:15', '14:00'], + '6': ['14:10', '14:55'], + '7': ['15:05', '15:50'], + '8': ['15:55', '16:40'], + '9': ['16:45', '17:30'] + } + curr = 3 + for p in periods: + ws.merge_cells('A' + str(curr) + ':A' + str(curr + 1)) + ws.row_dimensions[curr].height = 20 + ws.row_dimensions[curr + 1].height = 20 + ws['A' + str(curr)] = p + ws['A' + str(curr)].font = std_font + ws['A' + str(curr)].alignment = center + ws['A' + str(curr)].border = border + ws['A' + str(curr + 1)].border = border + ws['B' + str(curr)] = times[p][0] + ws['B' + str(curr)].font = std_font + ws['B' + str(curr)].alignment = center + ws['B' + str(curr)].border = border + ws['B' + str(curr + 1)] = times[p][1] + ws['B' + str(curr + 1)].font = std_font + ws['B' + str(curr + 1)].alignment = center + ws['B' + str(curr + 1)].border = border + + if p == 'm' or p == 'n': + ws.merge_cells('C' + str(curr) + ':G' + str(curr + 1)) + for i in range(1, 6): + ws[chr(ord('C') + i-1) + str(curr)].font = std_font + ws[chr(ord('C') + i-1) + str(curr)].alignment = center + ws[chr(ord('C') + i-1) + str(curr)].border = border + ws[chr(ord('C') + i-1) + str(curr + 1)].border = border + if p == 'm': + ws['C' + str(curr)] = '早自習' + else: + ws['C' + str(curr)] = '午餐 / 午休' + else: + for i in range(1, 6): + ws.merge_cells(chr(ord('C') + i-1) + str(curr) + ':' + chr(ord('C') + i-1) + str(curr + 1)) + ws[chr(ord('C') + i-1) + str(curr)].font = std_font + ws[chr(ord('C') + i-1) + str(curr)].alignment = center + ws[chr(ord('C') + i-1) + str(curr)].border = border + ws[chr(ord('C') + i-1) + str(curr + 1)].border = border + if i in data: + if p in data[i]: + ws[chr(ord('C') + i-1) + str(curr)] = (data[i][p]['subject'] if data[i][p]['subject'] != 'GP' + and data[i][p]['subject'] != '--' else '' if data[i][p]['subject'] == '--' else data[i][p]['teacher']) + curr += 2 + ws.merge_cells('A26:G26') + ws['A26'] = '科任老師一覽表' + ws['A26'].font = Font(size=14, bold=True) + ws['A26'].alignment = center + ws.row_dimensions[26].height = 20 + # loop over A26:G26 + for i in range(0, 7): + ws[chr(ord('A') + i) + '26'].border = border + curr = 0 + for i in subject_teacher: + if (curr % 3) == 0: + pos = ['A', 'C'] + elif (curr % 3) == 1: + pos = ['D', 'E'] + else: + pos = ['F', 'G'] + loc = str(27+ int(curr/3)) + ws.merge_cells(pos[0] + loc + ':' + pos[1] + loc) + ws[pos[0] + loc].font = std_font + ws[pos[0] + loc].alignment = center + ws[pos[0] + loc].border = border + ws[pos[0] + loc] = i + ': ' + subject_teacher[i] + for j in range(ord(pos[0]), ord(pos[1]) + 1): + ws[chr(j) + loc].border = border + ws.row_dimensions[curr + 27].height = 20 + curr += 1 + return workbook + +def create_student_list(workbook, class_code): + ws = workbook.create_sheet(class_code[0] + class_code[1]) + ws.merge_cells('A1:J1') + ws['A1'] = '台北市私立復興實驗高級中學學生名單' + ws['A1'].font = Font(name="DFKai-SB", size=15, bold=True) + ws['A1'].alignment = center + # loop over A:J + for i in range(0, 11): + ws[str(chr(ord('A') + i)) + '1'].border = border + ws.merge_cells('K1:L1') + ws['K1'] = class_code[0] + class_code[1] + ws['K1'].font = Font(name='Courier New', size=20, bold=True) + ws['K1'].alignment = center + ws['K1'].border = border + ws['L1'].border = border + ws.column_dimensions['A'].width = 5 + ws.column_dimensions['B'].width = 11 + ws.column_dimensions['C'].width = 12 + ws.row_dimensions[1].height = 25 + ws.row_dimensions[2].height = 20 + + ws['A2'] = '#' + ws['A2'].font = Font(name="Calibri", size=13, bold=True) + ws['A2'].alignment = center + ws['A2'].border = bold_bottom + ws['B2'] = '姓名' + ws['B2'].font = Font(name="DFKai-SB", size=13, bold=True) + ws['B2'].alignment = center + ws['B2'].border = bold_bottom + ws['C2'] = 'Name' + ws['C2'].font = Font(name="Calibri", size=13, bold=True) + ws['C2'].alignment = center + ws['C2'].border = bold_bottom + for i in range(3, 12): + ws[str(chr(ord('A') + i)) + '2'].border = bold_bottom + ws.column_dimensions[str(chr(ord('A') + i))].width = 5.8 + db = refresh_db() + cursor = db.cursor() + cursor.execute('SELECT num,name,ename FROM students WHERE grade=%s AND class_=%s ORDER BY num ASC', (class_code[0], class_code[1])) + data = cursor.fetchall() + last = data[-1][0] + delcnt = 0 + for i in range(0, last): + ws['A' + str(3 + i)] = i+1 + ws['A' + str(3 + i)].font = std_font + ws['A' + str(3 + i)].alignment = center + ws['B' + str(3 + i)] = data[i - delcnt][1] if data[i - delcnt][0] == i+1 else '' + ws['B' + str(3 + i)].font = Font(name="DFKai-SB", size=14) + ws['B' + str(3 + i)].alignment = center + ws['C' + str(3 + i)] = data[i - delcnt][2] if data[i - delcnt][0] == i+1 else '' + ws['C' + str(3 + i)].font = std_font + ws['C' + str(3 + i)].alignment = center + ws.row_dimensions[3 + i].height = 19 + for j in range(0, 12): + ws[str(chr(ord('A') + j)) + str(3 + i)].border = bold_bottom if (i+1)%5==0 else border + if data[i - delcnt][0] != i+1: + delcnt += 1 + return workbook + +def create_teacher_periods(workbook, teacher_name, orig_username=''): + ws = workbook.create_sheet(teacher_name) + ws.merge_cells('A1:E1') + ws['A1'] = '台北市私立復興實驗高級中學科任老師課表' + ws['A1'].font = Font(name="DFKai-SB", size=15, bold=True) + ws['A1'].alignment = center + # loop over A:E + for i in range(0, 5): + ws[str(chr(ord('A') + i)) + '1'].border = border + ws.merge_cells('F1:G1') + ws['F1'] = teacher_name + " 老師" + ws['F1'].font = Font(name='Calibri', size=15, bold=True) + ws['F1'].alignment = center + ws['F1'].border = border + ws['G1'].border = border + + ws.row_dimensions[1].height = 40 + ws.row_dimensions[2].height = 25 + ws.column_dimensions['A'].width = 3 + ws.column_dimensions['B'].width = 10 + + ws.merge_cells('A2:B2') + ws['A2'] = '時間' + ws['C2'] = '星期一' + ws['D2'] = '星期二' + ws['E2'] = '星期三' + ws['F2'] = '星期四' + ws['G2'] = '星期五' + + # loop over A2:G2 + for i in range(1, 8): + ws.cell(row=2, column=i).font = Font(size=14, bold=True) + ws.cell(row=2, column=i).alignment = center + ws.cell(row=2, column=i).border = border + + # loop over C:G + for i in range(2, 8): + ws.column_dimensions[str(chr(ord('A') + i))].width = 13 + + # get data + data = {} + db = refresh_db() + cursor = db.cursor() + if orig_username is not '': + cursor.execute('SELECT category,subclass FROM gpclasses WHERE accs LIKE %s', ('%'+orig_username+'%',)) + gp_sql = cursor.fetchall() + for i in gp_sql: + cursor.execute('SELECT dow,period FROM schedule WHERE teacher=%s', (i[0], )) + tmp_sql = cursor.fetchall() + for j in tmp_sql: + if j[0] not in data: + data[j[0]] = {} + data[j[0]][j[1]] = { + 'subject': i[0], + 'class': i[1] + } + cursor.execute("SELECT dow,period,subject,grade,class_ FROM schedule WHERE teacher=%s", (teacher_name, )) + sql = cursor.fetchall() + # loop over data + for i in sql: + if i[0] not in data: + data[i[0]] = {} + data[i[0]][i[1]] = { + 'subject': i[2], + 'class': str(i[3]) + str(i[4]) + } + + periods=['m', '1', '2', '3', '4', 'n', '5', '6', '7', '8', '9'] + times = { + 'm': ['7:30', '8:10'], + '1': ['8:20', '9:05'], + '2': ['9:15', '10:00'], + '3': ['10:10', '10:55'], + '4': ['11:05', '11:50'], + 'n': ['11:50', '13:05'], + '5': ['13:15', '14:00'], + '6': ['14:10', '14:55'], + '7': ['15:05', '15:50'], + '8': ['15:55', '16:40'], + '9': ['16:45', '17:30'] + } + curr = 3 + for p in periods: + ws.merge_cells('A' + str(curr) + ':A' + str(curr + 1)) + ws.row_dimensions[curr].height = 20 + ws.row_dimensions[curr + 1].height = 20 + ws['A' + str(curr)] = p + ws['A' + str(curr)].font = std_font + ws['A' + str(curr)].alignment = center + ws['A' + str(curr)].border = border + ws['A' + str(curr + 1)].border = border + ws['B' + str(curr)] = times[p][0] + ws['B' + str(curr)].font = std_font + ws['B' + str(curr)].alignment = center + ws['B' + str(curr)].border = border + ws['B' + str(curr + 1)] = times[p][1] + ws['B' + str(curr + 1)].font = std_font + ws['B' + str(curr + 1)].alignment = center + ws['B' + str(curr + 1)].border = border + + if p == 'm' or p == 'n': + ws.merge_cells('C' + str(curr) + ':G' + str(curr + 1)) + for i in range(1, 6): + ws[chr(ord('C') + i-1) + str(curr)].font = std_font + ws[chr(ord('C') + i-1) + str(curr)].alignment = center + ws[chr(ord('C') + i-1) + str(curr)].border = border + ws[chr(ord('C') + i-1) + str(curr + 1)].border = border + if p == 'm': + ws['C' + str(curr)] = '早自習' + else: + ws['C' + str(curr)] = '午餐 / 午休' + else: + for i in range(1, 6): + ws.merge_cells(chr(ord('C') + i-1) + str(curr) + ':' + chr(ord('C') + i-1) + str(curr + 1)) + ws[chr(ord('C') + i-1) + str(curr)].font = std_font + ws[chr(ord('C') + i-1) + str(curr)].border = border + ws[chr(ord('C') + i-1) + str(curr + 1)].border = border + ws[chr(ord('C') + i-1) + str(curr)].alignment = center + Alignment(wrapText=True) + if i in data: + if p in data[i]: + ws[chr(ord('C') + i-1) + str(curr)] = (data[i][p]['subject'] + '\n' + data[i][p]['class'] if data[i][p]['subject'] != 'GP' + and data[i][p]['subject'] != '--' else '' if data[i][p]['subject'] == '--' else data[i][p]['teacher']) + curr += 2 + return workbook \ No newline at end of file diff --git a/login.py b/login.py index 1553454..aa55bd2 100644 --- a/login.py +++ b/login.py @@ -283,7 +283,6 @@ def resetPassword(): WHERE resetID = %s """, (request.args.get('resetCode'),)) user = cursor.fetchone() - cursor.close() dtnow = datetime.now(tz).replace(tzinfo=None) if user == None: raise Exception('無此重置密碼代碼
Invalid reset password code') diff --git a/manage/__pycache__/admin.cpython-39.pyc b/manage/__pycache__/admin.cpython-39.pyc new file mode 100644 index 0000000..c8ad650 Binary files /dev/null and b/manage/__pycache__/admin.cpython-39.pyc differ diff --git a/manage/__pycache__/group.cpython-39.pyc b/manage/__pycache__/group.cpython-39.pyc new file mode 100644 index 0000000..3711296 Binary files /dev/null and b/manage/__pycache__/group.cpython-39.pyc differ diff --git a/manage/__pycache__/homeroom.cpython-39.pyc b/manage/__pycache__/homeroom.cpython-39.pyc new file mode 100644 index 0000000..2797977 Binary files /dev/null and b/manage/__pycache__/homeroom.cpython-39.pyc differ diff --git a/manage/__pycache__/manage.cpython-39.pyc b/manage/__pycache__/manage.cpython-39.pyc new file mode 100644 index 0000000..8c562c7 Binary files /dev/null and b/manage/__pycache__/manage.cpython-39.pyc differ diff --git a/manage/__pycache__/student.cpython-39.pyc b/manage/__pycache__/student.cpython-39.pyc new file mode 100644 index 0000000..a74af62 Binary files /dev/null and b/manage/__pycache__/student.cpython-39.pyc differ diff --git a/manage/admin.py b/manage/admin.py new file mode 100644 index 0000000..23296b2 --- /dev/null +++ b/manage/admin.py @@ -0,0 +1,139 @@ +from functions import * +from export import * +admin = Blueprint('admin', __name__) + +@admin.route('/manage/admin/mark', methods=['GET', 'POST']) +def mark_absent(): + if (check_login_status() or session['subuser_type'] != 'admin'): + return redirect('/logout') + refresh_token() + if request.method == 'POST': + try: + data = request.form.to_dict() + periods = [i[7] for i in data if i.startswith('period-')] + db = refresh_db() + cursor = db.cursor() + for p in periods: + cursor.execute("INSERT INTO absent (grade, class_, date, period, num, status, note) VALUES (%s, %s, %s, %s, %s, %s, %s)", + (data['grade'], data['class'], data['date'], p, data['num'], data['type'], data['notes'] if 'notes' in data else '')) + db.commit() + except Exception as e: + flash(e) + else: + flash("`成功! (" + data['grade'] + data['class'] + "班" + data['num'] + "號, 日期: " + data['date'] + ", 總計 " + str(len(periods)) + "堂課)") + return redirect('/manage/admin/mark') + db = refresh_db() + cursor = db.cursor() + cursor.execute("SELECT grade, class_, num, name FROM students ORDER BY grade,class_,num ASC") + sql = cursor.fetchall() + students = {} + for i in sql: + if i[0] not in students: + students[i[0]] = {} + if i[1] not in students[i[0]]: + students[i[0]][i[1]] = {} + students[i[0]][i[1]][i[2]] = i[3] + cursor.execute("SELECT date,period,grade,class_,num,status,note FROM absent ORDER BY id DESC LIMIT 10") + records = cursor.fetchall() + return render_template("admin_mark.html", students=students, periods=['m', '1', '2', '3', '4', 'n', '5', '6', '7', '8', '9'], records=records, hideSel=True) + +@admin.route('/manage/admin/export', methods=['GET']) +def admin_export(): + if (check_login_status() or session['subuser_type'] != 'admin'): + return redirect('/logout') + refresh_token() + return render_template("admin_export.html", hideSel=True) + +@admin.route('/manage/admin/export/homeroom_period', methods=['POST']) +def admin_export_homeroom_period(): + if (check_login_status() or session['subuser_type'] != 'admin'): + return redirect('/logout') + refresh_token() + workbook = Workbook() + workbook.remove_sheet(workbook.get_sheet_by_name('Sheet')) + workbook = create_period_sheets(workbook, [request.form['grade'], request.form['class']]) + excel_stream = io.BytesIO() + workbook.save(excel_stream) + excel_stream.seek(0) + return send_file(excel_stream, attachment_filename='homeroom_period_' + request.form['grade'] + request.form['class'] +'.xlsx', as_attachment=True) + +@admin.route('/manage/admin/export/homeroom_period/all', methods=['GET']) +def admin_export_homeroom_period_all(): + if (check_login_status() or session['subuser_type'] != 'admin'): + return redirect('/logout') + refresh_token() + db = refresh_db() + cursor = db.cursor() + cursor.execute("SELECT grade,class_ FROM homerooms") + homerooms = cursor.fetchall() + workbook = Workbook() + workbook.remove_sheet(workbook.get_sheet_by_name('Sheet')) + for i in homerooms: + workbook = create_period_sheets(workbook, [str(i[0]), str(i[1])]) + excel_stream = io.BytesIO() + workbook.save(excel_stream) + excel_stream.seek(0) + return send_file(excel_stream, attachment_filename='homeroom_period_all.xlsx', as_attachment=True) + + +@admin.route('/manage/admin/export/student_list', methods=['POST']) +def admin_export_student_list(): + if (check_login_status() or session['subuser_type'] != 'admin'): + return redirect('/logout') + refresh_token() + workbook = Workbook() + workbook.remove_sheet(workbook.get_sheet_by_name('Sheet')) + workbook = create_student_list(workbook, [request.form['grade'], request.form['class']]) + excel_stream = io.BytesIO() + workbook.save(excel_stream) + excel_stream.seek(0) + return send_file(excel_stream, attachment_filename='student_list_' + request.form['grade'] + request.form['class'] +'.xlsx', as_attachment=True) + +@admin.route("/manage/admin/export/student_list/all", methods=['GET']) +def admin_export_student_list_all(): + if (check_login_status() or session['subuser_type'] != 'admin'): + return redirect('/logout') + refresh_token() + db = refresh_db() + cursor = db.cursor() + cursor.execute("SELECT grade,class_ FROM homerooms") + homerooms = cursor.fetchall() + workbook = Workbook() + workbook.remove_sheet(workbook.get_sheet_by_name('Sheet')) + for i in homerooms: + workbook = create_student_list(workbook, [str(i[0]), str(i[1])]) + excel_stream = io.BytesIO() + workbook.save(excel_stream) + excel_stream.seek(0) + return send_file(excel_stream, attachment_filename='student_list_all.xlsx', as_attachment=True) + +@admin.route('/manage/admin/export/teacher_period', methods=['POST']) +def admin_export_teacher_period(): + if (check_login_status() or session['subuser_type'] != 'admin'): + return redirect('/logout') + refresh_token() + workbook = Workbook() + workbook.remove_sheet(workbook.get_sheet_by_name('Sheet')) + workbook = create_teacher_periods(workbook, request.form['name'], request.form['orig_username']) + excel_stream = io.BytesIO() + workbook.save(excel_stream) + excel_stream.seek(0) + return send_file(excel_stream, attachment_filename='teacher_period_' + request.form['name'] + '_' + ('' if 'orig_username' not in request.form else request.form['orig_username']) +'.xlsx', as_attachment=True) + +@admin.route('/manage/admin/export/teacher_period/all', methods=['GET']) +def admin_export_teacher_period_all(): + if (check_login_status() or session['subuser_type'] != 'admin'): + return redirect('/logout') + refresh_token() + db = refresh_db() + cursor = db.cursor() + cursor.execute("SELECT name,oldUsername FROM users") + teachers = cursor.fetchall() + workbook = Workbook() + workbook.remove_sheet(workbook.get_sheet_by_name('Sheet')) + for i in teachers: + workbook = create_teacher_periods(workbook, i[0], i[1]) + excel_stream = io.BytesIO() + workbook.save(excel_stream) + excel_stream.seek(0) + return send_file(excel_stream, attachment_filename='teacher_period_all.xlsx', as_attachment=True) \ No newline at end of file diff --git a/manage/group.py b/manage/group.py new file mode 100644 index 0000000..9f5a7b2 --- /dev/null +++ b/manage/group.py @@ -0,0 +1,102 @@ +from functions import * +group = Blueprint('group', __name__) + +@group.route('/manage/group_teach_publish', methods=['POST']) +def group_teach_publish(): + if (check_login_status()): + return redirect('/logout') + refresh_token() + data = request.form.to_dict() + cclass = { + "category": data.pop('category'), + "class_id": data.pop('class_id') + } + db = refresh_db() + cursor = db.cursor() + cursor.execute("SELECT about FROM gpclasses WHERE category=%s AND subclass=%s", + (cclass['category'], cclass['class_id'])) + cclass["name"] = cursor.fetchone()[0] + cursor.execute("SELECT grade,class_,num,name,ename FROM students WHERE classes LIKE " + '\'%\"'+ cclass['category'] + '\": \"' + cclass['class_id'] +'\"%\'' + " ORDER BY grade ASC,class_ ASC,num ASC") + students = cursor.fetchall() + homerooms = [] + for x in students: + if (str(x[0]) + '^' + str(x[1])) not in homerooms: + homerooms.append(str(x[0]) + '^' + str(x[1])) + data.pop('dsnumbers') + data.pop('dsoffense') + data.pop('dsoffenseother') + date = data.pop('date') + period = data.pop('period') + signature = data.pop('signatureData') + notes = data.pop('notes') + submissionType = data.pop('submissionType') + if (submissionType == 'newAbsent'): + absentData = [] + for x in data: + xs = x.split('^') + if xs[0] == 'note': + continue + else: + absentData.append([xs[1], xs[2], xs[3], 'K' if xs[0] == '1' else 'L', data['note^'+xs[1]+'^'+xs[2]+'^'+xs[3]]]) + for h in homerooms: + h = h.split('^') + cursor = db.cursor() + cursor.execute(""" + SELECT signature, notes FROM submission WHERE grade=%s AND class_=%s AND date=%s AND period=%s + """, (h[0], h[1], date, period)) + one = cursor.fetchone() + if one is None: + jSignature = json.dumps({cclass['class_id']: signature}) + cursor.execute(""" + INSERT INTO submission (grade, class_, date, period, signature, notes) + VALUES (%s, %s, %s, %s, %s, %s) + """, (h[0], h[1], date, period, jSignature, notes)) + db.commit() + else: + jSignature = json.loads(one[0]) + if cclass['class_id'] in jSignature: + continue + jSignature[cclass['class_id']] = signature + note = one[1] + '; ' + notes + cursor.execute(""" + UPDATE submission SET signature=%s, notes=%s WHERE grade=%s AND class_=%s AND date=%s AND period=%s + """, (json.dumps(jSignature), note, h[0], h[1], date, period)) + db.commit() + for a in absentData: + cursor = db.cursor() + cursor.execute(""" + INSERT INTO absent (grade, class_, num, date, period, status, note) + VALUES (%s, %s, %s, %s, %s, %s, %s) + """, (a[0], a[1], a[2], date, period, a[3], a[4])) + db.commit() + elif (submissionType == 'dsSubmit'): + dsData = [] + for x in data: + xs = x.split('^') + if xs[0] == 'note': + continue + elif xs[0] == 'ds': + dsData.append([xs[1], xs[2].split('-')[0], xs[2].split('-')[1], data[x]]) + for h in homerooms: + h = h.split('^') + cursor = db.cursor() + cursor.execute(""" + SELECT dscfrm, notes FROM submission WHERE grade=%s AND class_=%s AND date=%s AND period=%s + """, (h[0], h[1], date, period)) + one = cursor.fetchone() + dsCfrm = [] if one[0] == None else json.loads(one[0]) + if cclass['class_id'] in dsCfrm: + continue + dsCfrm.append(cclass['class_id']) + note = one[1] + '; ' + notes + cursor.execute(""" + UPDATE submission SET dsCfrm=%s, notes=%s WHERE grade=%s AND class_=%s AND date=%s AND period=%s + """, (json.dumps(dsCfrm), note, h[0], h[1], date, period)) + for d in dsData: + cursor = db.cursor() + cursor.execute(""" + INSERT INTO ds (grade, class_, num, date, period, note) + VALUES (%s, %s, %s, %s, %s, %s) + """, (d[0], d[1], d[2], date, period, d[3])) + db.commit() + return redirect('/manage') \ No newline at end of file diff --git a/manage/homeroom.py b/manage/homeroom.py new file mode 100644 index 0000000..33cc03e --- /dev/null +++ b/manage/homeroom.py @@ -0,0 +1,141 @@ +from functions import * +homeroom = Blueprint('homeroom', __name__) + +@homeroom.route('/manage/abs', methods=['GET']) +def showAllAbs(): + if (check_login_status()): + return redirect('/logout') + refresh_token() + currRoom = session['homeroom'].split('^') + db = refresh_db() + cursor = db.cursor() + cursor.execute("SELECT num,name,ename FROM students WHERE grade=%s AND class_=%s ORDER BY num ASC", (currRoom[0], currRoom[1])) + studentsSQL = cursor.fetchall() + students = {} + for st in studentsSQL: + students[st[0]] = { + 'name': st[1], + 'ename': st[2], + } + cursor = db.cursor() + cursor.execute("SELECT date, period, num, status, note FROM absent WHERE grade=%s AND class_=%s ORDER BY date DESC, FIND_IN_SET(period, 'm,1,2,3,4,n,5,6,7,8,9') DESC, num ASC", (currRoom[0], currRoom[1])) + absentDataSQL = cursor.fetchall() + return render_template("list.html", title="Absent List | 缺勤紀錄", mode='ABS', students=students, data=absentDataSQL, currRoom=currRoom) + +@homeroom.route('/manage/ds', methods=['GET']) +def showAllDS(): + if (check_login_status()): + return redirect('/logout') + refresh_token() + currRoom = session['homeroom'].split('^') + db = refresh_db() + cursor = db.cursor() + cursor.execute("SELECT num,name,ename FROM students WHERE grade=%s AND class_=%s ORDER BY num ASC", (currRoom[0], currRoom[1])) + studentsSQL = cursor.fetchall() + students = {} + for st in studentsSQL: + students[st[0]] = { + 'name': st[1], + 'ename': st[2], + } + cursor = db.cursor() + cursor.execute("SELECT date, period, num, note FROM ds WHERE grade=%s AND class_=%s ORDER BY date DESC, FIND_IN_SET(period, 'm,1,2,3,4,n,5,6,7,8,9') DESC, num ASC", (currRoom[0], currRoom[1])) + dsDataSQL = cursor.fetchall() + return render_template("list.html", title="DS List | 定心紀錄", mode='DS', students=students, data=dsDataSQL, currRoom=currRoom) + +@homeroom.route('/manage/homeroom_abs', methods=['POST']) +def homeroom_abs_publish(): + if (check_login_status()): + return redirect('/logout') + refresh_token() + db = refresh_db() + data = request.form.to_dict() + date = data.pop('date') + period = data.pop('period') + signature = data.pop('signatureData') + notes = data.pop('notes') + homeroom = data.pop('homeroom').split('^') + absentData = {} + for x in data: + xt = x.split('^') + if (xt[0] == 'note'): + if xt[2] not in absentData: + absentData[xt[2]] = {} + absentData[xt[2]]['note'] = data[x] + else: + if xt[1] not in absentData: + absentData[xt[1]] = {} + absentData[xt[1]]['status'] = 'L' if x[0] == '2' else 'K' + cursor = db.cursor() + cursor.execute(""" + INSERT INTO submission + (grade, class_, date, period, signature, notes) + VALUES (%s, %s, %s, %s, %s, %s) + """, (homeroom[0], homeroom[1], date, period, signature, notes)) + for x in absentData: + cursor.execute(""" + INSERT INTO absent + (grade, class_, date, period, num, status, note) + VALUES (%s, %s, %s, %s, %s, %s, %s) + """, (homeroom[0], homeroom[1], date, period, x, absentData[x]['status'], absentData[x]['note'] if 'note' in absentData[x] else '')) + db.commit() + return redirect('/manage') + +@homeroom.route('/manage/homeroom_ds', methods=['POST']) +def homeroom_ds_publish(): + if (check_login_status()): + return redirect('/logout') + refresh_token() + db = refresh_db() + cursor = db.cursor() + data = request.form.to_dict() + print(data) + date = data.pop('date') + period = data.pop('period') + notes = ';' + data.pop('notes') + homeroom = data.pop('homeroom').split('^') + dsidv = {} + ds1 = data.pop('ds^1') + ds2 = data.pop('ds^2') + ds3 = data.pop('ds^3') + ds4 = data.pop('ds^4') + ds5 = data.pop('ds^5') + ds6 = data.pop('ds^6') + ds7 = data.pop('ds^7') + cursor.execute(""" + UPDATE submission + SET ds1=%s,ds2=%s,ds3=%s,ds4=%s,ds5=%s,ds6=%s,ds7=%s,notes=concat(ifnull(notes,""), %s),dscfrm='yes' + WHERE grade=%s AND class_=%s AND date=%s AND period=%s + """, (ds1, ds2, ds3, ds4, ds5, ds6, ds7, notes, homeroom[0], homeroom[1], date, period)) + for x in data: + xt = x.split('^') + if (xt[0] == 'dsidv'): + dsidv[xt[1]] = data[x] + for x in dsidv: + cursor.execute(""" + INSERT INTO ds + (grade, class_, date, period, num, note) + VALUES (%s, %s, %s, %s, %s, %s) + """, (homeroom[0], homeroom[1], date, period, x, dsidv[x])) + db.commit() + return redirect('/manage') + +@homeroom.route('/manage/homeroom_confirm', methods=['POST']) +def homeroom_confirm(): + if (check_login_status()): + return redirect('/logout') + refresh_token() + data = request.form.to_dict() + homeroom = data.pop('homeroom').split('^') + date = data.pop('date') + signature = data.pop('signatureData') + notes = data.pop('notes') + db = refresh_db() + cursor = db.cursor() + cursor.execute(""" + INSERT INTO submission + (grade, class_, date, period, signature, notes) + VALUES (%s, %s, %s, 'c', %s, %s) + """, (homeroom[0], homeroom[1], date, signature, notes)) + db.commit() + return redirect('/manage') diff --git a/manage.py b/manage/manage.py similarity index 60% rename from manage.py rename to manage/manage.py index d3d3d1d..9c5f886 100644 --- a/manage.py +++ b/manage/manage.py @@ -1,6 +1,29 @@ from functions import * - +from manage.homeroom import homeroom +from manage.student import student +from manage.admin import admin +from manage.group import group manage = Blueprint('manage', __name__) +manage.register_blueprint(homeroom) +manage.register_blueprint(student) +manage.register_blueprint(admin) +manage.register_blueprint(group) + +@manage.route('/manage', methods=['GET']) +def manageRoot(): + return manageProcess("", "") + +@homeroom.route('/manage/date/', methods=['GET']) +def manage_date(date): + return manageProcess("date", date) + +@manage.route('/manage/admin///', methods=['GET']) +def manage_admin(g, r, date): + data = [ + g + '^' + r, + date + ] + return manageProcess("admin", data) def manageProcess(fCommand, fData): @@ -182,14 +205,9 @@ def manageProcess(fCommand, fData): if (h not in data[cclass['category'] + ' ' + cclass['class_id']][p[0]]): data[cclass['category'] + ' ' + cclass['class_id']][p[0]][h] = {} cursor = db.cursor() - cursor.execute("SELECT signature FROM submission WHERE grade=%s AND class_=%s AND date=%s AND period=%s", (hs[0], hs[1], currDate, p[0])) + cursor.execute("SELECT signature, dscfrm FROM submission WHERE grade=%s AND class_=%s AND date=%s AND period=%s", (hs[0], hs[1], currDate, p[0])) submissionSQL = cursor.fetchone() submitted = False - try: - if submissionSQL[0] == 'STUD_AFFAIR_OFFICE': - submitted = True - except: - pass try: signatures = json.loads(submissionSQL[0]) if cclass['class_id'] in signatures: @@ -226,6 +244,7 @@ def manageProcess(fCommand, fData): "ename": x[4], "status": status, "note": '' if studStatus == [] else studStatus[0][2], + "needDS": False if hrCfrm != True and submissionSQL[1] != None and cclass['class_id'] in json.loads(submissionSQL[1]) else True } return render_template('group_teach.html', dates=dates, currDate=currDate, data=data, dsoffenses=DSOFFENSES) elif pl == 'homeroom': @@ -291,7 +310,7 @@ def manageProcess(fCommand, fData): "special": True } cursor = db.cursor() - cursor.execute("SELECT period, signature, notes, ds1,ds2,ds3,ds4,ds5,ds6,ds7 FROM submission WHERE grade=%s AND class_=%s AND date=%s", (currRoom[0], currRoom[1], currDate)) + cursor.execute("SELECT period, signature, notes, ds1,ds2,ds3,ds4,ds5,ds6,ds7, dscfrm FROM submission WHERE grade=%s AND class_=%s AND date=%s", (currRoom[0], currRoom[1], currDate)) submissionSQL = cursor.fetchall() cursor = db.cursor() cursor.execute("SELECT period, num, note FROM ds WHERE grade=%s AND class_=%s AND date=%s", (currRoom[0], currRoom[1], currDate)) @@ -328,6 +347,8 @@ def manageProcess(fCommand, fData): "ds6": i[8], "ds7": i[9], } + if i[10] == 'yes': + submission[i[0]]["dscfrm"] = True cursor = db.cursor() cursor.execute("SELECT period, num, status, note FROM absent WHERE grade=%s AND class_=%s AND date=%s", (currRoom[0], currRoom[1], currDate)) absentDataSQL = cursor.fetchall() @@ -342,255 +363,4 @@ def manageProcess(fCommand, fData): return render_template('homeroom.html', currRoom=currRoom, students=students, currDate=currDate, schedule=schedule, submission=submission, currPeriod=currPeriod, studGP=studGP, dates=dates, absentData=absentData, periods=['m', '1', '2', '3', '4', 'n', '5', '6', '7', '8', '9'], dsboard=DSBOARD, dstext=DSTEXT, dsoffenses=DSOFFENSES, idvDS=idvDS) else: - return redirect('/logout') - - -@manage.route('/manage', methods=['GET']) -def manageRoot(): - return manageProcess("", "") - - -@manage.route('/manage/date/', methods=['GET']) -def manage_date(date): - return manageProcess("date", date) - - -@manage.route('/manage/admin///', methods=['GET']) -def manage_admin(g, r, date): - data = [ - g + '^' + r, - date - ] - return manageProcess("admin", data) - -@manage.route('/student', methods=['GET']) -def showStudentAbs(): - if (check_login_status()): - return redirect('/logout') - refresh_token() - if not ('user_type' in session and session['user_type'] == 'student'): - return redirect('/') - db = refresh_db() - cursor = db.cursor() - cursor.execute("SELECT date, period, num, status, note FROM absent WHERE grade=%s AND class_=%s AND num=%s ORDER BY date DESC, period DESC, num ASC", (session['grade'], session['class'], session['num'])) - absentDataSQL = cursor.fetchall() - return render_template("list.html", title="Student Absent List | 學生缺勤紀錄", mode='STUDABS', data=absentDataSQL, currRoom=[session['grade'],session['class']], name=session['name'], num=session['num']) - -@manage.route('/student/ds', methods=['GET']) -def showStudentDS(): - if (check_login_status()): - return redirect('/logout') - refresh_token() - if not ('user_type' in session and session['user_type'] == 'student'): - return redirect('/') - db = refresh_db() - cursor = db.cursor() - cursor.execute("SELECT date, period, num, note FROM ds WHERE grade=%s AND class_=%s AND num=%s ORDER BY date DESC, period DESC, num ASC", (session['grade'], session['class'], session['num'])) - dsDataSQL = cursor.fetchall() - print(dsDataSQL) - return render_template("list.html", title="Student DS List | 學生定心紀錄", mode='STUDDS', data=dsDataSQL, currRoom=[session['grade'],session['class']], name=session['name'], num=session['num']) - -@manage.route('/manage/abs', methods=['GET']) -def showAllAbs(): - if (check_login_status()): - return redirect('/logout') - refresh_token() - currRoom = session['homeroom'].split('^') - db = refresh_db() - cursor = db.cursor() - cursor.execute("SELECT num,name,ename FROM students WHERE grade=%s AND class_=%s ORDER BY num ASC", (currRoom[0], currRoom[1])) - studentsSQL = cursor.fetchall() - students = {} - for st in studentsSQL: - students[st[0]] = { - 'name': st[1], - 'ename': st[2], - } - cursor = db.cursor() - cursor.execute("SELECT date, period, num, status, note FROM absent WHERE grade=%s AND class_=%s ORDER BY date DESC, period DESC, num ASC", (currRoom[0], currRoom[1])) - absentDataSQL = cursor.fetchall() - return render_template("list.html", title="Absent List | 缺勤紀錄", mode='ABS', students=students, data=absentDataSQL, currRoom=currRoom) - -@manage.route('/manage/ds', methods=['GET']) -def showAllDS(): - if (check_login_status()): - return redirect('/logout') - refresh_token() - currRoom = session['homeroom'].split('^') - db = refresh_db() - cursor = db.cursor() - cursor.execute("SELECT num,name,ename FROM students WHERE grade=%s AND class_=%s ORDER BY num ASC", (currRoom[0], currRoom[1])) - studentsSQL = cursor.fetchall() - students = {} - for st in studentsSQL: - students[st[0]] = { - 'name': st[1], - 'ename': st[2], - } - cursor = db.cursor() - cursor.execute("SELECT date, period, num, note FROM ds WHERE grade=%s AND class_=%s ORDER BY date DESC, period DESC, num ASC", (currRoom[0], currRoom[1])) - dsDataSQL = cursor.fetchall() - return render_template("list.html", title="DS List | 定心紀錄", mode='DS', students=students, data=dsDataSQL, currRoom=currRoom) - -@manage.route('/manage/group_teach_publish', methods=['POST']) -def group_teach_publish(): - if (check_login_status()): - return redirect('/logout') - refresh_token() - data = request.form.to_dict() - cclass = { - "category": data.pop('category'), - "class_id": data.pop('class_id') - } - db = refresh_db() - cursor = db.cursor() - cursor.execute("SELECT about FROM gpclasses WHERE category=%s AND subclass=%s", - (cclass['category'], cclass['class_id'])) - cclass["name"] = cursor.fetchone()[0] - cursor.execute("SELECT grade,class_,num,name,ename FROM students WHERE classes LIKE " + '\'%\"'+ cclass['category'] + '\": \"' + cclass['class_id'] +'\"%\'' + " ORDER BY grade ASC,class_ ASC,num ASC") - students = cursor.fetchall() - homerooms = [] - for x in students: - if (str(x[0]) + '^' + str(x[1])) not in homerooms: - homerooms.append(str(x[0]) + '^' + str(x[1])) - data.pop('dsnumbers') - data.pop('dsoffense') - data.pop('dsoffenseother') - date = data.pop('date') - period = data.pop('period') - signature = data.pop('signatureData') - notes = data.pop('notes') - absentData = [] - dsData = [] - for x in data: - xs = x.split('^') - if xs[0] == 'note': - continue - elif xs[0] == 'ds': - dsData.append([xs[1], xs[2].split('-')[0], xs[2].split('-')[1], data[x]]) - else: - absentData.append([xs[1], xs[2], xs[3], 'K' if xs[0] == '1' else 'L', data['note^'+xs[1]+'^'+xs[2]+'^'+xs[3]]]) - for h in homerooms: - h = h.split('^') - cursor = db.cursor() - cursor.execute(""" - SELECT signature, notes FROM submission WHERE grade=%s AND class_=%s AND date=%s AND period=%s - """, (h[0], h[1], date, period)) - one = cursor.fetchone() - if one is None: - jSignature = json.dumps({cclass['class_id']: signature}) - cursor.execute(""" - INSERT INTO submission (grade, class_, date, period, signature, notes) - VALUES (%s, %s, %s, %s, %s, %s) - """, (h[0], h[1], date, period, jSignature, notes)) - db.commit() - else: - jSignature = json.loads(one[0]) - if cclass['class_id'] in jSignature: - continue - jSignature[cclass['class_id']] = signature - note = one[1] + '; ' + notes - cursor.execute(""" - UPDATE submission SET signature=%s, notes=%s WHERE grade=%s AND class_=%s AND date=%s AND period=%s - """, (json.dumps(jSignature), note, h[0], h[1], date, period)) - db.commit() - for d in dsData: - cursor = db.cursor() - cursor.execute(""" - INSERT INTO ds (grade, class_, num, date, period, note) - VALUES (%s, %s, %s, %s, %s, %s) - """, (d[0], d[1], d[2], date, period, d[3])) - db.commit() - for a in absentData: - cursor = db.cursor() - cursor.execute(""" - INSERT INTO absent (grade, class_, num, date, period, status, note) - VALUES (%s, %s, %s, %s, %s, %s, %s) - """, (a[0], a[1], a[2], date, period, a[3], a[4])) - db.commit() - return redirect('/manage') - -@manage.route('/manage/homeroom_abs', methods=['POST']) -def homeroom_abs_publish(): - if (check_login_status()): - return redirect('/logout') - refresh_token() - db = refresh_db() - data = request.form.to_dict() - date = data.pop('date') - period = data.pop('period') - signature = data.pop('signatureData') - notes = data.pop('notes') - homeroom = data.pop('homeroom').split('^') - ds1 = data.pop('ds^1') - ds2 = data.pop('ds^2') - ds3 = data.pop('ds^3') - ds4 = data.pop('ds^4') - ds5 = data.pop('ds^5') - ds6 = data.pop('ds^6') - ds7 = data.pop('ds^7') - # 2: L / 1: K - absentData = {} - dsidv = {} - for x in data: - xt = x.split('^') - if (xt[0] == 'note'): - if xt[2] not in absentData: - absentData[xt[2]] = {} - absentData[xt[2]]['note'] = data[x] - elif (xt[0] == 'dsidv'): - dsidv[xt[1]] = data[x] - else: - if xt[1] not in absentData: - absentData[xt[1]] = {} - absentData[xt[1]]['status'] = 'L' if x[0] == '2' else 'K' - cursor = db.cursor() - cursor.execute(""" - INSERT INTO submission - (grade, class_, date, period, signature, ds1, ds2, ds3, ds4, ds5, ds6, ds7, notes) - VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s) - """, (homeroom[0], homeroom[1], date, period, signature, ds1, ds2, ds3, ds4, ds5, ds6, ds7, notes)) - for x in absentData: - cursor.execute(""" - INSERT INTO absent - (grade, class_, date, period, num, status, note) - VALUES (%s, %s, %s, %s, %s, %s, %s) - """, (homeroom[0], homeroom[1], date, period, x, absentData[x]['status'], absentData[x]['note'])) - for x in dsidv: - cursor.execute(""" - INSERT INTO ds - (grade, class_, date, period, num, note) - VALUES (%s, %s, %s, %s, %s, %s) - """, (homeroom[0], homeroom[1], date, period, x, dsidv[x])) - db.commit() - 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() - data = request.form.to_dict() - print(data) - return "" - -@manage.route('/manage/homeroom_confirm', methods=['POST']) -def homeroom_confirm(): - if (check_login_status()): - return redirect('/logout') - refresh_token() - data = request.form.to_dict() - homeroom = data.pop('homeroom').split('^') - date = data.pop('date') - signature = data.pop('signatureData') - notes = data.pop('notes') - db = refresh_db() - cursor = db.cursor() - cursor.execute(""" - INSERT INTO submission - (grade, class_, date, period, signature, notes) - VALUES (%s, %s, %s, 'c', %s, %s) - """, (homeroom[0], homeroom[1], date, signature, notes)) - db.commit() - return redirect('/manage') + return redirect('/logout') \ No newline at end of file diff --git a/manage/student.py b/manage/student.py new file mode 100644 index 0000000..cf4f977 --- /dev/null +++ b/manage/student.py @@ -0,0 +1,30 @@ +from functions import * +student = Blueprint('student', __name__) + +@student.route('/student', methods=['GET']) +def showStudentAbs(): + if (check_login_status()): + return redirect('/logout') + refresh_token() + if not ('user_type' in session and session['user_type'] == 'student'): + return redirect('/') + db = refresh_db() + cursor = db.cursor() + cursor.execute("SELECT date, period, num, status, note FROM absent WHERE grade=%s AND class_=%s AND num=%s ORDER BY date DESC, FIND_IN_SET(period, 'm,1,2,3,4,n,5,6,7,8,9') DESC, num ASC", (session['grade'], session['class'], session['num'])) + absentDataSQL = cursor.fetchall() + return render_template("list.html", title="Student Absent List | 學生缺勤紀錄", mode='STUDABS', data=absentDataSQL, currRoom=[session['grade'],session['class']], name=session['name'], num=session['num']) + +@student.route('/student/ds', methods=['GET']) +def showStudentDS(): + if (check_login_status()): + return redirect('/logout') + refresh_token() + if not ('user_type' in session and session['user_type'] == 'student'): + return redirect('/') + db = refresh_db() + cursor = db.cursor() + cursor.execute("SELECT date, period, num, note FROM ds WHERE grade=%s AND class_=%s AND num=%s ORDER BY date DESC, FIND_IN_SET(period, 'm,1,2,3,4,n,5,6,7,8,9') DESC, num ASC", (session['grade'], session['class'], session['num'])) + dsDataSQL = cursor.fetchall() + print(dsDataSQL) + return render_template("list.html", title="Student DS List | 學生定心紀錄", mode='STUDDS', data=dsDataSQL, currRoom=[session['grade'],session['class']], name=session['name'], num=session['num']) + diff --git a/static/old_favicon.ico b/static/old_favicon.ico deleted file mode 100644 index 0e9fedd..0000000 Binary files a/static/old_favicon.ico and /dev/null differ diff --git a/static/pagejs/admin.js b/static/pagejs/admin.js index 67f68ef..cc693e2 100644 --- a/static/pagejs/admin.js +++ b/static/pagejs/admin.js @@ -75,4 +75,51 @@ function submitForm() { $('#finalCheck').modal('hide'); $('.container').hide(); $('#loading').show(); -} \ No newline at end of file +} + +function refresh_homeroom() { + var grade = $('#grade').val(); + $('#class').html(''); + $('span#name').html = "" + if (grade === "") { + $('#class').attr('disabled', 'disabled') + return + } + // get keys in dict + var keys = Object.keys(students[grade]); + keys.forEach(element => { + $('#class').append(``) + }); + $('#class').removeAttr('disabled') +} +function refresh_numbers() { + var grade = $('#grade').val(); + var class_ = $('#class').val(); + $('span#name').html = "" + $('#number').html(''); + if (grade === "") { + $('#class').attr('disabled', 'disabled') + if (clas_ !== "") return + } if (class_ === "") { + $('#number').attr('disabled', 'disabled') + return + } + // get keys in dict + var keys = Object.keys(students[grade][class_]); + keys.forEach(element => { + $('#number').append(``) + }); + $('#number').removeAttr('disabled') +} +function showName() { + var grade = $('#grade').val(); + var class_ = $('#class').val(); + var number = $('#number').val(); + $('#name').html(students[grade][class_][number]); +} +function clearForm() { + document.getElementById('newabs').reset(); + $('#class').attr('disabled', 'disabled') + $('#number').attr('disabled', 'disabled') + $('span#name').html = "" +} diff --git a/static/pagejs/group_teach.js b/static/pagejs/group_teach.js index b2a6251..b14245c 100644 --- a/static/pagejs/group_teach.js +++ b/static/pagejs/group_teach.js @@ -2,13 +2,6 @@ var signaturePad, selPeriod, canvas, width = $(window).width(), modal; var indDS = {}; function submitForm() { if (!signaturePad.isEmpty()) { - for (var i in indDS) { - var tmp = document.createElement('input'); - tmp.type = 'hidden'; - tmp.name = 'ds^' + i; - tmp.value = indDS[i]; - document.getElementById('attendanceData^' + selPeriod).appendChild(tmp); - } $('#' + modal).modal('hide'); loadingAnimation(); signaturePad.off(); @@ -20,6 +13,18 @@ function submitForm() { alert("Please sign first"); } } +function submitDSForm() { + for (var i in indDS) { + var tmp = document.createElement('input'); + tmp.type = 'hidden'; + tmp.name = 'ds^' + i; + tmp.value = indDS[i]; + document.getElementById('attendanceData^' + selPeriod).appendChild(tmp); + } + $('#' + modal).modal('hide'); + loadingAnimation(); + document.getElementById("attendanceData^" + selPeriod).submit(); +} function resizeCanvas() { var ratio = Math.max(window.devicePixelRatio || 1, 1); canvas.width = canvas.offsetWidth * ratio; @@ -29,8 +34,7 @@ function resizeCanvas() { } function viewSignature(period) { selPeriod = period - $('.viewSignatureBtn').attr({ 'disabled': 'disabled' }); - $('.viewSignatureBtn').removeClass('margin-bottom'); + document.getElementById("attendanceData^" + selPeriod).getElementsByClassName("submissionType")[0].value = "newAbsent"; modal = 'sign-' + period; $('#' + modal).modal('show'); var cnt = 0; @@ -58,6 +62,12 @@ function viewSignature(period) { }); resizeCanvas(); } +function signDS(period) { + selPeriod = period + document.getElementById("attendanceData^" + selPeriod).getElementsByClassName("submissionType")[0].value = "dsSubmit"; + modal = 'ds-' + period; + $('#' + modal).modal('show'); +} function unCheckLate(string) { document.getElementById('late^' + string).checked = false; strForNote = string.substring(string.indexOf("^") + 1); diff --git a/static/pagejs/homeroom.js b/static/pagejs/homeroom.js index 1ae3544..33047e9 100644 --- a/static/pagejs/homeroom.js +++ b/static/pagejs/homeroom.js @@ -26,11 +26,6 @@ function submitForm() { document.getElementById('homeroom_confirm').submit() } else { var notes = $('#subjectNotes').val(); - for (var i = 0; i < 7; i++) - document.getElementById('HR-ds'+(i+1)).value = $('.dsboard input[name="ds'+(i+1)+'"]:checked').val(); - for (var i in indDS) { - $('#postHomeroomAbs').append('') - } document.getElementById('HR-signatureData').value = data; document.getElementById('HR-notes').value = notes; document.getElementById('postHomeroomAbs').submit(); @@ -40,6 +35,16 @@ function submitForm() { alert("Please sign first"); } } +function submitDSForm() { + for (var i = 0; i < 7; i++) + document.getElementById('DS-ds'+(i+1)).value = $('.dsboard input[name="ds'+(i+1)+'"]:checked').val(); + for (var i in indDS) { + $('#postHomeroomDS').append('') + } + $('#DS-notes').val($('input#dsNotesEnter').val()); + loadingAnimation() + document.getElementById('postHomeroomDS').submit(); +} function resizeCanvas() { var ratio = Math.max(window.devicePixelRatio || 1, 1); canvas.width = canvas.offsetWidth * ratio; @@ -88,7 +93,6 @@ function afterSelAbs(period) { } function homeroomCfrm() { hrCfrm = true; - $('.ds').attr('hidden', 'hidden'); $('#showSignPeriod').text("HOMEROOM CONFIRM"); $('#showSignSubjectName').text("班導確認"); $('.tobeform').attr('disabled', 'disabled'); @@ -125,4 +129,8 @@ function addDS() { $('#dsoffenseother').val(""); $('#dsoffensesel').val(""); $('#dsnumbersel').val(""); +} +function showSelDS(period) { + $('#DS-period').val(period) + $('#dsCheck').modal('show'); } \ No newline at end of file diff --git a/temp/placeholderfile.txt b/temp/placeholderfile.txt deleted file mode 100644 index 8f11eb7..0000000 --- a/temp/placeholderfile.txt +++ /dev/null @@ -1 +0,0 @@ -this is just so that /temp doesn't disappear \ No newline at end of file diff --git a/templates/admin.html b/templates/admin.html index d754215..18b3d4e 100644 --- a/templates/admin.html +++ b/templates/admin.html @@ -69,67 +69,63 @@ {% for j in periods %}
{% if schedule[j]['subject'] == 'GP' %} - {% for k in submission[j] %} - {% if studGP[i[0]][schedule[j]['teacher']] == k %} - {% if i[0] in absentData[j] %} - {% if absentData[j][i[0]]['status'] == 'L' %} -

𝜑

- {% elif absentData[j][i[0]]['status'] == 'K' %} -

- {% elif absentData[j][i[0]]['status'] == 'G' %} -

- {% elif absentData[j][i[0]]['status'] == 'S' %} -

- {% elif absentData[j][i[0]]['status'] == 'F' %} -

- {% elif absentData[j][i[0]]['status'] == 'P' %} -

- {% elif absentData[j][i[0]]['status'] == 'O' %} -

+ {% for k in submission[j] %} + {% if k!='notes' and i[0] in absentData[j] %} + {% if absentData[j][i[0]]['status'] == 'L' %} +

𝜑

+ {% elif absentData[j][i[0]]['status'] == 'K' %} +

+ {% elif absentData[j][i[0]]['status'] == 'G' %} +

+ {% elif absentData[j][i[0]]['status'] == 'S' %} +

+ {% elif absentData[j][i[0]]['status'] == 'F' %} +

+ {% elif absentData[j][i[0]]['status'] == 'P' %} +

+ {% elif absentData[j][i[0]]['status'] == 'O' %} +

+ {% else %} +

{{absentData[j][i[0]]['status']}}

+ {% endif %} +

{{absentData[j][i[0]]['note']}}

+ {% elif studGP[i[0]][schedule[j]['teacher']] == k %} +

V

+ {% if j in idvDS and i[0] in idvDS[j] %} +

{{idvDS[j][i[0]]}}

+ {% endif %} + {% else %} +

+ {% endif %} + {% endfor %} {% else %} -

{{absentData[j][i[0]]['status']}}

- {% endif %} -

{{absentData[j][i[0]]['note']}}

- {% else %} -

V

- {% if j in idvDS and i[0] in idvDS[j] %} -

{{idvDS[j][i[0]]}}

- {% endif %} - {% endif %} - {% else %} -

- {% endif %} - {% endfor %} - {% else %} - {% if j in submission %} - {% if i[0] in absentData[j] %} - {% if absentData[j][i[0]]['status'] == 'L' %} -

𝜑

- {% elif absentData[j][i[0]]['status'] == 'K' %} -

- {% elif absentData[j][i[0]]['status'] == 'G' %} -

- {% elif absentData[j][i[0]]['status'] == 'S' %} -

- {% elif absentData[j][i[0]]['status'] == 'F' %} -

- {% elif absentData[j][i[0]]['status'] == 'P' %} -

- {% elif absentData[j][i[0]]['status'] == 'O' %} -

- {% else %} -

{{absentData[j][i[0]]['status']}}

- {% endif %} -

{{absentData[j][i[0]]['note']}}

- {% else %} -

V

- {% if j in idvDS and i[0] in idvDS[j] %} -

{{idvDS[j][i[0]]}}

- {% endif %} - {% endif %} - {% else %} -

- {% endif %} + {% if i[0] in absentData[j] %} + {% if absentData[j][i[0]]['status'] == 'L' %} +

𝜑

+ {% elif absentData[j][i[0]]['status'] == 'K' %} +

+ {% elif absentData[j][i[0]]['status'] == 'G' %} +

+ {% elif absentData[j][i[0]]['status'] == 'S' %} +

+ {% elif absentData[j][i[0]]['status'] == 'F' %} +

+ {% elif absentData[j][i[0]]['status'] == 'P' %} +

+ {% elif absentData[j][i[0]]['status'] == 'O' %} +

+ {% else %} +

{{absentData[j][i[0]]['status']}}

+ {% endif %} +

{{absentData[j][i[0]]['note']}}

+ {% elif j in submission %} +

V

+ {% else %} +

+ {% endif %} + {% if j in idvDS and i[0] in idvDS[j] %} +

{{idvDS[j][i[0]]}}

+ {% endif %} {% endif %}
{% endfor %} @@ -201,34 +197,12 @@ {% endif %} {% endfor %} - {% if showUpload == '1' %} -
-
-

此排 [請勿] 隨意點選

-
- - - - - -
- {% endif %} + {% include 'footer.html' %} - {% include 'footer.html' %} - \ No newline at end of file diff --git a/templates/admin_export.html b/templates/admin_export.html new file mode 100644 index 0000000..1951af6 --- /dev/null +++ b/templates/admin_export.html @@ -0,0 +1,92 @@ + + + + + + + + Admin 管理員 - Attendance 點名 + + + + + + + + + + + +
+ {% include 'sidebar.html' %} + +
+

Export | 匯出資料

+
+
+

班級課表

+
+
+ + +
+
+ + +
+ + +
+
+
+

學生名單

+
+
+ + +
+
+ + +
+ + +
+
+
+

老師課表

+
+
+ + +
+
+ + +
+ + +
+
+
+ {% include 'footer.html' %} +
+ + + + + + + \ No newline at end of file diff --git a/templates/admin_mark.html b/templates/admin_mark.html new file mode 100644 index 0000000..0b24c1d --- /dev/null +++ b/templates/admin_mark.html @@ -0,0 +1,178 @@ + + + + + + + + Admin 管理員 - Attendance 點名 + + + + + + + + + + + +
+ {% include 'sidebar.html' %} + +
+

Mark Absent | 新增請假

+
+
+
+
+ + +
+
+
+
+ + {% for p in periods %} +
+ + +
+ {% endfor %} +
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+
+
+
+ {% with messages = get_flashed_messages() %} + {% if messages %} + {% for message in messages %} + {% if message[0] == '`' %} + + {% else %} + + {% endif %} + {% endfor %} + {% endif %} + {% endwith %} +
+

最新 10 筆資料 (完整資料請到 這裡)

+
+
日期
+
節次
+
班級
+
座號
+
姓名
+
假別
+
備註
+
+ {% for r in records %} +
+
{{r[0]}}
+
{{r[1]}}
+
{{r[2]}}{{r[3]}}
+
{{r[4]}}
+
{{students[r[2]][r[3]][r[4]]}}
+
+ {% if r[5] == 'L' %}遲到{% endif %} + {% if r[5] == 'K' %}曠課{% endif %} + {% if r[5] == 'G' %}事假{% endif %} + {% if r[5] == 'S' %}病假{% endif %} + {% if r[5] == 'F' %}喪假{% endif %} + {% if r[5] == 'P' %}疫情假{% endif %} + {% if r[5] == 'O' %}公假{% endif %} +
+
{{r[6]}}
+
+ {% endfor %} + {% include 'footer.html' %} +
+ + + + + + + + \ No newline at end of file diff --git a/templates/group_teach.html b/templates/group_teach.html index ca45166..7a02e46 100644 --- a/templates/group_teach.html +++ b/templates/group_teach.html @@ -47,6 +47,7 @@ +
Grade 年級
@@ -56,6 +57,7 @@
Period {{p}} | 第 {{p}} 節
{% set need_fill = namespace(found=false) %} + {% set need_ds = namespace(found=false) %} {% if data[c] != None %} {% for grade in data[c][p] %} {% for student in data[c][p][grade] %} @@ -113,18 +115,25 @@ onchange="unCheckLate('{{p}}^{{grade}}^{{student}}')">
{% endif %} + {% if data[c][p][grade][student]['needDS'] == True %} + {% set need_ds.found = true %} + {% endif %} {% endfor %} {% endfor %} {% endif %} - {% if not need_fill.found %} - - {% else %} + {% if need_fill.found %} + {% elif need_ds.found %} + + {% else %} + {% endif %} + + + + + + + + +