Compare commits
7 commits
98183575af
...
84c432c325
Author | SHA1 | Date | |
---|---|---|---|
84c432c325 | |||
c639307cfb | |||
951128147c | |||
0b8ce65a0a | |||
22bb6931e8 | |||
cb3518a5e5 | |||
e6d757c069 |
7 changed files with 41 additions and 37 deletions
|
@ -32,10 +32,12 @@ services:
|
||||||
rabbitmq:
|
rabbitmq:
|
||||||
image: rabbitmq
|
image: rabbitmq
|
||||||
container_name: musik_rabbitmq
|
container_name: musik_rabbitmq
|
||||||
|
restart: unless-stopped
|
||||||
|
|
||||||
postgres:
|
postgres:
|
||||||
image: postgres:17
|
image: postgres:17
|
||||||
container_name: musik_postgres
|
container_name: musik_postgres
|
||||||
|
restart: unless-stopped
|
||||||
env_file: stack.env
|
env_file: stack.env
|
||||||
volumes:
|
volumes:
|
||||||
- /docker/musik/postgres:/var/lib/postgresql/data
|
- /docker/musik/postgres:/var/lib/postgresql/data
|
||||||
|
|
|
@ -99,6 +99,9 @@ def generateYoutubePlaylist(sender, instance, created, **kwargs):
|
||||||
|
|
||||||
if creds := instance.group.owner.youtubecredentials:
|
if creds := instance.group.owner.youtubecredentials:
|
||||||
tasks.generate_playlist.delay_on_commit(creds.credentials, instance.pk)
|
tasks.generate_playlist.delay_on_commit(creds.credentials, instance.pk)
|
||||||
|
else:
|
||||||
|
instance.playlist_loading = False
|
||||||
|
instance.save()
|
||||||
|
|
||||||
|
|
||||||
@receiver(post_delete, sender=MusikGame)
|
@receiver(post_delete, sender=MusikGame)
|
||||||
|
@ -118,13 +121,10 @@ class MusicGameOrder(models.Model):
|
||||||
value = models.PositiveIntegerField(default=0)
|
value = models.PositiveIntegerField(default=0)
|
||||||
|
|
||||||
def update_value(self):
|
def update_value(self):
|
||||||
n_right = self.musicgameanswer_set.filter(game__player=F("answer")).count()
|
x = self.musicgameanswer_set.filter(game__player=F("answer")).count()
|
||||||
if n_right == 0:
|
n = self.game.players.count()
|
||||||
self.value = 1000
|
n = max(3, n)
|
||||||
else:
|
self.value = 1000 * 2 ** (-(x - 2) / (n - 2))
|
||||||
self.value = 1000 / (
|
|
||||||
1 + ((n_right - 1) / (self.game.players.count() - 1)) ** 0.5
|
|
||||||
)
|
|
||||||
self.save()
|
self.save()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
|
@ -18,7 +18,7 @@ def generate_playlist(creds, game_pk):
|
||||||
"description": "Playlist générée par Musik",
|
"description": "Playlist générée par Musik",
|
||||||
},
|
},
|
||||||
"status": {
|
"status": {
|
||||||
"privacyStatus": "private",
|
"privacyStatus": "unlisted",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
|
@ -21,6 +21,6 @@
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
{% if not musikgame.over %}<button type="submit">Valider mes réponses</button>{% endif %}
|
{% if not musikgame.over %}<button type="submit">Sauvegarder mes réponses</button>{% endif %}
|
||||||
</form>
|
</form>
|
||||||
{% endblock content %}
|
{% endblock content %}
|
||||||
|
|
|
@ -9,14 +9,15 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{{ musikgame.date }}
|
{{ musikgame.date }}
|
||||||
</h1>
|
</h1>
|
||||||
{% if musikgame.playlist or musikgame.playlist_loading %}
|
|
||||||
<form method="post">
|
<form method="post">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<fieldset role="group">
|
<fieldset role="group">
|
||||||
|
{% if musikgame.playlist or musikgame.playlist_loading %}
|
||||||
<a target="_blank"
|
<a target="_blank"
|
||||||
href="{% yt_playlist musikgame %}"
|
href="{% yt_playlist musikgame %}"
|
||||||
role="button"
|
role="button"
|
||||||
{% if musikgame.playlist_loading %}aria-busy="true"{% endif %}><i class="ri-youtube-fill"></i> Playlist</a>
|
{% if musikgame.playlist_loading %}aria-busy="true"{% endif %}><i class="ri-youtube-fill"></i> Playlist</a>
|
||||||
|
{% endif %}
|
||||||
{% if musikgame.over %}
|
{% if musikgame.over %}
|
||||||
<a href="{% url "game_answer" musikgame.pk %}"
|
<a href="{% url "game_answer" musikgame.pk %}"
|
||||||
role="button"
|
role="button"
|
||||||
|
@ -33,7 +34,6 @@
|
||||||
</fieldset>
|
</fieldset>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</form>
|
</form>
|
||||||
{% endif %}
|
|
||||||
<h2>
|
<h2>
|
||||||
<i class="ri-group-2-fill"></i> Joueurs
|
<i class="ri-group-2-fill"></i> Joueurs
|
||||||
</h2>
|
</h2>
|
||||||
|
|
|
@ -5,10 +5,12 @@
|
||||||
<i class="ri-group-2-fill"></i> {{ group.name }}
|
<i class="ri-group-2-fill"></i> {{ group.name }}
|
||||||
</h1>
|
</h1>
|
||||||
<p>
|
<p>
|
||||||
{% if not user.youtubecredentials.credentials %}
|
{% if group.owner.youtubecredentials.credentials %}
|
||||||
<a href="{% url "youtube_login" %}" role="button"><i class="ri-youtube-fill"></i> Me connecter au compte Youtube</a>
|
<i class="ri-youtube-fill"></i> Une playlist sera générée automatiquement sur le compte Youtube de <strong>{{ group.owner }}</strong> (<strong>{{ group.owner.youtubecredentials.title }}</strong>).
|
||||||
|
{% elif user == group.owner %}
|
||||||
|
<a href="{% url "youtube_login" %}" role="button"><i class="ri-youtube-fill"></i> Connecter mon compte Youtube</a>
|
||||||
{% else %}
|
{% else %}
|
||||||
<i class="ri-youtube-fill"></i> Une playlist sera générée automatiquement sur le compte Youtube <strong>{{ user.youtubecredentials.title }}</strong>.
|
<small>Aucune playlist Youtube ne sera générée car <strong>{{ group.owner }}</strong> n'a pas lié son compte Youtube.</small>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</p>
|
</p>
|
||||||
{% form form %}
|
{% form form %}
|
||||||
|
|
|
@ -327,13 +327,10 @@ class GameCreateView(LoginRequiredMixin, CreateView):
|
||||||
pm_list = list(zip(players, musics))
|
pm_list = list(zip(players, musics))
|
||||||
random.shuffle(pm_list)
|
random.shuffle(pm_list)
|
||||||
for (player, music), order in zip(pm_list, range(1, len(pm_list) + 1)):
|
for (player, music), order in zip(pm_list, range(1, len(pm_list) + 1)):
|
||||||
music.blacklisted = True
|
|
||||||
music.save()
|
|
||||||
models.MusicGameOrder.objects.create(
|
models.MusicGameOrder.objects.create(
|
||||||
game=form.instance, player=player, music_video=music, order=order
|
game=form.instance, player=player, music_video=music, order=order
|
||||||
)
|
)
|
||||||
|
|
||||||
if models.YoutubeCredentials.objects.filter(user=self.request.user).exists():
|
|
||||||
form.instance.playlist_loading = True
|
form.instance.playlist_loading = True
|
||||||
form.instance.save()
|
form.instance.save()
|
||||||
return res
|
return res
|
||||||
|
@ -481,6 +478,9 @@ class GameEndView(LoginRequiredMixin, SingleObjectMixin, View):
|
||||||
if not game.group.is_leader(request.user):
|
if not game.group.is_leader(request.user):
|
||||||
raise PermissionDenied()
|
raise PermissionDenied()
|
||||||
game.over = True
|
game.over = True
|
||||||
|
models.MusicVideo.objects.filter(musicgameorder__game=game).update(
|
||||||
|
blacklisted=True
|
||||||
|
)
|
||||||
|
|
||||||
for go in game.musicgameorder_set.all():
|
for go in game.musicgameorder_set.all():
|
||||||
go.update_value()
|
go.update_value()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue