Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wybór semestru w planie zajęć nie tylko własnym, ale też dowolnej osoby #1778

Open
wants to merge 4 commits into
base: master-dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion zapisy/apps/users/templates/users/employee_profile_contents.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,28 @@ <h3>Konsultacje:</h3>
{% endif %}

<h3 class="subheader">Plan zajęć:</h3>

<nav class="col-lg-3 col-12 d-print-none order-first order-lg-last mb-3">
<div class="dropdown">
<div class="btn-group btn-block mb-3 w-100">
<button class="btn btn-light" disabled>
<strong>Semestr {{ semester }}</strong>
</button>
<button class="btn btn-light dropdown-toggle dropdown-toggle-split"
href="#" role="button" id="semester-dropdown"
data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="sr-only"></span>
</button>
<div class="dropdown-menu" aria-labelledby="semester-dropdown">
{% for semester in all_semesters %}
<a class="dropdown-item semester-link"
href={% url 'employee-profile-semester' employee.user_id semester.pk %}>
{{ semester }}
</a>
{% endfor %}
</div>
</div>
</div>
</nav>
<div id="timetable"></div>
<script id="timetable-data" type="application/json">{{ groups_json|safe }}</script>
{% render_bundle 'timetable-timetable-component' %}
Expand Down
22 changes: 22 additions & 0 deletions zapisy/apps/users/templates/users/student_profile_contents.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,28 @@ <h3 class="subheader">{{student.get_full_name}}</h3>
</table>

<h3 class="subheader">Plan zajęć:</h3>
<nav class="col-lg-3 col-12 d-print-none order-first order-lg-last mb-3">
<div class="dropdown">
<div class="btn-group btn-block mb-3 w-100">
<button class="btn btn-light" disabled>
<strong>Semestr {{ semester }}</strong>
</button>
<button class="btn btn-light dropdown-toggle dropdown-toggle-split"
href="#" role="button" id="semester-dropdown"
data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="sr-only"></span>
</button>
<div class="dropdown-menu" aria-labelledby="semester-dropdown">
{% for semester in all_semesters %}
<a class="dropdown-item semester-link"
href={% url 'student-profile-semester' student.user_id semester.pk %}>
{{ semester }}
</a>
{% endfor %}
</div>
</div>
</div>
</nav>
<div id="timetable"></div>
<script id="timetable-data" type="application/json">{{ groups_json|safe }}</script>
{% render_bundle 'timetable-timetable-component' %}
Expand Down
2 changes: 2 additions & 0 deletions zapisy/apps/users/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
path('employees/', views.employees_view, name='employees-list'),
path('students/', views.students_view, name='students-list'),
path('employees/<int:user_id>/', views.employees_view, name='employee-profile'),
path("employess/<int:user_id>/semester/<int:semester_id>/", views.employees_view, name="employee-profile-semester"),
path('students/<int:user_id>/', views.students_view, name='student-profile'),
path("students/<int:user_id>/semester/<int:semester_id>/", views.students_view, name="student-profile-semester"),
path('personal-data-consent/', views.personal_data_consent, name='personal_data_consent'),
]
24 changes: 19 additions & 5 deletions zapisy/apps/users/views.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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,
Expand All @@ -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 = {
Expand All @@ -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')
Expand All @@ -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)

Expand Down
Loading