From fa60eac6ed44be7d38e9dcbd3abdc66e8db7bcad Mon Sep 17 00:00:00 2001 From: MarcinL1337 Date: Tue, 10 Dec 2024 21:51:07 +0100 Subject: [PATCH] New branch for add to schedule button feature. Button works, but it doesn't change to remove from schedule after adding yet --- .../courses/course_parts/groups_section.html | 23 +++++++++++++ zapisy/apps/enrollment/records/urls.py | 2 ++ zapisy/apps/enrollment/records/views.py | 33 +++++++++++++++++++ 3 files changed, 58 insertions(+) diff --git a/zapisy/apps/enrollment/courses/templates/courses/course_parts/groups_section.html b/zapisy/apps/enrollment/courses/templates/courses/course_parts/groups_section.html index ef2fad2118..e270a0c230 100644 --- a/zapisy/apps/enrollment/courses/templates/courses/course_parts/groups_section.html +++ b/zapisy/apps/enrollment/courses/templates/courses/course_parts/groups_section.html @@ -124,6 +124,29 @@

{{ class_type|decode_class_type_plural }} lista + + {% if group.is_pinned %} +
{% csrf_token %} +
+ + +
+
+ {% else %} +
{% csrf_token %} +
+ + +
+
+ {% endif %} + {% endif %}
diff --git a/zapisy/apps/enrollment/records/urls.py b/zapisy/apps/enrollment/records/urls.py index 91f1fde3d7..77a8a0d0d8 100644 --- a/zapisy/apps/enrollment/records/urls.py +++ b/zapisy/apps/enrollment/records/urls.py @@ -7,5 +7,7 @@ urlpatterns = [ path('enqueue/', views.enqueue, name='records-enqueue'), path('dequeue/', views.dequeue, name='records-dequeue'), + path('pin/', views.pin, name='pin'), + path('unpin/', views.unpin, name='unpin'), path('queue-set-priority/', views.queue_set_priority, name='records-set-priority'), ] diff --git a/zapisy/apps/enrollment/records/views.py b/zapisy/apps/enrollment/records/views.py index cc383bbd36..50e3493382 100644 --- a/zapisy/apps/enrollment/records/views.py +++ b/zapisy/apps/enrollment/records/views.py @@ -2,9 +2,11 @@ from django.http import Http404 from django.shortcuts import redirect from django.views.decorators.http import require_POST +from django.shortcuts import Http404, HttpResponse from apps.enrollment.courses.models import Group from apps.enrollment.records.models.records import Record +from apps.enrollment.timetable.models import Pin from apps.users.decorators import student_required from apps.users.models import Student @@ -58,6 +60,37 @@ def dequeue(request): return redirect('course-page', slug=group.course.slug) +@student_required +@require_POST +def pin(request): + """Pins a course to a timetable prototype.""" + student = request.user.student + try: + group_id = request.POST['group_id'] + except KeyError: + raise Http404 + Pin.objects.get_or_create(student_id=student.pk, group_id=group_id) + group = Group.objects.select_related('course').get(pk=group_id) + group.is_pinned = True + return HttpResponse(status=204) + + +@student_required +@require_POST +def unpin(request): + """Unpins a course from a timetable prototype.""" + student = request.user.student + try: + group_id = request.POST['group_id'] + except KeyError: + raise Http404 + Pin.objects.filter(student_id=student.pk, group_id=group_id).delete() + group = Group.objects.select_related('course').get(pk=group_id) + group.is_pinned = False + return HttpResponse(status=204) + + + @student_required @require_POST def queue_set_priority(request):