diff --git a/.gitignore b/.gitignore index b400de5..440e80e 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,6 @@ test*.* __pycache__/* excel/* -venv/* \ No newline at end of file +venv/* +.idea/* +__pycache__/* \ No newline at end of file diff --git a/export.py b/export.py index df929e3..b818d14 100644 --- a/export.py +++ b/export.py @@ -214,6 +214,72 @@ def create_student_list(workbook, class_code): return workbook +def create_group_student_list(workbook, cclass, data): + class_code = [cclass['category'], cclass['class_id']] + ws = workbook.create_sheet(class_code[0] + '.' + class_code[1]) + ws.merge_cells('A1:H1') + ws['A1'] = '台北市私立復興實驗高級中學分組課學生名單' + ws['A1'].font = Font(name="DFKai-SB", size=15, bold=True) + ws['A1'].alignment = center + # loop over A:I + for i in range(0, 10): + ws[str(chr(ord('A') + i)) + '1'].border = border + ws.merge_cells('I1:L1') + ws['I1'] = class_code[0] + class_code[1] + ws['I1'].font = Font(name='Calibri', size=15, bold=True) + ws['I1'].alignment = center + ws['I1'].border = border + ws['J1'].border = border + ws['K1'].border = border + ws['L1'].border = border + ws.column_dimensions['A'].width = 6 + ws.column_dimensions['B'].width = 4 + ws.column_dimensions['C'].width = 11 + ws.column_dimensions['D'].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="Calibri", size=13, bold=True) + ws['B2'].alignment = center + ws['B2'].border = bold_bottom + ws['C2'] = '姓名' + ws['C2'].font = Font(name="DFKai-SB", size=13, bold=True) + ws['C2'].alignment = center + ws['C2'].border = bold_bottom + ws['D2'] = 'Name' + ws['D2'].font = Font(name="Calibri", size=13, bold=True) + ws['D2'].alignment = center + ws['D2'].border = bold_bottom + for i in range(4, 12): + ws[str(chr(ord('A') + i)) + '2'].border = bold_bottom + ws.column_dimensions[str(chr(ord('A') + i))].width = 5.8 + + cnt = 0 + for i in data: + ws['A' + str(3 + cnt)] = str(i[0]) + str(i[1]) + ws['A' + str(3 + cnt)].font = std_font + ws['A' + str(3 + cnt)].alignment = center + ws['B' + str(3 + cnt)] = i[2] + ws['B' + str(3 + cnt)].font = std_font + ws['B' + str(3 + cnt)].alignment = center + ws['C' + str(3 + cnt)] = i[3] + ws['C' + str(3 + cnt)].font = Font(name="DFKai-SB", size=14) + ws['C' + str(3 + cnt)].alignment = center + ws['D' + str(3 + cnt)] = i[4] + ws['D' + str(3 + cnt)].font = std_font + ws['D' + str(3 + cnt)].alignment = center + ws.row_dimensions[3 + cnt].height = 19 + for j in range(0, 12): + ws[str(chr(ord('A') + j)) + str(3 + cnt)].border = bold_bottom if (cnt + 1) % 5 == 0 else border + cnt += 1 + return workbook + + def create_teacher_periods(workbook, teacher_name, orig_username=''): ws = workbook.create_sheet(teacher_name) ws.merge_cells('A1:E1') diff --git a/manage/__pycache__/admin.cpython-39.pyc b/manage/__pycache__/admin.cpython-39.pyc deleted file mode 100644 index c8ad650..0000000 Binary files a/manage/__pycache__/admin.cpython-39.pyc and /dev/null differ diff --git a/manage/__pycache__/group.cpython-39.pyc b/manage/__pycache__/group.cpython-39.pyc deleted file mode 100644 index 3711296..0000000 Binary files a/manage/__pycache__/group.cpython-39.pyc and /dev/null differ diff --git a/manage/__pycache__/homeroom.cpython-39.pyc b/manage/__pycache__/homeroom.cpython-39.pyc deleted file mode 100644 index 2797977..0000000 Binary files a/manage/__pycache__/homeroom.cpython-39.pyc and /dev/null differ diff --git a/manage/__pycache__/manage.cpython-39.pyc b/manage/__pycache__/manage.cpython-39.pyc deleted file mode 100644 index 8c562c7..0000000 Binary files a/manage/__pycache__/manage.cpython-39.pyc and /dev/null differ diff --git a/manage/__pycache__/student.cpython-39.pyc b/manage/__pycache__/student.cpython-39.pyc deleted file mode 100644 index a74af62..0000000 Binary files a/manage/__pycache__/student.cpython-39.pyc and /dev/null differ diff --git a/manage/admin.py b/manage/admin.py index bbb41f5..b8340c8 100644 --- a/manage/admin.py +++ b/manage/admin.py @@ -124,6 +124,54 @@ def admin_export_student_list_all(): return send_file(excel_stream, attachment_filename='student_list_all.xlsx', as_attachment=True) +@admin.route('/manage/admin/export/group_student_list', methods=['POST']) +def admin_export_group_student_list(): + if check_login_status() or session['subuser_type'] != 'admin': + return redirect('/logout') + refresh_token() + cclass = { + 'category': request.form['category'], + 'class_id': request.form['class_id'], + } + db = refresh_db() + cursor = db.cursor() + 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() + workbook = Workbook() + workbook.remove_sheet(workbook.get_sheet_by_name('Sheet')) + workbook = create_group_student_list(workbook, cclass, students) + excel_stream = io.BytesIO() + workbook.save(excel_stream) + excel_stream.seek(0) + return send_file(excel_stream, attachment_filename='student_list_' + cclass['category'] + '_' + cclass[ + 'class_id'] + '.xlsx', as_attachment=True) + +@admin.route('/manage/admin/export/group_student_list_only_category', methods=['POST']) +def admin_export_group_student_list_only_category(): + if check_login_status() or session['subuser_type'] != 'admin': + return redirect('/logout') + refresh_token() + cclass = { + 'category': request.form['category'], + } + db = refresh_db() + cursor = db.cursor() + cursor.execute("SELECT subclass FROM gpclasses WHERE category=%s", (cclass['category'], )) + classes = cursor.fetchall() + workbook = Workbook() + workbook.remove_sheet(workbook.get_sheet_by_name('Sheet')) + for i in classes: + cclass['class_id'] = i[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() + workbook = create_group_student_list(workbook, cclass, students) + excel_stream = io.BytesIO() + workbook.save(excel_stream) + excel_stream.seek(0) + return send_file(excel_stream, attachment_filename='student_list_' + cclass['category'] + '.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': diff --git a/templates/admin_export.html b/templates/admin_export.html index 1951af6..07c975e 100644 --- a/templates/admin_export.html +++ b/templates/admin_export.html @@ -78,6 +78,21 @@ +