-
Notifications
You must be signed in to change notification settings - Fork 0
/
attendance_management.py
75 lines (57 loc) · 3.14 KB
/
attendance_management.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# Import necessary modules and classes
from flask import Blueprint, render_template, redirect, url_for, request
from db_config import execute_query
attendance_maintenance_routes = Blueprint('attendance_maintenance', __name__)
@attendance_maintenance_routes.route('/attendance', methods=['GET'])
def view_attendance():
query = """
SELECT Attendance.AttendanceID, Members.FirstName, Members.LastName, Classes.ClassName, Attendance.AttendanceDate, Attendance.AttendanceStatus
FROM Attendance
JOIN Members ON Attendance.MemberID = Members.MemberID
JOIN Classes ON Attendance.ClassID = Classes.ClassID
"""
attendance_records = execute_query(query)
return render_template('attendance.html', attendance_records=attendance_records)
@attendance_maintenance_routes.route('/attendance/add', methods=['GET', 'POST'])
def add_attendance():
if request.method == 'POST':
member_id = request.form.get('member_id')
class_id = request.form.get('class_id')
attendance_date = request.form.get('attendance_date')
attendance_status = request.form.get('attendance_status')
query = """
INSERT INTO Attendance (MemberID, ClassID, AttendanceDate, AttendanceStatus)
VALUES (%s, %s, %s, %s)
"""
values = (member_id, class_id, attendance_date, attendance_status)
execute_query(query, values)
return redirect(url_for('attendance_maintenance.view_attendance'))
# Fetch members and classes data for dropdowns
members_query = "SELECT MemberID, CONCAT(FirstName, ' ', LastName) AS FullName FROM Members"
classes_query = "SELECT ClassID, ClassName FROM Classes"
members = execute_query(members_query)
classes = execute_query(classes_query)
return render_template('add_attendance.html', members=members, classes=classes)
@attendance_maintenance_routes.route('/attendance/edit/<int:attendance_id>', methods=['GET', 'POST'])
def edit_attendance(attendance_id):
if request.method == 'POST':
attendance_status = request.form.get('attendance_status')
query = "UPDATE Attendance SET AttendanceStatus = %s WHERE AttendanceID = %s"
values = (attendance_status, attendance_id)
execute_query(query, values)
return redirect(url_for('attendance_maintenance.view_attendance'))
query = """
SELECT Attendance.AttendanceID, Members.FirstName, Members.LastName, Classes.ClassName, Attendance.AttendanceDate, Attendance.AttendanceStatus
FROM Attendance
JOIN Members ON Attendance.MemberID = Members.MemberID
JOIN Classes ON Attendance.ClassID = Classes.ClassID
WHERE Attendance.AttendanceID = %s
"""
attendance_record = execute_query(query, (attendance_id,), fetch_one=True)
return render_template('edit_attendance.html', attendance_record=attendance_record)
@attendance_maintenance_routes.route('/attendance/delete/<int:attendance_id>', methods=['POST'])
def delete_attendance(attendance_id):
if request.method == 'POST':
query = "DELETE FROM Attendance WHERE AttendanceID = %s"
execute_query(query, (attendance_id,))
return redirect(url_for('attendance_maintenance.view_attendance'))