Skip to content

Commit bae1daa

Browse files
committed
Change course fav/unfav button to POST only
1 parent b76d32f commit bae1daa

2 files changed

Lines changed: 32 additions & 21 deletions

File tree

catalog/templates/catalog/course.html

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,28 +37,34 @@ <h1 class="d-flex align-items-center gap-2">
3737
{% endif %}
3838
{% if following %}
3939
<turbo-frame id="favorite">
40-
<a href="{% url 'catalog:leave_course' course.slug %}"
41-
class="btn btn-outline-secondary btn-sm d-inline-flex align-items-center gap-1">
42-
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"
43-
class="bi bi-star-fill text-warning hover-spin" viewBox="0 0 16 16">
44-
<path
45-
d="M3.612 15.443c-.386.198-.824-.149-.746-.592l.83-4.73L.173 6.765c-.329-.314-.158-.888.283-.95l4.898-.696L7.538.792c.197-.39.73-.39.927 0l2.184 4.327 4.898.696c.441.062.612.636.282.95l-3.522 3.356.83 4.73c.078.443-.36.79-.746.592L8 13.187l-4.389 2.256z"/>
46-
</svg>
47-
<span>Favori</span>
48-
</a>
40+
<form method="POST" action="{% url 'catalog:leave_course' course.slug %}" class="d-inline">
41+
{% csrf_token %}
42+
<button type="submit"
43+
class="btn btn-outline-secondary btn-sm d-inline-flex align-items-center gap-1">
44+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"
45+
class="bi bi-star-fill text-warning hover-spin" viewBox="0 0 16 16">
46+
<path
47+
d="M3.612 15.443c-.386.198-.824-.149-.746-.592l.83-4.73L.173 6.765c-.329-.314-.158-.888.283-.95l4.898-.696L7.538.792c.197-.39.73-.39.927 0l2.184 4.327 4.898.696c.441.062.612.636.282.95l-3.522 3.356.83 4.73c.078.443-.36.79-.746.592L8 13.187l-4.389 2.256z"/>
48+
</svg>
49+
<span>Favori</span>
50+
</button>
51+
</form>
4952
</turbo-frame>
5053
{% else %}
5154
<turbo-frame id="favorite">
52-
<a href="{% url 'catalog:join_course' course.slug %}"
53-
class="btn btn-outline-secondary btn-sm d-inline-flex align-items-center gap-1">
54-
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"
55-
class="bi bi-star hover-spin"
56-
viewBox="0 0 16 16">
57-
<path
58-
d="M2.866 14.85c-.078.444.36.791.746.593l4.39-2.256 4.389 2.256c.386.198.824-.149.746-.592l-.83-4.73 3.522-3.356c.33-.314.16-.888-.282-.95l-4.898-.696L8.465.792a.513.513 0 0 0-.927 0L5.354 5.12l-4.898.696c-.441.062-.612.636-.283.95l3.523 3.356-.83 4.73zm4.905-2.767-3.686 1.894.694-3.957a.565.565 0 0 0-.163-.505L1.71 6.745l4.052-.576a.525.525 0 0 0 .393-.288L8 2.223l1.847 3.658a.525.525 0 0 0 .393.288l4.052.575-2.906 2.77a.565.565 0 0 0-.163.506l.694 3.957-3.686-1.894a.503.503 0 0 0-.461 0z"/>
59-
</svg>
60-
<span>Ajouter aux favoris</span>
61-
</a>
55+
<form method="POST" action="{% url 'catalog:join_course' course.slug %}" class="d-inline">
56+
{% csrf_token %}
57+
<button type="submit"
58+
class="btn btn-outline-secondary btn-sm d-inline-flex align-items-center gap-1">
59+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"
60+
class="bi bi-star hover-spin"
61+
viewBox="0 0 16 16">
62+
<path
63+
d="M2.866 14.85c-.078.444.36.791.746.593l4.39-2.256 4.389 2.256c.386.198.824-.149.746-.592l-.83-4.73 3.522-3.356c.33-.314.16-.888-.282-.95l-4.898-.696L8.465.792a.513.513 0 0 0-.927 0L5.354 5.12l-4.898.696c-.441.062-.612.636-.283.95l3.523 3.356-.83 4.73zm4.905-2.767-3.686 1.894.694-3.957a.565.565 0 0 0-.163-.505L1.71 6.745l4.052-.576a.525.525 0 0 0 .393-.288L8 2.223l1.847 3.658a.525.525 0 0 0 .393.288l4.052.575-2.906 2.77a.565.565 0 0 0-.163.506l.694 3.957-3.686-1.894a.503.503 0 0 0-.461 0z"/>
64+
</svg>
65+
<span>Ajouter aux favoris</span>
66+
</button>
67+
</form>
6268
</turbo-frame>
6369
{% endif %}
6470
</header>
@@ -78,7 +84,8 @@ <h1 class="d-flex align-items-center gap-2">
7884
>
7985
<a class="btn btn-primary" data-bs-toggle="collapse" href="#collapseExample" role="button"
8086
aria-expanded="false" aria-controls="collapseExample">
81-
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" class="bi bi-funnel"
87+
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor"
88+
class="bi bi-funnel"
8289
viewBox="0 0 16 16">
8390
<path
8491
d="M1.5 1.5A.5.5 0 0 1 2 1h12a.5.5 0 0 1 .5.5v2a.5.5 0 0 1-.128.334L10 8.692V13.5a.5.5 0 0 1-.342.474l-3 1A.5.5 0 0 1 6 14.5V8.692L1.628 3.834A.5.5 0 0 1 1.5 3.5v-2zm1 .5v1.308l4.372 4.858A.5.5 0 0 1 7 8.5v5.306l2-.666V8.5a.5.5 0 0 1 .128-.334L13.5 3.308V2h-11z"/>
@@ -230,7 +237,8 @@ <h1 class="d-flex align-items-center gap-2">
230237
<h4 class="alert-heading">
231238

232239
Rentrée 2023-2024: Nouveaux cours !
233-
<span style="font-size: .5rem;transform: translate(0, -5px);" class="badge rounded-pill bg-danger">
240+
<span style="font-size: .5rem;transform: translate(0, -5px);"
241+
class="badge rounded-pill bg-danger">
234242
NEW
235243
</span>
236244

catalog/views.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from django.http import Http404, HttpRequest, HttpResponse, HttpResponseRedirect
77
from django.shortcuts import get_object_or_404, redirect, render
88
from django.urls import reverse
9+
from django.views.decorators.http import require_POST
910

1011
from catalog.models import Category, Course, CourseUserView
1112
from catalog.slug import normalize_slug
@@ -81,12 +82,14 @@ def set_follow_course(request, slug: str, action: str) -> HttpResponse:
8182

8283
@login_required
8384
@slug_redirect
85+
@require_POST
8486
def join_course(request: HttpRequest, slug: str):
8587
return set_follow_course(request, slug, "follow")
8688

8789

8890
@login_required
8991
@slug_redirect
92+
@require_POST
9093
def leave_course(request: HttpRequest, slug: str):
9194
return set_follow_course(request, slug, "leave")
9295

0 commit comments

Comments
 (0)