diff --git a/zapisy/apps/enrollment/timetable/templates/timetable/timetable.html b/zapisy/apps/enrollment/timetable/templates/timetable/timetable.html index 73662400a6..61b62e7da5 100644 --- a/zapisy/apps/enrollment/timetable/templates/timetable/timetable.html +++ b/zapisy/apps/enrollment/timetable/templates/timetable/timetable.html @@ -29,28 +29,7 @@

{% endif %} - + {% include "semester_dropdown.html" with url_pattern_name="my-timetable-semester" %}
diff --git a/zapisy/apps/users/templates/users/employee_profile_contents.html b/zapisy/apps/users/templates/users/employee_profile_contents.html index 3e66e0e901..04888070be 100644 --- a/zapisy/apps/users/templates/users/employee_profile_contents.html +++ b/zapisy/apps/users/templates/users/employee_profile_contents.html @@ -44,7 +44,7 @@

Konsultacje:

{% endif %}

Plan zajęć:

- + {% include "semester_dropdown.html" with url_pattern_name="employee-profile-semester" user_id=employee.user_id %}
{% render_bundle 'timetable-timetable-component' %} diff --git a/zapisy/apps/users/templates/users/student_profile_contents.html b/zapisy/apps/users/templates/users/student_profile_contents.html index d4e703fa5a..33a4d99629 100644 --- a/zapisy/apps/users/templates/users/student_profile_contents.html +++ b/zapisy/apps/users/templates/users/student_profile_contents.html @@ -40,6 +40,7 @@

{{student.get_full_name}}

Plan zajęć:

+ {% include "semester_dropdown.html" with url_pattern_name="student-profile-semester" user_id=student.user_id %}
{% render_bundle 'timetable-timetable-component' %} diff --git a/zapisy/apps/users/urls.py b/zapisy/apps/users/urls.py index 791dac5bba..243eb87334 100644 --- a/zapisy/apps/users/urls.py +++ b/zapisy/apps/users/urls.py @@ -9,6 +9,8 @@ path('employees/', views.employees_view, name='employees-list'), path('students/', views.students_view, name='students-list'), path('employees//', views.employees_view, name='employee-profile'), + path("employess//semester//", views.employees_view, name="employee-profile-semester"), path('students//', views.students_view, name='student-profile'), + path("students//semester//", views.students_view, name="student-profile-semester"), path('personal-data-consent/', views.personal_data_consent, name='personal_data_consent'), ] diff --git a/zapisy/apps/users/views.py b/zapisy/apps/users/views.py index a7f5753148..82c5ad9982 100644 --- a/zapisy/apps/users/views.py +++ b/zapisy/apps/users/views.py @@ -1,10 +1,11 @@ import json import logging +from typing import Optional from django.contrib import messages from django.contrib.auth.decorators import login_required from django.core.serializers.json import DjangoJSONEncoder -from django.shortcuts import Http404, redirect, render, reverse +from django.shortcuts import get_object_or_404, Http404, redirect, render, reverse from django.views.decorators.http import require_POST from apps.enrollment.courses.models import Group, Semester @@ -23,7 +24,7 @@ @login_required @external_contractor_forbidden -def students_view(request, user_id: int = None): +def students_view(request, user_id: int = None, semester_id: Optional[int] = None): """View for students list and student profile if user id in URL is provided.""" students_queryset = Student.get_active_students().select_related('user') if not request.user.employee: @@ -54,7 +55,11 @@ def students_view(request, user_id: int = None): messages.warning(request, "Student ukrył swój profil") return redirect('students-list') - semester = Semester.get_upcoming_semester() + semester: Optional[Semester] + if semester_id is None: + semester = Semester.get_upcoming_semester() + else: + semester = get_object_or_404(Semester, pk=semester_id) records = Record.objects.filter( student=student, @@ -73,11 +78,13 @@ def students_view(request, user_id: int = None): data.update({ 'student': student, 'groups_json': json.dumps(group_dicts, cls=DjangoJSONEncoder), + 'semester': semester, + 'all_semesters': Semester.objects.filter(visible=True) }) return render(request, 'users/users_view.html', data) -def employees_view(request, user_id: int = None): +def employees_view(request, user_id: int = None, semester_id: Optional[int] = None): """View for employees list and employee profile if user id in URL is provided.""" employees_queryset = Employee.get_actives().select_related('user') employees = { @@ -101,7 +108,12 @@ def employees_view(request, user_id: int = None): except Employee.DoesNotExist: raise Http404 - semester = Semester.get_upcoming_semester() + semester: Optional[Semester] + if semester_id is None: + semester = Semester.get_upcoming_semester() + else: + semester = get_object_or_404(Semester, pk=semester_id) + groups = Group.objects.filter( course__semester_id=semester.pk, teacher=employee).select_related( 'teacher', 'teacher__user', 'course').prefetch_related('term', 'term__classrooms') @@ -117,6 +129,8 @@ def employees_view(request, user_id: int = None): data.update({ 'employee': employee, 'groups_json': json.dumps(group_dicts, cls=DjangoJSONEncoder), + 'semester': semester, + 'all_semesters': Semester.objects.filter(visible=True) }) return render(request, 'users/users_view.html', data) diff --git a/zapisy/templates/semester_dropdown.html b/zapisy/templates/semester_dropdown.html new file mode 100644 index 0000000000..977ae3d94f --- /dev/null +++ b/zapisy/templates/semester_dropdown.html @@ -0,0 +1,29 @@ + \ No newline at end of file