From f1be68ece87d7103c94b205c52944808f439dc8d Mon Sep 17 00:00:00 2001 From: TareqMonwer Date: Mon, 4 Nov 2024 19:19:47 +0600 Subject: [PATCH] update academics url path references --- .../dj_sms_context_processor.py | 6 +++++- django_school_management/academics/models.py | 9 ++++---- .../templates/academics/create_subject.html | 12 ++++++----- .../templates/academics/subject_list.html | 2 +- django_school_management/academics/views.py | 21 ++++++++++--------- templates/_sidebar.html | 16 +++++++++----- templates/academics/departments.html | 4 ++-- 7 files changed, 42 insertions(+), 28 deletions(-) diff --git a/context_processors/dj_sms_context_processor.py b/context_processors/dj_sms_context_processor.py index 70e05881..2a1b6e2b 100644 --- a/context_processors/dj_sms_context_processor.py +++ b/context_processors/dj_sms_context_processor.py @@ -1,3 +1,4 @@ +from django_school_management.academics.constants import AcademicsURLConstants from django_school_management.accounts.constants import AccountURLConstants from django_school_management.institute.models import (InstituteProfile, TextWidget, ListWidget @@ -42,4 +43,7 @@ def attach_institute_data_ctx_processor(request): def attach_urls_for_common_templates(request): - return dict(account_urls=AccountURLConstants) + return dict( + account_urls=AccountURLConstants, + academic_urls=AcademicsURLConstants, + ) diff --git a/django_school_management/academics/models.py b/django_school_management/academics/models.py index 79db6011..a525dee0 100644 --- a/django_school_management/academics/models.py +++ b/django_school_management/academics/models.py @@ -5,6 +5,7 @@ from django.urls import reverse from django_school_management.teachers.models import Teacher +from .constants import AcademicsURLConstants from .utils import model_help_texts @@ -56,7 +57,7 @@ def __str__(self): return str(self.name) def create_resource(self): - return reverse('academics:create_department') + return reverse(AcademicsURLConstants.create_department) class AcademicSession(TimeStampedModel): @@ -69,7 +70,7 @@ def __str__(self): return '{} - {}'.format(self.year, self.year + 1) def create_resource(self): - return reverse('academics:create_academic_session') + return reverse(AcademicsURLConstants.create_academic_session) class Semester(TimeStampedModel): @@ -97,7 +98,7 @@ def __str__(self): return '%sth' % self.number def create_resource(self): - return reverse('academics:create_semester') + return reverse(AcademicsURLConstants.create_semester) class Subject(TimeStampedModel): @@ -121,7 +122,7 @@ def __str__(self): return "{} ({})".format(self.name, self.subject_code) def create_resource(self): - return reverse('academics:create_subject') + return reverse(AcademicsURLConstants.create_subject) class Batch(TimeStampedModel): diff --git a/django_school_management/academics/templates/academics/create_subject.html b/django_school_management/academics/templates/academics/create_subject.html index b5cfbab2..bfeadbd1 100644 --- a/django_school_management/academics/templates/academics/create_subject.html +++ b/django_school_management/academics/templates/academics/create_subject.html @@ -6,11 +6,13 @@ {% endblock %} {% block dashboard-body %} -
- {% csrf_token %} - {{ form|crispy }} - -
+

Introduce New Subject

+
+
+ {% csrf_token %} + {{ form|crispy }} + +
{% endblock %} diff --git a/django_school_management/academics/templates/academics/subject_list.html b/django_school_management/academics/templates/academics/subject_list.html index 452807c0..af76ee71 100644 --- a/django_school_management/academics/templates/academics/subject_list.html +++ b/django_school_management/academics/templates/academics/subject_list.html @@ -6,7 +6,7 @@ diff --git a/django_school_management/academics/views.py b/django_school_management/academics/views.py index fa204b11..1682bd93 100644 --- a/django_school_management/academics/views.py +++ b/django_school_management/academics/views.py @@ -6,6 +6,7 @@ from django.views.generic import ListView from django.urls import reverse_lazy +from .constants import AcademicsURLConstants from .models import (Semester, Department, AcademicSession, Subject) from .forms import SemesterForm, DepartmentForm, AcademicSessionForm, SubjectForm @@ -32,7 +33,7 @@ def semesters(request): semster = form.save(commit=False) semster.created_by = request.user semster.save() - return redirect('academics:all_semester') + return redirect(AcademicsURLConstants.all_semester) form = SemesterForm() ctx = { 'all_sems': all_sems, @@ -53,7 +54,7 @@ def academic_session(request): ac_session = form.save(commit=False) ac_session.created_by = request.user ac_session.save() - return redirect('academics:academic_sessions') + return redirect(AcademicsURLConstants.academic_sessions) else: form = AcademicSessionForm() all_academic_session = AcademicSession.objects.all() @@ -76,7 +77,7 @@ def departments(request): dept = form.save(commit=False) dept.created_by = request.user dept.save() - return redirect('academics:departments') + return redirect(AcademicsURLConstants.departments) else: form = DepartmentForm() all_department = Department.objects.all() @@ -91,14 +92,14 @@ def departments(request): def delete_semester(request, pk): obj = get_object_or_404(Semester, pk=pk) obj.delete() - return redirect('academics:departments') + return redirect(AcademicsURLConstants.all_semester) class UpdateDepartment(LoginRequiredMixin, UserPassesTestMixin, UpdateView): model = Department form_class = DepartmentForm template_name = 'academics/update_department.html' - success_url = reverse_lazy('academics:departments') + success_url = reverse_lazy(AcademicsURLConstants.departments) def test_func(self): user = self.request.user @@ -112,7 +113,7 @@ def form_valid(self, form): def delete_department(request, pk): obj = get_object_or_404(Department, pk=pk) obj.delete() - return redirect('academics:departments') + return redirect(AcademicsURLConstants.departments) @user_passes_test(user_is_teacher_or_administrative) @@ -149,7 +150,7 @@ def upload_subjects_csv(request): class CreateDepartmentView(LoginRequiredMixin, UserPassesTestMixin, CreateView, CreatedByMixin): form_class = DepartmentForm - success_url = reverse_lazy('academics:departments') + success_url = reverse_lazy(AcademicsURLConstants.departments) template_name = 'academics/create_department.html' def test_func(self): @@ -161,7 +162,7 @@ def test_func(self): class CreateSemesterView(LoginRequiredMixin, UserPassesTestMixin, CreateView, CreatedByMixin): form_class = SemesterForm - success_url = reverse_lazy('academics:all_semester') + success_url = reverse_lazy(AcademicsURLConstants.all_semester) template_name = 'academics/create_semester.html' def test_func(self): @@ -173,7 +174,7 @@ def test_func(self): class CreateAcademicSession(LoginRequiredMixin, UserPassesTestMixin, CreateView, CreatedByMixin): form_class = AcademicSessionForm - success_url = reverse_lazy('academics:academic_sessions') + success_url = reverse_lazy(AcademicsURLConstants.academic_sessions) template_name = 'academics/create_academic_semester.html' def test_func(self): @@ -198,7 +199,7 @@ def test_func(self): class CreateSubjectView(LoginRequiredMixin, UserPassesTestMixin, CreateView, CreatedByMixin): form_class = SubjectForm template_name = 'academics/create_subject.html' - success_url = reverse_lazy('academics:subject_list') + success_url = reverse_lazy(AcademicsURLConstants.subject_list) def test_func(self): user = self.request.user diff --git a/templates/_sidebar.html b/templates/_sidebar.html index 60b7e54d..ce50eefe 100644 --- a/templates/_sidebar.html +++ b/templates/_sidebar.html @@ -157,13 +157,13 @@