Compare commits
2 commits
4b331f7968
...
51b44bcec1
Author | SHA1 | Date | |
---|---|---|---|
51b44bcec1 | |||
562bd3d205 |
2 changed files with 20 additions and 1 deletions
|
@ -1,6 +1,10 @@
|
||||||
|
import google.oauth2.credentials
|
||||||
|
import googleapiclient.discovery
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.db.models.functions import Lower
|
from django.db.models.functions import Lower
|
||||||
|
from django.db.models.signals import post_delete
|
||||||
|
from django.dispatch import receiver
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
|
||||||
|
|
||||||
|
@ -53,6 +57,20 @@ class MusikGame(models.Model):
|
||||||
return reverse("game_detail", kwargs={"pk": self.pk})
|
return reverse("game_detail", kwargs={"pk": self.pk})
|
||||||
|
|
||||||
|
|
||||||
|
@receiver(post_delete, sender=MusikGame)
|
||||||
|
def deleteYoutubePlaylist(sender, instance, using, **kwargs):
|
||||||
|
if not instance.playlist:
|
||||||
|
return
|
||||||
|
|
||||||
|
game = instance
|
||||||
|
credentials = google.oauth2.credentials.Credentials(
|
||||||
|
**game.group.owner.youtubecredentials.credentials
|
||||||
|
)
|
||||||
|
yt_api = googleapiclient.discovery.build("youtube", "v3", credentials=credentials)
|
||||||
|
pl_request = yt_api.playlists().delete(id=game.playlist)
|
||||||
|
pl_request.execute()
|
||||||
|
|
||||||
|
|
||||||
class MusicGameOrder(models.Model):
|
class MusicGameOrder(models.Model):
|
||||||
game = models.ForeignKey(MusikGame, on_delete=models.CASCADE)
|
game = models.ForeignKey(MusikGame, on_delete=models.CASCADE)
|
||||||
player = models.ForeignKey(User, on_delete=models.CASCADE)
|
player = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||||
|
|
|
@ -57,7 +57,8 @@
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{% if game.playlist %}
|
{% if game.playlist %}
|
||||||
<a href="{% yt_playlist game %}"><i class="ri-youtube-fill"></i> Playlist</a>
|
<a href="{% yt_playlist game %}"
|
||||||
|
{% if game.playlist_loading %}aria-busy="true"{% endif %}><i class="ri-youtube-fill"></i> Playlist</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
<td>{{ game.players.all|join:", " }}</td>
|
<td>{{ game.players.all|join:", " }}</td>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue