Refactor group music management: update removal logic and enhance user feedback in group views

This commit is contained in:
Edgar P. Burkhart 2025-06-14 12:09:07 +02:00
parent 094c5c104d
commit 7ed5cfcb83
Signed by: edpibu
GPG key ID: 9833D3C5A25BD227
3 changed files with 62 additions and 37 deletions

View file

@ -114,31 +114,31 @@
<summary role="button"> <summary role="button">
<i class="ri-music-2-fill"></i> Liste des musiques <i class="ri-music-2-fill"></i> Liste des musiques
</summary> </summary>
<form method="post">
{% csrf_token %}
<table class="striped"> <table class="striped">
<thead> <thead>
<tr> <tr>
<th></th>
<th>Musique</th> <th>Musique</th>
<th>ID</th> <th>ID</th>
<th> <th>
<i class="ri-history-fill"></i> <i class="ri-history-fill"></i>
</th> </th>
<th>
<i class="ri-delete-bin-fill"></i>
</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{% for music in musics %} {% for music in musics %}
<tr> <tr>
<td>
<input type="checkbox" name="musics" value="{{ music.pk }}">
</td>
<th>{{ music.title }}</th> <th>{{ music.title }}</th>
<td> <td>
<a href="https://youtu.be/{{ music.yt_id }}">{{ music.yt_id }}</a> <a href="https://youtu.be/{{ music.yt_id }}">{{ music.yt_id }}</a>
</td> </td>
<td> <td>
<input type="checkbox" disabled {% if music.blacklisted %}checked{% endif %} <input type="checkbox" disabled {% if music.blacklisted %}checked{% endif %}>
</td>
<td>
<a href="{% url "group_remove_music" pk=music.pk %}"><i class="ri-close-fill" alt="Supprimer"></i></a>
</td> </td>
</tr> </tr>
{% empty %} {% empty %}
@ -148,6 +148,12 @@
{% endfor %} {% endfor %}
</tbody> </tbody>
</table> </table>
{% if musics %}
<button type="submit" formaction="{% url "group_remove_music" pk=group.pk %}">
<i class="ri-delete-bin-fill"></i> Supprimer les musiques sélectionnées
</button>
{% endif %}
</form>
</details> </details>
<form method="post" action="{% url "group_add_music" pk=group.pk %}"> <form method="post" action="{% url "group_add_music" pk=group.pk %}">
{% csrf_token %} {% csrf_token %}

View file

@ -27,7 +27,7 @@ urlpatterns = [
name="group_remove_music", name="group_remove_music",
), ),
path( path(
"group/remove_game/<int:pk>/", "group/<int:pk>/remove_game/",
views.GroupRemoveGameView.as_view(), views.GroupRemoveGameView.as_view(),
name="group_remove_game", name="group_remove_game",
), ),

View file

@ -131,13 +131,32 @@ class GroupAddMemberView(OwnerFilterMixin, SingleObjectMixin, View):
return redirect(group) return redirect(group)
class GroupRemoveMusicView(OwnerFilterMixin, SingleObjectMixin, View): class GroupRemoveMusicView(MemberFilterMixin, SingleObjectMixin, View):
model = models.MusicVideo model = models.Group
def get(self, request, pk): def post(self, request, pk):
music = self.get_object() group = self.get_object()
group = music.group musics = group.musicvideo_set.filter(
music.delete() owner=request.user, pk__in=request.POST.getlist("musics")
)
if musics.count() == 0:
messages.add_message(request, messages.INFO, "Aucune musique supprimée.")
return redirect(group)
if musics.count() != len(request.POST.getlist("musics")):
messages.add_message(
request,
messages.WARNING,
"Certaines musiques n'ont pas pu être supprimées.",
)
musics.delete()
else:
musics.delete()
messages.add_message(
request,
messages.SUCCESS,
"Les musiques sélectionnées ont été supprimées.",
)
return redirect(group) return redirect(group)