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:
|
||||
image: rabbitmq
|
||||
container_name: musik_rabbitmq
|
||||
restart: unless-stopped
|
||||
|
||||
postgres:
|
||||
image: postgres:17
|
||||
container_name: musik_postgres
|
||||
restart: unless-stopped
|
||||
env_file: stack.env
|
||||
volumes:
|
||||
- /docker/musik/postgres:/var/lib/postgresql/data
|
||||
|
|
|
@ -99,6 +99,9 @@ def generateYoutubePlaylist(sender, instance, created, **kwargs):
|
|||
|
||||
if creds := instance.group.owner.youtubecredentials:
|
||||
tasks.generate_playlist.delay_on_commit(creds.credentials, instance.pk)
|
||||
else:
|
||||
instance.playlist_loading = False
|
||||
instance.save()
|
||||
|
||||
|
||||
@receiver(post_delete, sender=MusikGame)
|
||||
|
@ -118,13 +121,10 @@ class MusicGameOrder(models.Model):
|
|||
value = models.PositiveIntegerField(default=0)
|
||||
|
||||
def update_value(self):
|
||||
n_right = self.musicgameanswer_set.filter(game__player=F("answer")).count()
|
||||
if n_right == 0:
|
||||
self.value = 1000
|
||||
else:
|
||||
self.value = 1000 / (
|
||||
1 + ((n_right - 1) / (self.game.players.count() - 1)) ** 0.5
|
||||
)
|
||||
x = self.musicgameanswer_set.filter(game__player=F("answer")).count()
|
||||
n = self.game.players.count()
|
||||
n = max(3, n)
|
||||
self.value = 1000 * 2 ** (-(x - 2) / (n - 2))
|
||||
self.save()
|
||||
|
||||
class Meta:
|
||||
|
|
|
@ -18,7 +18,7 @@ def generate_playlist(creds, game_pk):
|
|||
"description": "Playlist générée par Musik",
|
||||
},
|
||||
"status": {
|
||||
"privacyStatus": "private",
|
||||
"privacyStatus": "unlisted",
|
||||
},
|
||||
},
|
||||
)
|
||||
|
|
|
@ -21,6 +21,6 @@
|
|||
{% endfor %}
|
||||
</tbody>
|
||||
</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>
|
||||
{% endblock content %}
|
||||
|
|
|
@ -9,31 +9,31 @@
|
|||
{% endif %}
|
||||
{{ musikgame.date }}
|
||||
</h1>
|
||||
{% if musikgame.playlist or musikgame.playlist_loading %}
|
||||
<form method="post">
|
||||
{% csrf_token %}
|
||||
<fieldset role="group">
|
||||
<form method="post">
|
||||
{% csrf_token %}
|
||||
<fieldset role="group">
|
||||
{% if musikgame.playlist or musikgame.playlist_loading %}
|
||||
<a target="_blank"
|
||||
href="{% yt_playlist musikgame %}"
|
||||
role="button"
|
||||
{% if musikgame.playlist_loading %}aria-busy="true"{% endif %}><i class="ri-youtube-fill"></i> Playlist</a>
|
||||
{% if musikgame.over %}
|
||||
<a href="{% url "game_answer" musikgame.pk %}"
|
||||
role="button"
|
||||
class="secondary"><i class="ri-play-list-2-fill"></i> Mes réponses</a>
|
||||
{% else %}
|
||||
<a href="{% url "game_answer" musikgame.pk %}" role="button"><i class="ri-play-list-2-fill"></i> Répondre</a>
|
||||
{% endif %}
|
||||
</fieldset>
|
||||
{% if is_leader and not musikgame.over %}
|
||||
<fieldset>
|
||||
<button type="submit" formaction="{% url "game_end" musikgame.pk %}">
|
||||
<i class="ri-stop-circle-fill"></i> Finir la partie
|
||||
</button>
|
||||
</fieldset>
|
||||
{% endif %}
|
||||
</form>
|
||||
{% endif %}
|
||||
{% if musikgame.over %}
|
||||
<a href="{% url "game_answer" musikgame.pk %}"
|
||||
role="button"
|
||||
class="secondary"><i class="ri-play-list-2-fill"></i> Mes réponses</a>
|
||||
{% else %}
|
||||
<a href="{% url "game_answer" musikgame.pk %}" role="button"><i class="ri-play-list-2-fill"></i> Répondre</a>
|
||||
{% endif %}
|
||||
</fieldset>
|
||||
{% if is_leader and not musikgame.over %}
|
||||
<fieldset>
|
||||
<button type="submit" formaction="{% url "game_end" musikgame.pk %}">
|
||||
<i class="ri-stop-circle-fill"></i> Finir la partie
|
||||
</button>
|
||||
</fieldset>
|
||||
{% endif %}
|
||||
</form>
|
||||
<h2>
|
||||
<i class="ri-group-2-fill"></i> Joueurs
|
||||
</h2>
|
||||
|
|
|
@ -5,10 +5,12 @@
|
|||
<i class="ri-group-2-fill"></i> {{ group.name }}
|
||||
</h1>
|
||||
<p>
|
||||
{% if not user.youtubecredentials.credentials %}
|
||||
<a href="{% url "youtube_login" %}" role="button"><i class="ri-youtube-fill"></i> Me connecter au compte Youtube</a>
|
||||
{% if group.owner.youtubecredentials.credentials %}
|
||||
<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 %}
|
||||
<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 %}
|
||||
</p>
|
||||
{% form form %}
|
||||
|
|
|
@ -327,15 +327,12 @@ class GameCreateView(LoginRequiredMixin, CreateView):
|
|||
pm_list = list(zip(players, musics))
|
||||
random.shuffle(pm_list)
|
||||
for (player, music), order in zip(pm_list, range(1, len(pm_list) + 1)):
|
||||
music.blacklisted = True
|
||||
music.save()
|
||||
models.MusicGameOrder.objects.create(
|
||||
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.save()
|
||||
form.instance.playlist_loading = True
|
||||
form.instance.save()
|
||||
return res
|
||||
|
||||
|
||||
|
@ -481,6 +478,9 @@ class GameEndView(LoginRequiredMixin, SingleObjectMixin, View):
|
|||
if not game.group.is_leader(request.user):
|
||||
raise PermissionDenied()
|
||||
game.over = True
|
||||
models.MusicVideo.objects.filter(musicgameorder__game=game).update(
|
||||
blacklisted=True
|
||||
)
|
||||
|
||||
for go in game.musicgameorder_set.all():
|
||||
go.update_value()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue