mirror of
https://github.com/aaronleetw/Attendance.git
synced 2024-11-14 19:11:39 -08:00
Added group class export namelist
This commit is contained in:
parent
dbffe9289c
commit
14ad35d268
9 changed files with 138 additions and 1 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -3,4 +3,6 @@
|
|||
test*.*
|
||||
__pycache__/*
|
||||
excel/*
|
||||
venv/*
|
||||
venv/*
|
||||
.idea/*
|
||||
__pycache__/*
|
66
export.py
66
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')
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -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':
|
||||
|
|
|
@ -78,6 +78,21 @@
|
|||
<a href="/manage/admin/export/teacher_period/all"><button type="button" class="btn btn-secondary">匯出所有老師</button></a>
|
||||
</form>
|
||||
</div>
|
||||
<div class="col reqpadding">
|
||||
<h2>分組課學生名單</h2>
|
||||
<form action="/manage/admin/export/group_student_list" method="post" id="group_student_list">
|
||||
<div class="form-group row">
|
||||
<label for="category">類別</label>
|
||||
<input type="text" name="category" id="category" class="form-control" required>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<label for="class_id">分組課</label>
|
||||
<input type="text" name="class_id" id="class_id" class="form-control">
|
||||
</div>
|
||||
<button class="btn btn-primary">確認</button>
|
||||
<button type="button" class="btn btn-secondary" onclick="onlyCategory()">匯出該類別</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
{% include 'footer.html' %}
|
||||
</div>
|
||||
|
@ -87,6 +102,12 @@
|
|||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
|
||||
<script src="/static/pagejs/admin.js"></script>
|
||||
<script src="/static/time.js"></script>
|
||||
<script>
|
||||
function onlyCategory() {
|
||||
document.getElementById('group_student_list').action = '/manage/admin/export/group_student_list_only_category';
|
||||
document.getElementById('group_student_list').submit();
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
Loading…
Reference in a new issue