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">
|
||||
<i class="ri-music-2-fill"></i> Liste des musiques
|
||||
</summary>
|
||||
<table class="striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Musique</th>
|
||||
<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 %}
|
||||
<form method="post">
|
||||
{% csrf_token %}
|
||||
<table class="striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{{ music.title }}</th>
|
||||
<td>
|
||||
<a href="https://youtu.be/{{ music.yt_id }}">{{ music.yt_id }}</a>
|
||||
</td>
|
||||
<td>
|
||||
<input type="checkbox" disabled {% if music.blacklisted %}checked{% endif %}
|
||||
<th></th>
|
||||
<th>Musique</th>
|
||||
<th>ID</th>
|
||||
<th>
|
||||
<i class="ri-history-fill"></i>
|
||||
</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>
|
||||
<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>
|
||||
</tr>
|
||||
{% empty %}
|
||||
|
@ -148,12 +148,18 @@
|
|||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</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>
|
||||
{% 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>
|
||||
{% 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",
|
||||
),
|
||||
path(
|
||||
"group/remove_game/<int:pk>/",
|
||||
"group/<int:pk>/remove_game/",
|
||||
views.GroupRemoveGameView.as_view(),
|
||||
name="group_remove_game",
|
||||
),
|
||||
|
|
|
@ -131,13 +131,32 @@ class GroupAddMemberView(OwnerFilterMixin, SingleObjectMixin, View):
|
|||
return redirect(group)
|
||||
|
||||
|
||||
class GroupRemoveMusicView(OwnerFilterMixin, SingleObjectMixin, View):
|
||||
model = models.MusicVideo
|
||||
class GroupRemoveMusicView(MemberFilterMixin, SingleObjectMixin, View):
|
||||
model = models.Group
|
||||
|
||||
def get(self, request, pk):
|
||||
music = self.get_object()
|
||||
group = music.group
|
||||
music.delete()
|
||||
def post(self, request, pk):
|
||||
group = self.get_object()
|
||||
musics = group.musicvideo_set.filter(
|
||||
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)
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue