Skip to content

Commit

Permalink
update academics url path references
Browse files Browse the repository at this point in the history
  • Loading branch information
TareqMonwer committed Nov 4, 2024
1 parent c21bb53 commit f1be68e
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 28 deletions.
6 changes: 5 additions & 1 deletion context_processors/dj_sms_context_processor.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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,
)
9 changes: 5 additions & 4 deletions django_school_management/academics/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
{% endblock %}

{% block dashboard-body %}
<form action="{% url 'academics:create_subject' %}" method="POST" class="d-block">
{% csrf_token %}
{{ form|crispy }}
<input type="submit" value="Create Subject" class="btn btn-dark">
</form>
<h4>Introduce New Subject</h4>
<hr>
<form action="{% url academic_urls.create_subject %}" method="POST" class="d-block">
{% csrf_token %}
{{ form|crispy }}
<input type="submit" value="Create Subject" class="btn btn-dark">
</form>
{% endblock %}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="#">Dashboard</a></li>
<li class="breadcrumb-item">
<a href="{% url 'academics:subject_list' %}">Subjects</a>
<a href="{% url academic_urls.subject_list %}">Subjects</a>
</li>
<li class="breadcrumb-item active" aria-current="page">All Subjects</li>
</ol>
Expand Down
21 changes: 11 additions & 10 deletions django_school_management/academics/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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()
Expand 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()
Expand 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
Expand All @@ -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)
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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
Expand Down
16 changes: 11 additions & 5 deletions templates/_sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,13 @@
<ul class="dropdown-menu">
<li>
<a class="sidebar-link"
href="{% url 'academics:departments' %}">
href="{% url academic_urls.departments %}">
Departments
</a>
</li>
<li>
<a class="sidebar-link"
href="{% url 'academics:create_subject' %}">
href="{% url academic_urls.create_subject %}">
Create Subject
</a>
</li>
Expand All @@ -181,19 +181,25 @@
</li>
<li>
<a class="sidebar-link"
href="{% url 'academics:academic_sessions' %}">
href="{% url academic_urls.academic_sessions %}">
Academic Sessions
</a>
</li>
<li>
<a class="sidebar-link"
href="{% url 'academics:create_semester' %}">
href="{% url academic_urls.create_semester %}">
Create Semester
</a>
</li>
<li>
<a class="sidebar-link"
href="{% url 'academics:all_semester' %}">
href="{% url academic_urls.all_semester %}">
Semesters
</a>
</li>
<li>
<a class="sidebar-link"
href="{% url academic_urls.all_semester %}">
Semesters
</a>
</li>
Expand Down
4 changes: 2 additions & 2 deletions templates/academics/departments.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
<td>{{ department.head.name }}</td>
<td>{{ department.created_by }}</td>
<td>
<a class="btn btn-sm btn-danger" href="{% url 'academics:delete_dept' pk=department.id %}">
<a class="btn btn-sm btn-danger" href="{% url academic_urls.delete_dept pk=department.id %}">
Delete
</a>
<a href="{% url 'academics:update_department' pk=department.pk %}" class="btn btn-sm btn-primary">
<a href="{% url academic_urls.update_department pk=department.pk %}" class="btn btn-sm btn-primary">
Update
</a>
</td>
Expand Down

0 comments on commit f1be68e

Please sign in to comment.