From 9a842c12bfe5111df9c3d68a33a833915527ef60 Mon Sep 17 00:00:00 2001 From: S4NKALP Date: Sun, 19 Jan 2025 14:44:28 +0545 Subject: [PATCH] huh new thing --- app/admin.py | 170 ++---- app/adminViews.py | 509 +++++++++++++++--- app/apps.py | 4 +- ...ssword_remove_student_username_and_more.py | 29 + ...10_alter_feedbackstudent_feedback_reply.py | 18 + ..._id_feedbackteacher_teacher_id_and_more.py | 23 + ...ademic_year_attendance_academic_year_id.py | 18 + ..._student_password_student_user_and_more.py | 72 +++ ...t_user_remove_student_username_and_more.py | 29 + app/models.py | 14 +- app/studentViews.py | 163 ++++++ app/teacherViews.py | 7 + app/urls.py | 92 +++- app/views.py | 2 +- student_management_system/settings.py | 1 + templates/hod/add_student.html | 149 +++++ templates/hod/add_teacher.html | 100 ++++ templates/hod/edit_student.html | 212 ++++++++ templates/hod/edit_teacher.html | 126 +++++ templates/hod/manage_student.html | 65 +++ templates/hod/manage_subject.html | 253 ++++++--- templates/hod/manage_teacher.html | 43 ++ templates/hod/student_feedback.html | 144 +++++ templates/hod/student_leave_view.html | 188 +++++++ templates/hod/teacher_feedback.html | 115 ++++ templates/hod/teacher_leave_view.html | 186 +++++++ templates/hod/view_attendance.html | 208 +++++++ templates/student/dashboard.html | 83 +++ templates/teacher/dashboard.html | 83 +++ 29 files changed, 2811 insertions(+), 295 deletions(-) create mode 100644 app/migrations/0009_remove_student_password_remove_student_username_and_more.py create mode 100644 app/migrations/0010_alter_feedbackstudent_feedback_reply.py create mode 100644 app/migrations/0011_rename_staff_id_feedbackteacher_teacher_id_and_more.py create mode 100644 app/migrations/0012_rename_academic_year_attendance_academic_year_id.py create mode 100644 app/migrations/0013_student_fcm_token_student_password_student_user_and_more.py create mode 100644 app/migrations/0014_remove_student_user_remove_student_username_and_more.py create mode 100644 templates/hod/add_student.html create mode 100644 templates/hod/add_teacher.html create mode 100644 templates/hod/edit_student.html create mode 100644 templates/hod/edit_teacher.html create mode 100644 templates/hod/manage_student.html create mode 100644 templates/hod/manage_teacher.html create mode 100644 templates/hod/student_feedback.html create mode 100644 templates/hod/student_leave_view.html create mode 100644 templates/hod/teacher_feedback.html create mode 100644 templates/hod/teacher_leave_view.html create mode 100644 templates/hod/view_attendance.html create mode 100644 templates/student/dashboard.html create mode 100644 templates/teacher/dashboard.html diff --git a/app/admin.py b/app/admin.py index 0c4106d..edc6abc 100644 --- a/app/admin.py +++ b/app/admin.py @@ -16,168 +16,58 @@ from app.models import ( ) # Register your models here. -admin.site.register(FeedbackStudent) -admin.site.register(FeedbackTeacher) -admin.site.register(LeaveReportStudent) -admin.site.register(LeaveReportTeacher) + +@admin.register(LeaveReportStudent) +class LeaveReportStudentAdmin(admin.ModelAdmin): + def changelist_view(self, request, extra_context=None): + return redirect(reverse("student_leave_view")) + + +@admin.register(LeaveReportTeacher) +class LeaveReportTeacherAdmin(admin.ModelAdmin): + def changelist_view(self, request, extra_context=None): + return redirect(reverse("teacher_leave_view")) + + +@admin.register(FeedbackTeacher) +class FeedbackTeacherAdmin(admin.ModelAdmin): + def changelist_view(self, request, extra_context=None): + return redirect(reverse("teacher_feedback")) + + +@admin.register(FeedbackStudent) +class FeedbackStudentAdmin(admin.ModelAdmin): + def changelist_view(self, request, extra_context=None): + return redirect(reverse("student_feedback_message")) @admin.register(AcademicYear) class AcademicYearAdmin(admin.ModelAdmin): - list_display = ("id", "start_date", "created_at", "updated_at") - def changelist_view(self, request, extra_context=None): return redirect(reverse("manage_academicyear")) @admin.register(Attendance) class AttendanceAdmin(admin.ModelAdmin): - list_display = ("subject_id", "attendance_date", "created_at", "updated_at") + def changelist_view(self, request, extra_context=None): + return redirect(reverse("admin_view_attendance")) @admin.register(AttendanceReport) class AttendanceReportAdmin(admin.ModelAdmin): - list_display = ("student_id", "attendance_id", "status", "created_at", "updated_at") + pass @admin.register(Student) class StudentAdmin(admin.ModelAdmin): - list_display = ( - "id", - "first_name", - "middle_name", - "last_name", - "username", - "email", - "phone", - "dob", - "gender", - "address", - "father_name", - "mother_name", - "parents_number", - "father_occupation", - "guardian_name", - "relationship_with_student", - ) - search_fields = ( - "first_name", - "middle_name", - "last_name", - "email", - "phone", - "father_name", - "mother_name", - "guardian_name", - ) - list_filter = ( - "gender", - "father_occupation", - "mother_occupation", - "relationship_with_student", - ) - list_editable = ("phone", "email", "gender", "address") - date_hierarchy = "dob" - fieldsets = ( - ( - "Personal Information", - { - "fields": ( - "first_name", - "middle_name", - "last_name", - "dob", - "gender", - "address", - ) - }, - ), - ("Contact Information", {"fields": ("username", "password", "phone", "email")}), - ( - "Parent Details", - { - "fields": ( - "father_name", - "mother_name", - "parents_number", - "father_occupation", - "mother_occupation", - ) - }, - ), - ( - "Guardian Details", - { - "fields": ( - "guardian_name", - "guardian_number", - "relationship_with_student", - ) - }, - ), - ("Timestamps", {"fields": ("created_at", "updated_at")}), - ) - readonly_fields = ("created_at", "updated_at") + def changelist_view(self, request, extra_context=None): + return redirect(reverse("manage_student")) @admin.register(Teacher) class TeacherAdmin(admin.ModelAdmin): - list_display = ( - "id", - "first_name", - "middle_name", - "last_name", - "username", - "email", - "phone", - "gender", - "qualification", - "specialization_on", - "marital_status", - "date_of_joining", - "created_at", - "updated_at", - ) - search_fields = ( - "first_name", - "middle_name", - "last_name", - "email", - "phone", - "username", - "specialization_on", - ) - list_filter = ( - "gender", - "qualification", - "marital_status", - "date_of_joining", - ) - list_editable = ("phone", "email", "gender", "marital_status") - date_hierarchy = "date_of_joining" - fieldsets = ( - ( - "Personal Information", - { - "fields": ( - "first_name", - "middle_name", - "last_name", - "dob", - "gender", - "marital_status", - "address", - ) - }, - ), - ("Contact Information", {"fields": ("username", "password", "phone", "email")}), - ( - "Professional Details", - {"fields": ("qualification", "specialization_on", "date_of_joining")}, - ), - ("Timestamps", {"fields": ("created_at", "updated_at")}), - ) - readonly_fields = ("created_at", "updated_at") + def changelist_view(self, request, extra_context=None): + return redirect(reverse("manage_teacher")) @admin.register(Course) diff --git a/app/adminViews.py b/app/adminViews.py index 6685e58..72d9491 100644 --- a/app/adminViews.py +++ b/app/adminViews.py @@ -17,6 +17,8 @@ from app.models import ( Attendance, AttendanceReport, AcademicYear, + FeedbackStudent, + FeedbackTeacher, ) from django.contrib.auth.decorators import login_required, user_passes_test from app.forms import SubjectForm @@ -27,7 +29,6 @@ admin_site = site @login_required @user_passes_test(lambda u: u.is_superuser) def admin_home(request): - admin_site = site student_count1 = Student.objects.all().count() teacher_count = Teacher.objects.all().count() subject_count = Subject.objects.all().count() @@ -43,48 +44,50 @@ def admin_home(request): subject_count_list.append(subjects) student_count_list_in_course.append(students) - subjects_all = Subject.objects.all() - subject_list = [] - student_count_list_in_subject = [] - for subject in subjects_all: - course = subject.course - student_count = Student.objects.filter(course_id=course.id).count() - subject_list.append(subject.name) - student_count_list_in_subject.append(student_count) + # subjects_all = Subject.objects.all() + # subject_list = [] + # student_count_list_in_subject = [] + # for subject in subjects_all: + # course = subject.course + # student_count = Student.objects.filter(course_id=course.id).count() + # subject_list.append(subject.name) + # student_count_list_in_subject.append(student_count) - teacher = Teacher.objects.all() - attendance_present_list_teacher = [] - attendance_absent_list_teacher = [] - teacher_name_list = [] - for teacher in teacher: - subject_ids = Subject.objects.filter(teacher_id=teacher.id) - attendance = Attendance.objects.filter( - subject_id__in=subject_ids, - ).count() - leaves = LeaveReportTeacher.objects.filter( - teacher_id=teacher.id, leave_status=1 - ).count() - attendance_present_list_teacher.append(attendance) - attendance_absent_list_teacher.append(leaves) - teacher_name_list.append(teacher.first_name) + # teacher = Teacher.objects.all() + # attendance_present_list_teacher = [] + # attendance_absent_list_teacher = [] + # teacher_name_list = [] + # for teacher in teacher: + # subject_ids = Subject.objects.filter(teacher=teacher).values_list( + # "id", flat=True + # ) + # attendance = Attendance.objects.filter( + # subject_id__in=subject_ids, + # ).count() + # leaves = LeaveReportTeacher.objects.filter( + # teacher_id=teacher.id, leave_status=1 + # ).count() + # attendance_present_list_teacher.append(attendance) + # attendance_absent_list_teacher.append(leaves) + # teacher_name_list.append(teacher.first_name) - students_all = Student.objects.all() - attendance_present_list_student = [] - attendance_absent_list_student = [] - student_name_list = [] - for student in students_all: - attendance = AttendanceReport.objects.filter( - student_id=student.id, status=True - ).count() - absent = AttendanceReport.objects.filter( - student_id=student.id, status=False - ).count() - leaves = LeaveReportStudent.objects.filter( - student_id=student.id, leave_status=1 - ).count() - attendance_present_list_student.append(attendance) - attendance_absent_list_student.append(leaves + absent) - student_name_list.append(student.admin.username) + # students_all = Student.objects.all() + # attendance_present_list_student = [] + # attendance_absent_list_student = [] + # student_name_list = [] + # for student in students_all: + # attendance = AttendanceReport.objects.filter( + # student_id=student.id, status=True + # ).count() + # absent = AttendanceReport.objects.filter( + # student_id=student.id, status=False + # ).count() + # leaves = LeaveReportStudent.objects.filter( + # student_id=student.id, leave_status=1 + # ).count() + # attendance_present_list_student.append(attendance) + # attendance_absent_list_student.append(leaves + absent) + # student_name_list.append(student.username) context = { **admin_site.each_context(request), @@ -93,17 +96,17 @@ def admin_home(request): "teacher_count": teacher_count, "subject_count": subject_count, "course_count": course_count, - "course_name_list": course_name_list, + # "course_name_list": course_name_list, "subject_count_list": subject_count_list, - "student_count_list_in_course": student_count_list_in_course, - "student_count_list_in_subject": student_count_list_in_subject, - "subject_list": subject_list, - "teacher_name_list": teacher_name_list, - "attendance_present_list_teacher": attendance_present_list_teacher, - "attendance_absent_list_teacher": attendance_absent_list_teacher, - "student_name_list": student_name_list, - "attendance_present_list_student": attendance_present_list_student, - "attendance_absent_list_student": attendance_absent_list_student, + # "student_count_list_in_course": student_count_list_in_course, + # "student_count_list_in_subject": student_count_list_in_subject, + # "subject_list": subject_list, + # "teacher_name_list": teacher_name_list, + # "attendance_present_list_teacher": attendance_present_list_teacher, + # "attendance_absent_list_teacher": attendance_absent_list_teacher, + # "student_name_list": student_name_list, + # "attendance_present_list_student": attendance_present_list_student, + # "attendance_absent_list_student": attendance_absent_list_student, "opts": Student._meta, } return render(request, "hod/dashboard.html", context) @@ -146,7 +149,6 @@ def add_course(request): def manage_course(request): - admin_site = site courses = Course.objects.all() context = { **admin_site.each_context(request), @@ -183,10 +185,12 @@ def edit_course(request, course_id): except Exception as e: messages.error(request, f"Error updating course: {str(e)}") - - return render( - request, "hod/edit_course.html", {"course": course, "title": "Edit Course"} - ) + context = { + **admin_site.each_context(request), + "title": "Edit Course", + "course": course, + } + return render(request, "hod/edit_course.html", context) def delete_course(request, course_id): @@ -201,7 +205,6 @@ def delete_course(request, course_id): def add_academicyear(request): - admin_site = site if request.method == "POST": start_date = request.POST.get("start_date") academic_year = AcademicYear.objects.create(start_date=start_date) @@ -210,6 +213,7 @@ def add_academicyear(request): context = { **admin_site.each_context(request), "title": "Add Academic Year", + # "academic_year": academic_year, "opts": AcademicYear._meta, } return render(request, "hod/add_academicyear.html", context) @@ -217,7 +221,6 @@ def add_academicyear(request): def edit_academicyear(request, pk): academic_year = get_object_or_404(AcademicYear, pk=pk) - admin_site = site if request.method == "POST": start_date = request.POST.get("start_date") @@ -233,13 +236,10 @@ def edit_academicyear(request, pk): "title": "Edit Academic Year", "opts": AcademicYear._meta, } - return render( - request, "hod/edit_academicyear.html", {"academic_year": academic_year} - ) + return render(request, "hod/edit_academicyear.html", context) def manage_academicyear(request): - admin_site = site context = { **admin_site.each_context(request), "academic_years": AcademicYear.objects.all(), @@ -315,7 +315,7 @@ def edit_subject(request, pk): form = SubjectForm(request.POST, instance=subject) if form.is_valid(): form.save() - return redirect("manage_subjects") + return redirect("manage_subject") else: form = SubjectForm(instance=subject) context = { @@ -339,3 +339,386 @@ def delete_subject(request, subject_id): messages.error(request, "Failed to Delete Subject.") return redirect("manage_subject") + +def manage_student(request): + search_query = request.GET.get("search", "") + students = Student.objects.all() + + if search_query: + students = ( + students.filter(first_name__icontains=search_query) + | students.filter(last_name__icontains=search_query) + | students.filter(email__icontains=search_query) + ) + + context = { + **admin_site.each_context(request), + "title": "Manage Students", + "students": students, + "search_query": search_query, + } + return render(request, "hod/manage_student.html", context) + + +def add_student(request): + courses = Course.objects.all() + academic_years = AcademicYear.objects.all() + occupation_choices = dict(Student.occupation_choice) + relationship_choices = dict(Student.relationship_choice) + + if request.method == "POST": + first_name = request.POST.get("first_name") + middle_name = request.POST.get("middle_name") + last_name = request.POST.get("last_name") + email = request.POST.get("email") + phone = request.POST.get("phone") + dob = request.POST.get("dob") + gender = request.POST.get("gender") + course_id = request.POST.get("course") + academic_year_id = request.POST.get("academic_year") + address = request.POST.get("address") + father_name = request.POST.get("father_name") + father_occupation = request.POST.get("father_occupation") + mother_name = request.POST.get("mother_name") + mother_occupation = request.POST.get("mother_occupation") + guardian_name = request.POST.get("guardian_name") + guardian_number = request.POST.get("guardian_number") + parents_number = request.POST.get("parents_number") + relationship_with_student = request.POST.get("relationship_with_student") + + try: + course = get_object_or_404(Course, id=course_id) + academic_year = get_object_or_404(AcademicYear, id=academic_year_id) + + Student.objects.create( + first_name=first_name, + middle_name=middle_name, + last_name=last_name, + email=email, + phone=phone, + dob=dob, + gender=gender, + course=course, + academic_year=academic_year, + address=address, + father_name=father_name, + father_occupation=father_occupation, + mother_name=mother_name, + mother_occupation=mother_occupation, + guardian_name=guardian_name, + guardian_number=guardian_number, + parents_number=parents_number, + relationship_with_student=relationship_with_student, + ) + messages.success(request, "Student added successfully!") + return redirect("manage_student") + except Exception as e: + messages.error(request, f"Error adding student: {e}") + + context = { + **admin_site.each_context(request), + "title": "Add Student", + "courses": courses, + "academic_years": academic_years, + "occupation_choices": occupation_choices.items(), + "relationship_choices": relationship_choices.items(), + } + return render(request, "hod/add_student.html", context) + + +def edit_student(request, student_id): + student = get_object_or_404(Student, id=student_id) + courses = Course.objects.all() + academic_years = AcademicYear.objects.all() + occupation_choices = dict(Student.occupation_choice) + relationship_choices = dict(Student.relationship_choice) + + if request.method == "POST": + student.first_name = request.POST.get("first_name") + student.middle_name = request.POST.get("middle_name") + student.last_name = request.POST.get("last_name") + student.email = request.POST.get("email") + student.phone = request.POST.get("phone") + student.dob = request.POST.get("dob") + student.gender = request.POST.get("gender") + student.course = get_object_or_404(Course, id=request.POST.get("course")) + student.academic_year = get_object_or_404( + AcademicYear, id=request.POST.get("academic_year") + ) + student.father_occupation = request.POST.get("father_occupation") + student.relationship_with_student = request.POST.get( + "relationship_with_student" + ) + + try: + student.save() + messages.success(request, "Student updated successfully!") + return redirect("manage_student") + except Exception as e: + messages.error(request, f"Error updating student: {e}") + + context = { + **admin_site.each_context(request), + "title": "Edit Student", + "student": student, + "courses": courses, + "academic_years": academic_years, + "occupation_choices": occupation_choices.items(), + "relationship_choices": relationship_choices.items(), + } + return render(request, "hod/edit_student.html", context) + + +def delete_student(request, student_id): + student = get_object_or_404(Student, id=student_id) + student.delete() + messages.success(request, "Student deleted successfully!") + return redirect("manage_student") + + +def manage_teacher(request): + teachers = Teacher.objects.all() + context = { + **admin_site.each_context(request), + "title": "Manage Teachers", + "teachers": teachers, + } + return render(request, "hod/manage_teacher.html", context) + + +def add_teacher(request): + if request.method == "POST": + try: + Teacher.objects.create( + first_name=request.POST.get("first_name"), + middle_name=request.POST.get("middle_name"), + last_name=request.POST.get("last_name"), + email=request.POST.get("email"), + phone=request.POST.get("phone"), + dob=request.POST.get("dob"), + gender=request.POST.get("gender"), + address=request.POST.get("address"), + # username=request.POST.get("username"), + # password=request.POST.get("password"), + qualification=request.POST.get("qualification"), + specialization_on=request.POST.get("specialization_on"), + marital_status=request.POST.get("marital_status"), + date_of_joining=request.POST.get("date_of_joining"), + ) + messages.success(request, "Teacher added successfully!") + return redirect("manage_teacher") + except Exception as e: + messages.error(request, f"Error adding teacher: {e}") + + context = { + **admin_site.each_context(request), + "title": "Add Teacher", + "qualification_choices": dict(Teacher.qualification_choice).items(), + "marital_status_choices": dict(Teacher.marital_status_choice).items(), + } + return render(request, "hod/add_teacher.html", context) + + +def edit_teacher(request, teacher_id): + teacher = get_object_or_404(Teacher, id=teacher_id) + + if request.method == "POST": + try: + teacher.first_name = request.POST.get("first_name") + teacher.middle_name = request.POST.get("middle_name") + teacher.last_name = request.POST.get("last_name") + teacher.email = request.POST.get("email") + teacher.phone = request.POST.get("phone") + teacher.dob = request.POST.get("dob") + teacher.gender = request.POST.get("gender") + teacher.address = request.POST.get("address") + teacher.qualification = request.POST.get("qualification") + teacher.specialization_on = request.POST.get("specialization_on") + teacher.marital_status = request.POST.get("marital_status") + teacher.date_of_joining = request.POST.get("date_of_joining") + teacher.save() + + messages.success(request, "Teacher updated successfully!") + return redirect("manage_teacher") + except Exception as e: + messages.error(request, f"Error updating teacher: {e}") + + context = { + **admin_site.each_context(request), + "title": "Edit Teacher", + "teacher": teacher, + "qualification_choices": dict(Teacher.qualification_choice).items(), + "marital_status_choices": dict(Teacher.marital_status_choice).items(), + } + return render(request, "hod/edit_teacher.html", context) + + +def delete_teacher(request, teacher_id): + teacher = get_object_or_404(Teacher, id=teacher_id) + teacher.delete() + messages.success(request, "Teacher deleted successfully!") + return redirect("manage_teacher") + + +def student_feedback_message(request): + feedbacks = FeedbackStudent.objects.all() + context = { + **admin_site.each_context(request), + "title": "Student's Feedback", + "feedbacks": feedbacks, + } + return render(request, "hod/student_feedback.html", context) + + +@csrf_exempt +def student_feedback_message_reply(request): + feedback_id = request.POST.get("id") + feedback_reply = request.POST.get("reply") + + try: + feedback = FeedbackStudent.objects.get(id=feedback_id) + feedback.feedback_reply = feedback_reply + feedback.save() + return HttpResponse("True") + + except: + return HttpResponse("False") + + +def teacher_feedback(request): + feedbacks = FeedbackTeacher.objects.all() + context = { + **admin_site.each_context(request), + "title": "Staff's Feedback", + "feedbacks": feedbacks, + } + return render(request, "hod/teacher_feedback.html", context) + + +@csrf_exempt +def teacher_feedback_replied(request): + feedback_id = request.POST.get("id") + feedback_message = request.POST.get("message") + + try: + feedback = FeedbackTeacher.objects.get(id=feedback_id) + feedback.feedback_reply = feedback_message + feedback.save() + return HttpResponse("True") + except Exception: + return HttpResponse("False") + + +def student_leave_view(request): + leaves = LeaveReportStudent.objects.all() + context = { + **admin_site.each_context(request), + "title": "Student Application", + "leaves": leaves, + } + return render(request, "hod/student_leave_view.html", context) + + +def student_leave_approve(request, leave_id): + leave = LeaveReportStudent.objects.get(id=leave_id) + leave.leave_status = 1 + leave.save() + return HttpResponseRedirect(reverse("student_leave_view")) + + +def student_leave_reject(request, leave_id): + leave = LeaveReportStudent.objects.get(id=leave_id) + leave.leave_status = 2 + leave.save() + return HttpResponseRedirect(reverse("student_leave_view")) + + +def teacher_leave_view(request): + leaves = LeaveReportTeacher.objects.all() + context = { + **admin_site.each_context(request), + "title": "Teacher Application", + "leaves": leaves, + } + return render(request, "hod/teacher_leave_view.html", context) + + +def teacher_leave_approve(request, leave_id): + leave = LeaveReportTeacher.objects.get(id=leave_id) + leave.leave_status = 1 + leave.save() + return HttpResponseRedirect(reverse("teacher_leave_view")) + + +def teacher_leave_reject(request, leave_id): + leave = LeaveReportTeacher.objects.get(id=leave_id) + leave.leave_status = 2 + leave.save() + return HttpResponseRedirect(reverse("teacher_leave_view")) + + +def admin_view_attendance(request): + subjects = Subject.objects.all() + academic_years = AcademicYear.objects.all() + context = { + **admin_site.each_context(request), + "subjects": subjects, + "academic_years": academic_years, + } + return render(request, "hod/view_attendance.html", context) + + +@csrf_exempt +def admin_get_attendance_dates(request): + # Getting Values from Ajax POST 'Fetch Student' + subject_id = request.POST.get("subject") + academic_year = request.POST.get("academic_year_id") + + # Students enroll to Course, Course has Subjects + # Getting all data from subject model based on subject_id + subject_model = Subject.objects.get(id=subject_id) + + academic_model = AcademicYear.objects.get(id=academic_year) + + # students = Students.objects.filter(course_id=subject_model.course_id, session_year_id=session_model) + attendance = Attendance.objects.filter( + subject_id=subject_model, academic_year_id=academic_model + ) + + # Only Passing Student Id and Student Name Only + list_data = [] + + for attendance_single in attendance: + data_small = { + "id": attendance_single.id, + "attendance_date": str(attendance_single.attendance_date), + "academic_year_id": attendance_single.academic_year_id.id, + } + list_data.append(data_small) + + return JsonResponse( + json.dumps(list_data), content_type="application/json", safe=False + ) + + +@csrf_exempt +def admin_get_attendance_student(request): + # Getting Values from Ajax POST 'Fetch Student' + attendance_date = request.POST.get("attendance_date") + attendance = Attendance.objects.get(id=attendance_date) + + attendance_data = AttendanceReport.objects.filter(attendance_id=attendance) + # Only Passing Student Id and Student Name Only + list_data = [] + + for student in attendance_data: + data_small = { + "id": student.student_id.id, + "name": student.student_id.first_name + " " + student.student_id.last_name, + "status": student.status, + } + list_data.append(data_small) + + return JsonResponse( + json.dumps(list_data), content_type="application/json", safe=False + ) diff --git a/app/apps.py b/app/apps.py index ed327d2..bcfe39b 100644 --- a/app/apps.py +++ b/app/apps.py @@ -2,5 +2,5 @@ from django.apps import AppConfig class AppConfig(AppConfig): - default_auto_field = 'django.db.models.BigAutoField' - name = 'app' + default_auto_field = "django.db.models.BigAutoField" + name = "app" diff --git a/app/migrations/0009_remove_student_password_remove_student_username_and_more.py b/app/migrations/0009_remove_student_password_remove_student_username_and_more.py new file mode 100644 index 0000000..bab96fc --- /dev/null +++ b/app/migrations/0009_remove_student_password_remove_student_username_and_more.py @@ -0,0 +1,29 @@ +# Generated by Django 5.1.5 on 2025-01-18 06:51 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("app", "0008_alter_leavereportstudent_leave_date_and_more"), + ] + + operations = [ + migrations.RemoveField( + model_name="student", + name="password", + ), + migrations.RemoveField( + model_name="student", + name="username", + ), + migrations.RemoveField( + model_name="teacher", + name="password", + ), + migrations.RemoveField( + model_name="teacher", + name="username", + ), + ] diff --git a/app/migrations/0010_alter_feedbackstudent_feedback_reply.py b/app/migrations/0010_alter_feedbackstudent_feedback_reply.py new file mode 100644 index 0000000..4421ca8 --- /dev/null +++ b/app/migrations/0010_alter_feedbackstudent_feedback_reply.py @@ -0,0 +1,18 @@ +# Generated by Django 5.1.5 on 2025-01-18 07:59 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("app", "0009_remove_student_password_remove_student_username_and_more"), + ] + + operations = [ + migrations.AlterField( + model_name="feedbackstudent", + name="feedback_reply", + field=models.TextField(blank=True, null=True), + ), + ] diff --git a/app/migrations/0011_rename_staff_id_feedbackteacher_teacher_id_and_more.py b/app/migrations/0011_rename_staff_id_feedbackteacher_teacher_id_and_more.py new file mode 100644 index 0000000..667d5b0 --- /dev/null +++ b/app/migrations/0011_rename_staff_id_feedbackteacher_teacher_id_and_more.py @@ -0,0 +1,23 @@ +# Generated by Django 5.1.5 on 2025-01-18 09:04 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("app", "0010_alter_feedbackstudent_feedback_reply"), + ] + + operations = [ + migrations.RenameField( + model_name="feedbackteacher", + old_name="staff_id", + new_name="teacher_id", + ), + migrations.AlterField( + model_name="feedbackteacher", + name="feedback_reply", + field=models.TextField(blank=True, null=True), + ), + ] diff --git a/app/migrations/0012_rename_academic_year_attendance_academic_year_id.py b/app/migrations/0012_rename_academic_year_attendance_academic_year_id.py new file mode 100644 index 0000000..e322820 --- /dev/null +++ b/app/migrations/0012_rename_academic_year_attendance_academic_year_id.py @@ -0,0 +1,18 @@ +# Generated by Django 5.1.5 on 2025-01-18 09:48 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("app", "0011_rename_staff_id_feedbackteacher_teacher_id_and_more"), + ] + + operations = [ + migrations.RenameField( + model_name="attendance", + old_name="academic_year", + new_name="academic_year_id", + ), + ] diff --git a/app/migrations/0013_student_fcm_token_student_password_student_user_and_more.py b/app/migrations/0013_student_fcm_token_student_password_student_user_and_more.py new file mode 100644 index 0000000..d44d748 --- /dev/null +++ b/app/migrations/0013_student_fcm_token_student_password_student_user_and_more.py @@ -0,0 +1,72 @@ +# Generated by Django 5.1.5 on 2025-01-18 10:24 + +import django.db.models.deletion +from django.conf import settings +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("app", "0012_rename_academic_year_attendance_academic_year_id"), + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.AddField( + model_name="student", + name="fcm_token", + field=models.TextField(default=""), + ), + migrations.AddField( + model_name="student", + name="password", + field=models.CharField(default="1", max_length=255), + preserve_default=False, + ), + migrations.AddField( + model_name="student", + name="user", + field=models.OneToOneField( + default="1", + on_delete=django.db.models.deletion.CASCADE, + related_name="student", + to=settings.AUTH_USER_MODEL, + ), + preserve_default=False, + ), + migrations.AddField( + model_name="student", + name="username", + field=models.CharField(default="1", max_length=255), + preserve_default=False, + ), + migrations.AddField( + model_name="teacher", + name="fcm_token", + field=models.TextField(default=""), + ), + migrations.AddField( + model_name="teacher", + name="password", + field=models.CharField(default="1", max_length=255), + preserve_default=False, + ), + migrations.AddField( + model_name="teacher", + name="user", + field=models.OneToOneField( + default="1", + on_delete=django.db.models.deletion.CASCADE, + related_name="teacher", + to=settings.AUTH_USER_MODEL, + ), + preserve_default=False, + ), + migrations.AddField( + model_name="teacher", + name="username", + field=models.CharField(default="1", max_length=255), + preserve_default=False, + ), + ] diff --git a/app/migrations/0014_remove_student_user_remove_student_username_and_more.py b/app/migrations/0014_remove_student_user_remove_student_username_and_more.py new file mode 100644 index 0000000..b357d8a --- /dev/null +++ b/app/migrations/0014_remove_student_user_remove_student_username_and_more.py @@ -0,0 +1,29 @@ +# Generated by Django 5.1.5 on 2025-01-18 10:39 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("app", "0013_student_fcm_token_student_password_student_user_and_more"), + ] + + operations = [ + migrations.RemoveField( + model_name="student", + name="user", + ), + migrations.RemoveField( + model_name="student", + name="username", + ), + migrations.RemoveField( + model_name="teacher", + name="user", + ), + migrations.RemoveField( + model_name="teacher", + name="username", + ), + ] diff --git a/app/models.py b/app/models.py index 525ad67..75fc506 100644 --- a/app/models.py +++ b/app/models.py @@ -1,6 +1,6 @@ from django.db import models from django.core.validators import RegexValidator, ValidationError - +from django.contrib.auth.models import User # Create your models here. @@ -15,8 +15,8 @@ class Student(models.Model): academic_year = models.ForeignKey( "AcademicYear", on_delete=models.CASCADE, related_name="students" ) - username = models.CharField(max_length=255) password = models.CharField(max_length=255) + fcm_token = models.TextField(default="") phone = models.CharField( max_length=10, validators=[RegexValidator(r"^\+?1?\d{9,15}$")] ) @@ -80,7 +80,7 @@ class Teacher(models.Model): dob = models.DateField() gender = models.CharField(max_length=1, choices=[("M", "Male"), ("F", "Female")]) address = models.CharField(max_length=255) - username = models.CharField(max_length=255) + fcm_token = models.TextField(default="") password = models.CharField(max_length=255) qualification_choice = ( ("SLC", "SLC"), @@ -181,8 +181,8 @@ class Attendance(models.Model): # Subject Attendance id = models.AutoField(primary_key=True) subject_id = models.ForeignKey(Subject, on_delete=models.DO_NOTHING) attendance_date = models.DateField() + academic_year_id = models.ForeignKey(AcademicYear, on_delete=models.CASCADE) created_at = models.DateTimeField(auto_now_add=True) - academic_year = models.ForeignKey(AcademicYear, on_delete=models.CASCADE) updated_at = models.DateTimeField(auto_now=True) @@ -219,15 +219,15 @@ class FeedbackStudent(models.Model): id = models.AutoField(primary_key=True) student_id = models.ForeignKey(Student, on_delete=models.CASCADE) feedback = models.TextField() - feedback_reply = models.TextField() + feedback_reply = models.TextField(blank=True, null=True) created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) class FeedbackTeacher(models.Model): id = models.AutoField(primary_key=True) - staff_id = models.ForeignKey(Teacher, on_delete=models.CASCADE) + teacher_id = models.ForeignKey(Teacher, on_delete=models.CASCADE) feedback = models.TextField() - feedback_reply = models.TextField() + feedback_reply = models.TextField(blank=True, null=True) created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) diff --git a/app/studentViews.py b/app/studentViews.py index e69de29..a397429 100644 --- a/app/studentViews.py +++ b/app/studentViews.py @@ -0,0 +1,163 @@ +from django.contrib.auth.decorators import login_required + +from django.shortcuts import render + + +@login_required +def student_dashboard(request): + return render(request, "student/dashboard.html") # Student-specific page + + +# @login_required +# @student_required +# def student_view_attendance(request): +# student = Student.objects.get(admin=request.user.id) +# course = student.course_id +# subjects = Subject.objects.filter(course_id=course) +# student = Student.objects.get(admin=user) +# student_notifcation = Student.objects.get(admin=request.user.id) +# notifications = NotificationStudent.objects.filter( +# student_id=student_notifcation.id +# ) +# return render( +# request, +# "student_template/student_view_attendance.html", +# {"subjects": subjects, "student": student, "notifications": notifications}, +# ) +# +# +# @login_required +# @student_required +# def student_view_attendance_post(request): +# subject_id = request.POST.get("subject") +# start_date = request.POST.get("start_date") +# end_date = request.POST.get("end_date") +# +# start_data_parse = datetime.datetime.strptime(start_date, "%Y-%m-%d").date() +# end_data_parse = datetime.datetime.strptime(end_date, "%Y-%m-%d").date() +# subject_obj = Subjects.objects.get(id=subject_id) +# user_object = CustomUser.objects.get(id=request.user.id) +# stud_obj = Students.objects.get(admin=user_object) +# user = CustomUser.objects.get(id=request.user.id) +# student = Students.objects.get(admin=user) +# student_notifcation = Students.objects.get(admin=request.user.id) +# notifications = NotificationStudent.objects.filter( +# student_id=student_notifcation.id +# ) +# +# attendance = Attendance.objects.filter( +# attendance_date__range=(start_data_parse, end_data_parse), +# subject_id=subject_obj, +# ) +# attendance_reports = AttendanceReport.objects.filter( +# attendance_id__in=attendance, student_id=stud_obj +# ) +# return render( +# request, +# "student_template/student_attendance_data.html", +# { +# "attendance_reports": attendance_reports, +# "student": student, +# "notifications": notifications, +# }, +# ) +# +# +# @login_required +# @student_required +# def student_apply_leave(request): +# student_obj = Student.objects.get(admin=request.user.id) +# leave_data = LeaveReportStudent.objects.filter(student_id=student_obj) +# user = CustomUser.objects.get(id=request.user.id) +# student = Student.objects.get(admin=user) +# student_notifcation = Student.objects.get(admin=request.user.id) +# notifications = NotificationStudent.objects.filter( +# student_id=student_notifcation.id +# ) +# return render( +# request, +# "student/apply_leave.html", +# {"leave_data": leave_data, "student": student, "notifications": notifications}, +# ) +# +# +# @login_required +# @student_required +# def student_apply_leave_save(request): +# if request.method != "POST": +# return HttpResponseRedirect(reverse("student_apply_leave")) +# else: +# leave_start_date = request.POST.get("leave_start_date") +# leave_end_date = request.POST.get("leave_end_date") +# leave_date = request.POST.get("leave_date") +# leave_msg = request.POST.get("leave_msg") +# +# student_obj = Student.objects.get(admin=request.user.id) +# try: +# leave_report = LeaveReportStudent( +# student_id=student_obj, +# leave_start_date=leave_start_date, +# leave_end_date=leave_end_date, +# leave_message=leave_msg, +# leave_status=0, +# ) +# leave_report.save() +# messages.success(request, "Successfully Applied for Leave") +# return HttpResponseRedirect(reverse("student_apply_leave")) +# except: +# messages.error(request, "Failed To Apply for Leave") +# return HttpResponseRedirect(reverse("student_apply_leave")) +# +# +# @login_required +# @student_required +# def student_feedback(request): +# staff_id = Student.objects.get(admin=request.user.id) +# feedback_data = FeedBackStudent.objects.filter(student_id=staff_id) +# student = Student.objects.get(admin=user) +# student_notifcation = Student.objects.get(admin=request.user.id) +# notifications = NotificationStudent.objects.filter( +# student_id=student_notifcation.id +# ) +# return render( +# request, +# "student_template/student_feedback.html", +# { +# "feedback_data": feedback_data, +# "student": student, +# "notifications": notifications, +# }, +# ) +# +# +# @login_required +# @student_required +# def student_feedback_save(request): +# if request.method != "POST": +# return HttpResponseRedirect(reverse("student_feedback")) +# else: +# feedback_msg = request.POST.get("feedback_msg") +# +# student_obj = Student.objects.get(admin=request.user.id) +# try: +# feedback = FeedBackStudent( +# student_id=student_obj, feedback=feedback_msg, feedback_reply="" +# ) +# feedback.save() +# messages.success(request, "Feedback submitted for review") +# return HttpResponseRedirect(reverse("student_feedback")) +# except: +# messages.error(request, "Could not Submit") +# return HttpResponseRedirect(reverse("student_feedback")) +# +# +# @csrf_exempt +# def student_fcmtoken_save(request): +# token = request.POST.get("token") +# try: +# student = Student.objects.get(admin=request.user.id) +# student.fcm_token = token +# student.save() +# return HttpResponse("True") +# except: +# return HttpResponse("False") diff --git a/app/teacherViews.py b/app/teacherViews.py index e69de29..a0a88b9 100644 --- a/app/teacherViews.py +++ b/app/teacherViews.py @@ -0,0 +1,7 @@ +from django.shortcuts import render +from django.contrib.auth.decorators import login_required + + +@login_required +def teacher_dashboard(request): + return render(request, "teacher/dashboard.html") diff --git a/app/urls.py b/app/urls.py index 8d1a467..d457173 100644 --- a/app/urls.py +++ b/app/urls.py @@ -1,5 +1,5 @@ from django.urls import path -from app import adminViews +from app import adminViews, studentViews, teacherViews urlpatterns = [ path("dashboard/", adminViews.admin_home, name="dashboard"), @@ -29,5 +29,93 @@ urlpatterns = [ path( "delete_subject//", adminViews.delete_subject, name="delete_subject" ), + path("manage_student/", adminViews.manage_student, name="manage_student"), + path("add_student/", adminViews.add_student, name="add_student"), + path( + "edit_student//", adminViews.edit_student, name="edit_student" + ), + path( + "delete_student//", + adminViews.delete_student, + name="delete_student", + ), + path("manage_teacher/", adminViews.manage_teacher, name="manage_teacher"), + path("add_teacher/", adminViews.add_teacher, name="add_teacher"), + path( + "edit_teacher//", adminViews.edit_teacher, name="edit_teacher" + ), + path( + "delete_teacher//", + adminViews.delete_teacher, + name="delete_teacher", + ), + path( + "student_feedback_message/", + adminViews.student_feedback_message, + name="student_feedback_message", + ), + path( + "student_feedback_message_reply/", + adminViews.student_feedback_message_reply, + name="student_feedback_message_reply", + ), + path( + "teacher_feedback/", + adminViews.teacher_feedback, + name="teacher_feedback", + ), + path( + "teacher_feedback_replied/", + adminViews.teacher_feedback_replied, + name="teacher_feedback_replied", + ), + path( + "student_leave_view/", adminViews.student_leave_view, name="student_leave_view" + ), + path( + "student_leave_approve//", + adminViews.student_leave_approve, + name="student_leave_approve", + ), + path( + "student_leave_reject//", + adminViews.student_leave_reject, + name="student_leave_reject", + ), + path( + "teacher_leave_view/", adminViews.teacher_leave_view, name="teacher_leave_view" + ), + path( + "teacher_leave_approve//", + adminViews.teacher_leave_approve, + name="teacher_leave_approve", + ), + path( + "teacher_leave_reject//", + adminViews.teacher_leave_reject, + name="teacher_leave_reject", + ), + path( + "admin_view_attendance/", + adminViews.admin_view_attendance, + name="admin_view_attendance", + ), + path( + "admin_get_attendance_dates/", + adminViews.admin_get_attendance_dates, + name="admin_get_attendance_dates", + ), + path( + "admin_get_attendance_student/", + adminViews.admin_get_attendance_student, + name="admin_get_attendance_student", + ), + # ── Student ─────────────────────────────────────────────────────────── + path( + "student_dashboard/", studentViews.student_dashboard, name="student_dashboard" + ), + # ── teacher ─────────────────────────────────────────────────────────── + path( + "teacher_dashboard/", teacherViews.teacher_dashboard, name="teacher_dashboard" + ), ] - diff --git a/app/views.py b/app/views.py index 73d737b..9724de7 100644 --- a/app/views.py +++ b/app/views.py @@ -2,5 +2,5 @@ from django.contrib.auth import authenticate, login, logout from django.http import HttpResponseRedirect, HttpResponse from django.shortcuts import render, redirect from django.contrib import messages - +from django.contrib.auth.decorators import login_required # Create your views here. diff --git a/student_management_system/settings.py b/student_management_system/settings.py index d314837..88327e7 100644 --- a/student_management_system/settings.py +++ b/student_management_system/settings.py @@ -16,6 +16,7 @@ from student_management_system.jazzmin import JAZZMIN_SETTINGS, JAZZMIN_UI_TWEAK # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/5.1/howto/deployment/checklist/ diff --git a/templates/hod/add_student.html b/templates/hod/add_student.html new file mode 100644 index 0000000..11567eb --- /dev/null +++ b/templates/hod/add_student.html @@ -0,0 +1,149 @@ +{% extends "admin/base_site.html" %} +{% block page_title %}{{ title }}{% endblock %} +{% load static %} +{% block extrastyle %} + +{% endblock %} +{% block content %} +
+

Add Student

+
+ {% csrf_token %} +
+ +
+ + +
+
+ + +
+
+ + +
+ +
+ + +
+
+ + +
+ +
+ + +
+
+ + +
+
+ + +
+
+ + +
+ +
+ + +
+ +
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ +
+ + +
+
+ + +
+
+ + +
+
+
+ + Cancel +
+
+
+{% endblock %} diff --git a/templates/hod/add_teacher.html b/templates/hod/add_teacher.html new file mode 100644 index 0000000..06dc64e --- /dev/null +++ b/templates/hod/add_teacher.html @@ -0,0 +1,100 @@ +{% extends 'admin/base_site.html' %} +{% block content %} +
+

{{ title }}

+
+ {% csrf_token %} +
+
+ + +
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+
+ + Cancel +
+
+
+{% endblock %} diff --git a/templates/hod/edit_student.html b/templates/hod/edit_student.html new file mode 100644 index 0000000..00abaef --- /dev/null +++ b/templates/hod/edit_student.html @@ -0,0 +1,212 @@ +{% extends "admin/base_site.html" %} +{% load static %} +{% block extrastyle %} + + + +{% endblock %} +{% block content %} +
+ +
+ {% csrf_token %} +
+
+ + +
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+ + +
+
+ + Cancel +
+
+
+{% endblock %} diff --git a/templates/hod/edit_teacher.html b/templates/hod/edit_teacher.html new file mode 100644 index 0000000..771fc5c --- /dev/null +++ b/templates/hod/edit_teacher.html @@ -0,0 +1,126 @@ +{% extends 'admin/base_site.html' %} +{% block content %} +
+

Edit Teacher

+
+ {% csrf_token %} +
+
+ + +
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+
+ + Cancel +
+
+
+{% endblock %} diff --git a/templates/hod/manage_student.html b/templates/hod/manage_student.html new file mode 100644 index 0000000..7dd536e --- /dev/null +++ b/templates/hod/manage_student.html @@ -0,0 +1,65 @@ +{% extends "admin/base_site.html" %} +{% block page_title %}{{ title }}{% endblock %} +{% block content %} +
+
+
+

Manage Students

+
+ +
+
+
+
+ +
+
+ +
+
+
+
+ + + + + + + + + + + + + + {% for student in students %} + + + + + + + + + + {% empty %} + + + + {% endfor %} + +
S.NFull NameCourseAcademic YearPhoneEmailActions
{{ forloop.counter }}{{ student.first_name }}{{ student.course.name }}{{ student.academic_year.start_date|date:"Y" }}{{ student.phone }}{{ student.email }} + Edit + Delete +
No students found
+
+
+{% endblock %} diff --git a/templates/hod/manage_subject.html b/templates/hod/manage_subject.html index da50ceb..78ba22a 100644 --- a/templates/hod/manage_subject.html +++ b/templates/hod/manage_subject.html @@ -1,5 +1,5 @@ {% extends "admin/base_site.html" %} -{% block page_title %}Manage Subjects{% endblock %} +{% block page_title %}{{ title }}{% endblock %} {% load static %} {% block extrastyle %} {% endblock %} {% block content %} -
-

Manage Subjects

- -
-
-
- - + + + +{% endblock %} +{% block custom_js %} + +{% endblock custom_js %} diff --git a/templates/student/dashboard.html b/templates/student/dashboard.html new file mode 100644 index 0000000..8252370 --- /dev/null +++ b/templates/student/dashboard.html @@ -0,0 +1,83 @@ +{% extends "admin/base_site.html" %} +{% block content %} +

Dashboard

+

Welcome

+ +
+
+
+
Course
+

DCOM

+
+
+
+
+
Current Semester
+

5

+
+
+
+
+
Total Subject
+

12

+
+
+
+ +
+ +
+ +
+ +
+ +{% endblock %} diff --git a/templates/teacher/dashboard.html b/templates/teacher/dashboard.html new file mode 100644 index 0000000..8252370 --- /dev/null +++ b/templates/teacher/dashboard.html @@ -0,0 +1,83 @@ +{% extends "admin/base_site.html" %} +{% block content %} +

Dashboard

+

Welcome

+ +
+
+
+
Course
+

DCOM

+
+
+
+
+
Current Semester
+

5

+
+
+
+
+
Total Subject
+

12

+
+
+
+ +
+ +
+ +
+ +
+ +{% endblock %}