Skip to content

Commit

Permalink
added mandatory class filter in student attendance page (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
Noorain464 authored Jan 8, 2024
1 parent 739f664 commit 899c7d8
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 6 deletions.
10 changes: 5 additions & 5 deletions attendance/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,8 @@ def getAttendanceView(request, pk):

def studentAttendance(request, mail_prefix):
student = Student.objects.get(mail__startswith=mail_prefix + "@")
response = fetchAllStudentAttendances(student)
response = fetchAllStudentAttendances(student, include_optional=True)

for a in response["all_attendance"]:
if not a["status"]:
a["status"] = AttendanceStatus.Absent.name
Expand Down Expand Up @@ -412,12 +413,11 @@ def studentAttendance(request, mail_prefix):
)


def fetchAllStudentAttendances(student):
def fetchAllStudentAttendances(student, include_optional=False):
if not student:
return JsonResponse(None, safe=False)

all_attendance = student.get_all_attendance(include_optional=False)

all_attendance = student.get_all_attendance(include_optional=include_optional)
json_attendance = []
subject_pk_set = set()
for attendance in all_attendance:
Expand All @@ -438,7 +438,7 @@ def fetchAllStudentAttendances(student):
}
response["all_attendance"] = json_attendance

all_subjects = SubjectClass.get_all_classes(include_optional=False)
all_subjects = SubjectClass.get_all_classes(include_optional=include_optional)

for subject in all_subjects:
if subject.pk not in subject_pk_set:
Expand Down
41 changes: 40 additions & 1 deletion templates/attendance/studentAttendance.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ <h1>{{ data.student.name }}'s Attendance</h1>
<th>Class Name</th>
<th>Start Time</th>
<th>End Time</th>
<th>Attendance Mandatory</th>
<th><select id="val">
<option value="None">Attendance Mandatory</option>
<option value="true">True</option>
<option value="false">False</option>
</select>
</th>
<th>Status</th>
</tr>
</thead>
Expand All @@ -70,5 +75,39 @@ <h1>{{ data.student.name }}'s Attendance</h1>
{% endfor %}
</tbody>
</table>
<script>
let option = document.getElementById('val');
let rows = document.querySelectorAll('#attendanceData tr');

option.addEventListener("change",eventListener)

function filterrows(value) {
for(let i =0; i<rows.length;i++){
let row = rows[i];
let cellvalue = row.cells[3].innerHTML;
if(cellvalue === value || value === "*"){
row.style.display = 'table-row';
}
else{
row.style.display = 'none';
}
}
}

function eventListener(){
let selectedvalue = option.value;

if(selectedvalue === "true"){
filterrows("True")
}
else if(selectedvalue === "false"){
filterrows("False");
}
else{
filterrows("*");
}
}
option.value = "None";
</script>
</body>
</html>

0 comments on commit 899c7d8

Please sign in to comment.