Refactor group music management: update removal logic and enhance user feedback in group views
This commit is contained in:
parent
094c5c104d
commit
7ed5cfcb83
3 changed files with 62 additions and 37 deletions
|
@ -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>
|
||||||
<table class="striped">
|
<form method="post">
|
||||||
<thead>
|
{% csrf_token %}
|
||||||
<tr>
|
<table class="striped">
|
||||||
<th>Musique</th>
|
<thead>
|
||||||
<th>ID</th>
|
|
||||||
<th>
|
|
||||||
<i class="ri-history-fill"></i>
|
|
||||||
</th>
|
|
||||||
<th>
|
|
||||||
<i class="ri-delete-bin-fill"></i>
|
|
||||||
</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
{% for music in musics %}
|
|
||||||
<tr>
|
<tr>
|
||||||
<th>{{ music.title }}</th>
|
<th></th>
|
||||||
<td>
|
<th>Musique</th>
|
||||||
<a href="https://youtu.be/{{ music.yt_id }}">{{ music.yt_id }}</a>
|
<th>ID</th>
|
||||||
</td>
|
<th>
|
||||||
<td>
|
<i class="ri-history-fill"></i>
|
||||||
<input type="checkbox" disabled {% if music.blacklisted %}checked{% endif %}
|
</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for music in musics %}
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<input type="checkbox" name="musics" value="{{ music.pk }}">
|
||||||
|
</td>
|
||||||
|
<th>{{ music.title }}</th>
|
||||||
|
<td>
|
||||||
|
<a href="https://youtu.be/{{ music.yt_id }}">{{ music.yt_id }}</a>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<a href="{% url "group_remove_music" pk=music.pk %}"><i class="ri-close-fill" alt="Supprimer"></i></a>
|
<input type="checkbox" disabled {% if music.blacklisted %}checked{% endif %}>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% empty %}
|
{% empty %}
|
||||||
|
@ -148,12 +148,18 @@
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</details>
|
{% if musics %}
|
||||||
<form method="post" action="{% url "group_add_music" pk=group.pk %}">
|
<button type="submit" formaction="{% url "group_remove_music" pk=group.pk %}">
|
||||||
{% csrf_token %}
|
<i class="ri-delete-bin-fill"></i> Supprimer les musiques sélectionnées
|
||||||
<fieldset role="group">
|
</button>
|
||||||
<input type="string" name="yt_id" id="yt_id" placeholder="Musique" required>
|
{% endif %}
|
||||||
<button type="submit">Ajouter</button>
|
|
||||||
</fieldset>
|
|
||||||
</form>
|
</form>
|
||||||
{% endblock content %}
|
</details>
|
||||||
|
<form method="post" action="{% url "group_add_music" pk=group.pk %}">
|
||||||
|
{% csrf_token %}
|
||||||
|
<fieldset role="group">
|
||||||
|
<input type="string" name="yt_id" id="yt_id" placeholder="Musique" required>
|
||||||
|
<button type="submit">Ajouter</button>
|
||||||
|
</fieldset>
|
||||||
|
</form>
|
||||||
|
{% endblock content %}
|
||||||
|
|
|
@ -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",
|
||||||
),
|
),
|
||||||
|
|
|
@ -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)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue