Skip to content

Commit

Permalink
New branch for add to schedule button feature. Button works, but it d…
Browse files Browse the repository at this point in the history
…oesn't change to remove from schedule after adding yet
  • Loading branch information
MarcinL1337 committed Dec 10, 2024
1 parent acb6434 commit fa60eac
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,29 @@ <h3 class="d-inline-block">{{ class_type|decode_class_type_plural }}
<td>
<a href="{% url 'group-view' group.pk %}">lista</a>
</td>
<td class="schedule">
{% if group.is_pinned %}
<form action="{% url 'unpin' %}" method="post" class="removeFromSchedule">{% csrf_token %}
<div>
<input type="hidden" name="group_id" value="{{ group.pk }}"/>
<button type="submit" class="btn btn-danger btn-sm removeFromScheduleButton"
onclick="return confirm('Czy na pewno chcesz usunąć tą grupę z prototypu planu zajęć?');">
Usuń z prototypu
</button>
</div>
</form>
{% else %}
<form action="{% url 'pin' %}" method="post" class="addToSchedule">{% csrf_token %}
<div>
<input type="hidden" name="group_id" value="{{ group.pk }}"/>
<button type="submit" class="btn btn-primary btn-sm addToScheduleButton"
onclick="return confirm('Czy na pewno chcesz dodać tą grupę do prototypu planu zajęć?');">
Dodaj do prototypu
</button>
</div>
</form>
{% endif %}
</td>
{% endif %}
<td class="schedule">
<form action="" method="post" class="addToSchedule">
Expand Down
2 changes: 2 additions & 0 deletions zapisy/apps/enrollment/records/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
]
33 changes: 33 additions & 0 deletions zapisy/apps/enrollment/records/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit fa60eac

Please sign in to comment.