Compare commits
45 commits
Author | SHA1 | Date | |
---|---|---|---|
8c2e62e8de | |||
e4168b474d | |||
b20eee8cfb | |||
a462fabde4 | |||
b9711cbe9c | |||
bd8529cd01 | |||
84c432c325 | |||
c639307cfb | |||
951128147c | |||
0b8ce65a0a | |||
22bb6931e8 | |||
cb3518a5e5 | |||
e6d757c069 | |||
98183575af | |||
c7b907f115 | |||
b30ee77132 | |||
cc38d72df8 | |||
486f650ea6 | |||
302b884b23 | |||
993ed8963c | |||
2278345f32 | |||
e039889488 | |||
92abcb584c | |||
178a7cab03 | |||
3d585e1e14 | |||
303538bf48 | |||
b1ec960dfa | |||
33896916e6 | |||
f9ed70d386 | |||
d03d3b48d4 | |||
6dbb1a54e0 | |||
2478ec95e8 | |||
8faff47696 | |||
cd0ca2f5ea | |||
da1c750771 | |||
a24fb897a3 | |||
7259046916 | |||
83404e2ed5 | |||
f36fe8ea84 | |||
28203bd630 | |||
da29634e57 | |||
aafb7817c2 | |||
c73ff2f167 | |||
088bb52c07 | |||
f3e914aed8 |
54 changed files with 1218 additions and 282 deletions
|
@ -17,7 +17,7 @@ form a[role="button"] {
|
|||
width: 100%;
|
||||
}
|
||||
|
||||
i.owner {
|
||||
i.owner, .gold {
|
||||
color: var(--pico-color-amber-200);
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,7 @@ i.owner {
|
|||
display: none;
|
||||
}
|
||||
|
||||
a.group {
|
||||
a.group, a.running {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
|
@ -77,11 +77,6 @@ article.message {
|
|||
}
|
||||
|
||||
#hero {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: radial-gradient(
|
||||
circle 50vh at calc(100vw - 4rem) 50%,
|
||||
var(--pico-primary-background),
|
||||
|
@ -90,19 +85,41 @@ article.message {
|
|||
color-mix(in hsl, var(--pico-primary-background) 30%, var(--pico-background-color)) 60%,
|
||||
color-mix(in hsl, var(--pico-primary-background) 10%, var(--pico-background-color)) 80%,
|
||||
var(--pico-background-color));
|
||||
display: grid;
|
||||
grid-template-rows: 1fr min-content;
|
||||
align-items: center;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
height: 100%;
|
||||
overflow-y: auto;
|
||||
padding: 4rem;
|
||||
|
||||
.big-logo {
|
||||
font-size: 8rem;
|
||||
main {
|
||||
display: contents;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 4rem;
|
||||
section {
|
||||
max-width: 20rem;
|
||||
}
|
||||
}
|
||||
.full-page {
|
||||
height: 100%;
|
||||
display: grid;
|
||||
grid-template-rows: 1fr;
|
||||
align-items: center;
|
||||
margin-bottom: 4rem;
|
||||
|
||||
&.r {
|
||||
-ms-grid-column-align: end;
|
||||
}
|
||||
.big-logo {
|
||||
font-size: 8rem;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 4rem;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
h1,
|
||||
h2,
|
||||
|
@ -117,6 +134,9 @@ h6,
|
|||
i.i {
|
||||
margin-right: .5em;
|
||||
}
|
||||
i.hl, .me {
|
||||
color: var(--pico-primary);
|
||||
}
|
||||
|
||||
footer {
|
||||
text-align: center;
|
||||
|
@ -130,3 +150,75 @@ td.c, th.c {
|
|||
margin: 0;
|
||||
}
|
||||
}
|
||||
|
||||
table select {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.podium {
|
||||
> :first-child {
|
||||
font-weight: 900;
|
||||
font-size: 1.25em;
|
||||
&::marker {
|
||||
color: var(--pico-color-amber-200);
|
||||
}
|
||||
}
|
||||
> :nth-child(2) {
|
||||
font-weight: 800;
|
||||
font-size: 1.1em;
|
||||
&::marker {
|
||||
color: var(--pico-color-grey-300);
|
||||
}
|
||||
}
|
||||
> :nth-child(3) {
|
||||
font-weight: 600;
|
||||
font-size: 1.1em;
|
||||
&::marker {
|
||||
color: var(--pico-color-sand-300);
|
||||
}
|
||||
}
|
||||
.score {
|
||||
margin-left: .5em;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
.score {
|
||||
font-weight: 900;
|
||||
color: var(--pico-color-zinc-500);
|
||||
}
|
||||
.correct {
|
||||
.score, i {
|
||||
color: var(--pico-color-lime-200);}
|
||||
}
|
||||
.wrong {
|
||||
.score, i {
|
||||
color: var(--pico-color-red-500);}
|
||||
}
|
||||
|
||||
table.results, table.musics {
|
||||
white-space: nowrap;
|
||||
}
|
||||
.sc i {
|
||||
margin-right: .5em;
|
||||
}
|
||||
|
||||
@media (width < 576px) {
|
||||
[role="group"] {
|
||||
display: grid;
|
||||
& > :first-child {
|
||||
border-radius: var(--pico-border-radius) var(--pico-border-radius) 0 0 !important;
|
||||
}
|
||||
& > :not(:first-child) {
|
||||
margin-left: 0 !important;
|
||||
margin-top: calc(var(--pico-border-width) * -1);
|
||||
}
|
||||
& > :last-child {
|
||||
border-radius: 0 0 var(--pico-border-radius) var(--pico-border-radius) !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.brand-name {
|
||||
color: var(--pico-primary);
|
||||
}
|
||||
|
|
BIN
base/static/favicon/apple-touch-icon.png
Normal file
BIN
base/static/favicon/apple-touch-icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.9 KiB |
BIN
base/static/favicon/favicon-96x96.png
Normal file
BIN
base/static/favicon/favicon-96x96.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.6 KiB |
BIN
base/static/favicon/favicon.ico
Normal file
BIN
base/static/favicon/favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 15 KiB |
25
base/static/favicon/favicon.svg
Normal file
25
base/static/favicon/favicon.svg
Normal file
|
@ -0,0 +1,25 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg width="256" height="256" version="1.1"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<defs>
|
||||
<linearGradient id="Gradient" x1="0" x2="0" y1="0" y2="1">
|
||||
<stop offset="0%" style="stop-color:#AA40BF;stop-opacity:1" />
|
||||
<stop offset="100%" style="stop-color:#AA40BF;stop-opacity:1" />
|
||||
</linearGradient>
|
||||
<filter id="alpha-to-white">
|
||||
<feColorMatrix in="SourceGraphic" type="matrix"
|
||||
values="0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 1 0"/>
|
||||
</filter>
|
||||
<g id="child-svg"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" height="16px" width="16px"><path d="M18.7134 8.12811L18.4668 8.69379C18.2864 9.10792 17.7136 9.10792 17.5331 8.69379L17.2866 8.12811C16.8471 7.11947 16.0555 6.31641 15.0677 5.87708L14.308 5.53922C13.8973 5.35653 13.8973 4.75881 14.308 4.57612L15.0252 4.25714C16.0384 3.80651 16.8442 2.97373 17.2761 1.93083L17.5293 1.31953C17.7058 0.893489 18.2942 0.893489 18.4706 1.31953L18.7238 1.93083C19.1558 2.97373 19.9616 3.80651 20.9748 4.25714L21.6919 4.57612C22.1027 4.75881 22.1027 5.35653 21.6919 5.53922L20.9323 5.87708C19.9445 6.31641 19.1529 7.11947 18.7134 8.12811ZM7 3H12V6H9V17C9 19.2091 7.20914 21 5 21C2.79086 21 1 19.2091 1 17C1 14.7909 2.79086 13 5 13C5.72857 13 6.41165 13.1948 7 13.5351V3ZM18 13.5351V11H20V17C20 19.2091 18.2091 21 16 21C13.7909 21 12 19.2091 12 17C12 14.7909 13.7909 13 16 13C16.7286 13 17.4117 13.1948 18 13.5351Z" /></svg></g>
|
||||
</defs>
|
||||
<rect
|
||||
width="256"
|
||||
height="256"
|
||||
fill="url(#Gradient)"
|
||||
ry="128"
|
||||
x="0"
|
||||
y="0" />
|
||||
<use xlink:href="#child-svg" filter="url(#alpha-to-white)"
|
||||
transform="matrix(8,0,0,8,64,64)" />
|
||||
</svg>
|
After Width: | Height: | Size: 1.7 KiB |
21
base/static/favicon/site.webmanifest
Normal file
21
base/static/favicon/site.webmanifest
Normal file
|
@ -0,0 +1,21 @@
|
|||
{
|
||||
"name": "MyWebSite",
|
||||
"short_name": "MySite",
|
||||
"icons": [
|
||||
{
|
||||
"src": "/web-app-manifest-192x192.png",
|
||||
"sizes": "192x192",
|
||||
"type": "image/png",
|
||||
"purpose": "maskable"
|
||||
},
|
||||
{
|
||||
"src": "/web-app-manifest-512x512.png",
|
||||
"sizes": "512x512",
|
||||
"type": "image/png",
|
||||
"purpose": "maskable"
|
||||
}
|
||||
],
|
||||
"theme_color": "#aa40bf",
|
||||
"background_color": "#ffffff",
|
||||
"display": "standalone"
|
||||
}
|
BIN
base/static/favicon/web-app-manifest-192x192.png
Normal file
BIN
base/static/favicon/web-app-manifest-192x192.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.4 KiB |
BIN
base/static/favicon/web-app-manifest-512x512.png
Normal file
BIN
base/static/favicon/web-app-manifest-512x512.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 47 KiB |
25
base/templates/auth/user_confirm_delete.html
Normal file
25
base/templates/auth/user_confirm_delete.html
Normal file
|
@ -0,0 +1,25 @@
|
|||
{% extends "base.html" %}
|
||||
{% block content %}
|
||||
<dialog open>
|
||||
<article>
|
||||
<header>
|
||||
<p>
|
||||
<i class="ri-user-fill"></i> {{ user.username }}
|
||||
</p>
|
||||
</header>
|
||||
<p>
|
||||
Confirmer la supression du compte <strong>{{ user.username }}</strong> ?
|
||||
</p>
|
||||
<p>
|
||||
<small>Toute suppression est immédiate et définitive. La suppression du compte entraîne la suppression des groupes dont celui-ci est propriétaire.</small>
|
||||
</p>
|
||||
<form method="post">
|
||||
{% csrf_token %}
|
||||
<button type="submit">
|
||||
<i class="ri-delete-bin-fill"></i> Confirmer
|
||||
</button>
|
||||
<a href="{% url "account_settings" %}" role="button" class="secondary"><i class="ri-close-line"></i> Annuler</a>
|
||||
</form>
|
||||
</article>
|
||||
</dialog>
|
||||
{% endblock content %}
|
|
@ -1,6 +1,24 @@
|
|||
{% extends "base.html" %}
|
||||
{% load form %}
|
||||
{% block content %}
|
||||
<h1>Créer un compte</h1>
|
||||
{% form form %}
|
||||
{% endblock content %}
|
||||
<h1>Créer mon compte</h1>
|
||||
{% for error in form.non_field_errors %}<article class="message error">{{ error }}</article>{% endfor %}
|
||||
<form method="post" {% if action %}action="{% url action %}"{% endif %}>
|
||||
{% csrf_token %}
|
||||
<fieldset>
|
||||
{% for field in form %}
|
||||
<label for="{{ field.id_for_label }}">
|
||||
{{ field.label }}
|
||||
{{ field }}
|
||||
{% if field.errors %}
|
||||
<small id="{{ field.errors.field_id }}_error" class="form-error">{{ field.errors|join:", " }}</small>
|
||||
{% endif %}
|
||||
</label>
|
||||
{% endfor %}
|
||||
</fieldset>
|
||||
<button type="submit">Créer mon compte</button>
|
||||
<fieldset>
|
||||
<a href="{% url "login" %}" role="button" class="secondary">J'ai déjà un compte</a>
|
||||
</fieldset>
|
||||
</form>
|
||||
{% endblock content %}
|
||||
|
|
45
base/templates/auth/user_settings.html
Normal file
45
base/templates/auth/user_settings.html
Normal file
|
@ -0,0 +1,45 @@
|
|||
{% extends "base.html" %}
|
||||
{% load form %}
|
||||
{% block content %}
|
||||
<h1>
|
||||
<i class="ri-user-settings-fill"></i> Mon compte
|
||||
</h1>
|
||||
{% for error in form.non_field_errors %}<article class="message error">{{ error }}</article>{% endfor %}
|
||||
<form method="post" {% if action %}action="{% url action %}"{% endif %}>
|
||||
{% csrf_token %}
|
||||
<fieldset>
|
||||
<button type="submit" formaction="{% url "logout" %}" class="secondary">
|
||||
<i class="ri-logout-box-r-fill"></i> Me déconnecter
|
||||
</button>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
{% if not user.youtubecredentials.credentials %}
|
||||
<a href="{% url "youtube_login" %}" role="button"><i class="ri-youtube-fill"></i> Me connecter au compte Youtube</a>
|
||||
{% else %}
|
||||
<button type="submit"
|
||||
formaction="{% url "youtube_logout" %}"
|
||||
class="secondary">
|
||||
<i class="ri-youtube-fill"></i> Déconnecter le compte Youtube <strong>{{ user.youtubecredentials.title }}</strong>
|
||||
</button>
|
||||
{% endif %}
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
{% for field in form %}
|
||||
<label for="{{ field.id_for_label }}">
|
||||
{{ field.label }}
|
||||
{{ field }}
|
||||
{% if field.errors %}
|
||||
<small id="{{ field.errors.field_id }}_error" class="form-error">{{ field.errors|join:", " }}</small>
|
||||
{% endif %}
|
||||
</label>
|
||||
{% endfor %}
|
||||
<button type="submit">Mettre à jour mon compte</button>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<a href="{% url "password_change" %}" role="button" class="secondary">Changer mon mot de passe</a>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<a href="{% url "account_delete" %}" role="button" class="contrast">Supprimer mon compte</a>
|
||||
</fieldset>
|
||||
</form>
|
||||
{% endblock content %}
|
|
@ -11,7 +11,7 @@
|
|||
Musik
|
||||
{% endblock title %}
|
||||
</title>
|
||||
<link rel="icon" href="{% static "logo.svg" %}">
|
||||
{% include "favicon.html" %}
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Exo:ital,wght@0,100..900;1,100..900&display=swap"
|
||||
|
@ -47,16 +47,8 @@
|
|||
<nav>
|
||||
<ul>
|
||||
{% if user.is_authenticated %}
|
||||
<li>{{ user.username }}</li>
|
||||
<li>
|
||||
<form action="{% url 'logout' %}" method="post">
|
||||
{% csrf_token %}
|
||||
<input type="submit" value="Se déconnecter" class="logout">
|
||||
</form>
|
||||
</li>
|
||||
{% else %}
|
||||
<li>
|
||||
<a href="{% url 'login' %}" role="button">Se connecter <i class="ri-login-box-fill"></i></a>
|
||||
<a href="{% url "account_settings" %}"><i class="ri-user-fill" alt="Compte"></i> {{ user.username }}</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
|
|
11
base/templates/base/inline_form.html
Normal file
11
base/templates/base/inline_form.html
Normal file
|
@ -0,0 +1,11 @@
|
|||
{% for error in form.non_field_errors %}<article class="message error">{{ error }}</article>{% endfor %}
|
||||
<form method="post" {% if action %}action="{% url action %}"{% endif %}>
|
||||
{% csrf_token %}
|
||||
<fieldset role="group">
|
||||
{% for field in form %}{{ field }}{% endfor %}
|
||||
<input type="submit" {% if submit %}value="{{ submit }}"{% endif %}>
|
||||
{% if field.errors %}
|
||||
<small id="{{ field.errors.field_id }}_error" class="form-error">{{ field.errors|join:", " }}</small>
|
||||
{% endif %}
|
||||
</fieldset>
|
||||
</form>
|
8
base/templates/favicon.html
Normal file
8
base/templates/favicon.html
Normal file
|
@ -0,0 +1,8 @@
|
|||
{% load static %}
|
||||
<meta name="theme-color" content="#aa40bf">
|
||||
<link rel="icon" type="image/png" href="{% static "favicon/favicon-96x96.png" %}" sizes="96x96">
|
||||
<link rel="icon" type="image/svg+xml" href="{% static "favicon/favicon.svg" %}">
|
||||
<link rel="shortcut icon" href="{% static "favicon/favicon.ico" %}">
|
||||
<link rel="apple-touch-icon" sizes="180x180" href="{% static "favicon/apple-touch-icon.png" %}">
|
||||
<meta name="apple-mobile-web-app-title" content="Musik">
|
||||
<link rel="manifest" href="{% static "favicon/site.webmanifest" %}">
|
|
@ -1 +1 @@
|
|||
© <a href="https://edgarpierre.fr">Edgar P. Burkhart</a> – <a href="{% url "legal" %}">Mentions légales</a>
|
||||
Musik {{ VERSION }} – © <a href="https://code.edgarpierre.fr/edpibu/musik">Edgar P. Burkhart</a> – <a href="{% url "legal" %}">Mentions légales et confidentialité</a>
|
||||
|
|
|
@ -1,11 +1,25 @@
|
|||
{% load static %}
|
||||
<div id="hero">
|
||||
<main>
|
||||
<i class="ri-music-ai-fill big-logo"></i>
|
||||
<h1>Musik</h1>
|
||||
<p>
|
||||
<a href="{% url "login" %}" role="button"><i class="ri-play-fill"></i> Jouer</a>
|
||||
</p>
|
||||
<div class="full-page">
|
||||
<div>
|
||||
<i class="ri-music-ai-fill big-logo"></i>
|
||||
<h1>Musik</h1>
|
||||
<p>
|
||||
<a href="{% url "home" %}" role="button"><i class="ri-play-fill"></i> Jouer</a>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="full-page r">
|
||||
<section>
|
||||
<h2>
|
||||
<span class="brand-name"><i class="ri-music-ai-fill"></i> Musik</span> Le jeu où ta playlist devient ton arme secrète !
|
||||
</h2>
|
||||
<p>
|
||||
Invite ta bande, ajoute tes sons fétiches, et c’est parti ! Une playlist Youtube apparaît, mélangeant les coups de cœur de tout le monde. Le jeu ? Écoute, devine qui a choisi quoi, et découvre les secrets musicaux de tes potes. Entre pièges, révélations et fous rires, Musik c’est le jeu parfait pour tester vos oreilles… et vos amitiés. Prêt à jouer le DJ incognito ?
|
||||
</p>
|
||||
</section>
|
||||
</div>
|
||||
</main>
|
||||
<footer>
|
||||
{% include "footer.html" %}
|
||||
|
|
|
@ -1,11 +1,4 @@
|
|||
{% extends "base.html" %}
|
||||
{% block content %}
|
||||
{% include "game/home.html" %}
|
||||
{% endblock content %}
|
||||
{% block body %}
|
||||
{% if user.is_authenticated %}
|
||||
{{ block.super }}
|
||||
{% else %}
|
||||
{% include "hero.html" %}
|
||||
{% endif %}
|
||||
{% include "hero.html" %}
|
||||
{% endblock body %}
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
Youtube est une marque de Google LLC.
|
||||
</p>
|
||||
<p>
|
||||
La suppression des données stockée par le service Musik pour son utilisation peut être demandée par email à <a href="mailto:contact@edgarpierre.fr">Edgar P. Burkhart</a>.
|
||||
Les données saisies dans Musik (groupes créés, listes de musiques) sont conservées jusqu'à demande de suppression. La suppression du compte entraîne la suppression de l'ensemble des données qui y sont liées.
|
||||
La suppression du compte peut être demandée dans les paramètres du compte. La suppression des données est immédiate et définitive.
|
||||
</p>
|
||||
{% endblock content %}
|
||||
|
|
|
@ -1,9 +1,30 @@
|
|||
{% extends "base.html" %}
|
||||
{% load form %}
|
||||
{% block content %}
|
||||
<h1>Connexion</h1>
|
||||
<p>
|
||||
<a href="{% url "signup" %}">Créer un compte</a>
|
||||
</p>
|
||||
{% form form submit="Se connecter" %}
|
||||
{% endblock content %}
|
||||
{% for error in form.non_field_errors %}<article class="message error">{{ error }}</article>{% endfor %}
|
||||
<form method="post" {% if action %}action="{% url action %}"{% endif %}>
|
||||
{% csrf_token %}
|
||||
{% for field in form %}
|
||||
{% if field.id_for_label %}
|
||||
<label for="{{ field.id_for_label }}">
|
||||
{{ field.label }}
|
||||
{% else %}
|
||||
<legend>{{ field.label }}</legend>
|
||||
{% endif %}
|
||||
{{ field }}
|
||||
{% if field.errors %}
|
||||
<small id="{{ field.errors.field_id }}_error" class="form-error">{{ field.errors|join:", " }}</small>
|
||||
{% endif %}
|
||||
</label>
|
||||
{% endfor %}
|
||||
<button type="submit">Me connecter</button>
|
||||
<fieldset>
|
||||
<a href="{% url "signup" %}" role="button" class="secondary">Créer mon compte</a>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<a href="{% url "password_reset" %}"
|
||||
role="button"
|
||||
class="outline secondary">J'ai oublié mon mot de passe</a>
|
||||
</fieldset>
|
||||
</form>
|
||||
{% endblock content %}
|
||||
|
|
8
base/templates/registration/password_change_form.html
Normal file
8
base/templates/registration/password_change_form.html
Normal file
|
@ -0,0 +1,8 @@
|
|||
{% extends "base.html" %}
|
||||
{% load form %}
|
||||
{% block content %}
|
||||
<h1>
|
||||
<i class="ri-lock-password-line"></i> Changer mon mot de passe
|
||||
</h1>
|
||||
{% form form submit="Changer mon mot de passe" %}
|
||||
{% endblock content %}
|
8
base/templates/registration/password_reset_confirm.html
Normal file
8
base/templates/registration/password_reset_confirm.html
Normal file
|
@ -0,0 +1,8 @@
|
|||
{% extends "base.html" %}
|
||||
{% load form %}
|
||||
{% block content %}
|
||||
<h1>
|
||||
<i class="ri-lock-password-line"></i> Réinitialiser mon mot de passe
|
||||
</h1>
|
||||
{% form form submit="Réinitialiser mon mot de passe" %}
|
||||
{% endblock content %}
|
8
base/templates/registration/password_reset_form.html
Normal file
8
base/templates/registration/password_reset_form.html
Normal file
|
@ -0,0 +1,8 @@
|
|||
{% extends "base.html" %}
|
||||
{% load form %}
|
||||
{% block content %}
|
||||
<h1>
|
||||
<i class="ri-lock-password-line"></i> Réinitialiser mon mot de passe
|
||||
</h1>
|
||||
{% form form submit="Réinitialiser mon mot de passe" %}
|
||||
{% endblock content %}
|
|
@ -4,8 +4,13 @@ register = template.Library()
|
|||
|
||||
|
||||
@register.inclusion_tag("base/form.html")
|
||||
def form(form, **kwargs):
|
||||
def form(f, **kwargs):
|
||||
return kwargs | {
|
||||
"form": form,
|
||||
"errors": form.errors,
|
||||
"form": f,
|
||||
"errors": f.errors,
|
||||
}
|
||||
|
||||
|
||||
@register.inclusion_tag("base/inline_form.html")
|
||||
def inline_form(f, **kwargs):
|
||||
return form(f, **kwargs)
|
||||
|
|
23
base/urls.py
23
base/urls.py
|
@ -1,4 +1,5 @@
|
|||
from django.urls import include, path
|
||||
from django.contrib.auth import views as auth_views
|
||||
from django.urls import path
|
||||
from django.views.generic import TemplateView
|
||||
|
||||
from . import views
|
||||
|
@ -6,6 +7,24 @@ from . import views
|
|||
urlpatterns = [
|
||||
path("", views.HomePageView.as_view(), name="index"),
|
||||
path("accounts/signup/", views.SignupView.as_view(), name="signup"),
|
||||
path("accounts/", include("django.contrib.auth.urls")),
|
||||
path("accounts/login/", auth_views.LoginView.as_view(), name="login"),
|
||||
path("accounts/logout/", auth_views.LogoutView.as_view(), name="logout"),
|
||||
path(
|
||||
"accounts/password_change/",
|
||||
views.PasswordChangeView.as_view(),
|
||||
name="password_change",
|
||||
),
|
||||
path(
|
||||
"accounts/password_reset/",
|
||||
views.PasswordResetView.as_view(),
|
||||
name="password_reset",
|
||||
),
|
||||
path(
|
||||
"accounts/reset/<uidb64>/<token>/",
|
||||
views.PasswordResetConfirmView.as_view(),
|
||||
name="password_reset_confirm",
|
||||
),
|
||||
path("accounts/settings/", views.AccountView.as_view(), name="account_settings"),
|
||||
path("accounts/delete/", views.AccountDeleteView.as_view(), name="account_delete"),
|
||||
path("legal/", TemplateView.as_view(template_name="privacy.html"), name="legal"),
|
||||
]
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
from django.contrib.auth import views as auth_views
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.messages.views import SuccessMessageMixin
|
||||
from django.shortcuts import redirect
|
||||
from django.urls import reverse_lazy
|
||||
from django.views.generic.base import TemplateView
|
||||
from django.views.generic.edit import CreateView
|
||||
from django.views.generic.edit import CreateView, DeleteView, UpdateView
|
||||
|
||||
from . import forms
|
||||
|
||||
|
@ -10,9 +12,53 @@ from . import forms
|
|||
class HomePageView(TemplateView):
|
||||
template_name = "index.html"
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
if request.user.is_authenticated:
|
||||
return redirect("home")
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
||||
|
||||
class SignupView(SuccessMessageMixin, CreateView):
|
||||
model = User
|
||||
form_class = forms.UserSignupForm
|
||||
success_url = reverse_lazy("login")
|
||||
success_message = "Le compte %(username)s a été créé avec succès."
|
||||
|
||||
|
||||
class PasswordChangeView(SuccessMessageMixin, auth_views.PasswordChangeView):
|
||||
success_message = "Le mot de passe a été changé avec succès."
|
||||
success_url = reverse_lazy("index")
|
||||
|
||||
|
||||
class PasswordResetView(SuccessMessageMixin, auth_views.PasswordResetView):
|
||||
success_message = "Un courriel a été envoyé avec les instructions pour réinitialiser votre mot de passe."
|
||||
success_url = reverse_lazy("login")
|
||||
|
||||
|
||||
class PasswordResetConfirmView(
|
||||
SuccessMessageMixin, auth_views.PasswordResetConfirmView
|
||||
):
|
||||
success_message = "Le mot de passe a été réinitialisé avec succès."
|
||||
success_url = reverse_lazy("login")
|
||||
|
||||
|
||||
class AccountView(UpdateView):
|
||||
model = User
|
||||
fields = ["username", "email"]
|
||||
success_url = reverse_lazy("index")
|
||||
template_name = "auth/user_settings.html"
|
||||
|
||||
def get_object(self, queryset=None):
|
||||
if queryset is None:
|
||||
queryset = self.get_queryset()
|
||||
return queryset.get(pk=self.request.user.pk)
|
||||
|
||||
|
||||
class AccountDeleteView(DeleteView):
|
||||
model = User
|
||||
success_url = reverse_lazy("index")
|
||||
|
||||
def get_object(self, queryset=None):
|
||||
if queryset is None:
|
||||
queryset = self.get_queryset()
|
||||
return queryset.get(pk=self.request.user.pk)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -3,6 +3,16 @@ from django import forms
|
|||
from . import models
|
||||
|
||||
|
||||
class GroupForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = models.Group
|
||||
fields = ["name"]
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.fields["name"].widget.attrs["placeholder"] = self.fields["name"].label
|
||||
|
||||
|
||||
class GroupAddMembersForm(forms.ModelForm):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
@ -29,3 +39,23 @@ class MusikGameForm(forms.ModelForm):
|
|||
kwargs["initial"].setdefault("players", players)
|
||||
super().__init__(*args, **kwargs)
|
||||
self.fields["players"].queryset = players
|
||||
|
||||
|
||||
class AnswerForm(forms.Form):
|
||||
def __init__(self, *args, **kwargs):
|
||||
game = kwargs.pop("game")
|
||||
user = kwargs.pop("user")
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
for music in game.musicgameorder_set.all():
|
||||
self.fields[f"answer-{music.order}"] = forms.ChoiceField(
|
||||
choices=[("", "")]
|
||||
+ list(game.players.all().values_list("id", "username")),
|
||||
required=False,
|
||||
label=music.order,
|
||||
initial=ma.answer.id
|
||||
if (ma := music.musicgameanswer_set.filter(player=user).first())
|
||||
and ma.answer
|
||||
else "",
|
||||
disabled=game.over,
|
||||
)
|
||||
|
|
17
game/migrations/0017_youtubecredentials_title.py
Normal file
17
game/migrations/0017_youtubecredentials_title.py
Normal file
|
@ -0,0 +1,17 @@
|
|||
# Generated by Django 5.2.3 on 2025-06-15 08:24
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("game", "0016_alter_groupleader_member"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="youtubecredentials",
|
||||
name="title",
|
||||
field=models.CharField(blank=True),
|
||||
),
|
||||
]
|
60
game/migrations/0018_musicgameanswer.py
Normal file
60
game/migrations/0018_musicgameanswer.py
Normal file
|
@ -0,0 +1,60 @@
|
|||
# Generated by Django 5.2.3 on 2025-06-15 10:36
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("game", "0017_youtubecredentials_title"),
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name="MusicGameAnswer",
|
||||
fields=[
|
||||
(
|
||||
"id",
|
||||
models.BigAutoField(
|
||||
auto_created=True,
|
||||
primary_key=True,
|
||||
serialize=False,
|
||||
verbose_name="ID",
|
||||
),
|
||||
),
|
||||
(
|
||||
"answer",
|
||||
models.ForeignKey(
|
||||
null=True,
|
||||
on_delete=django.db.models.deletion.SET_NULL,
|
||||
related_name="+",
|
||||
to=settings.AUTH_USER_MODEL,
|
||||
),
|
||||
),
|
||||
(
|
||||
"game",
|
||||
models.ForeignKey(
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
to="game.musicgameorder",
|
||||
),
|
||||
),
|
||||
(
|
||||
"player",
|
||||
models.ForeignKey(
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
to=settings.AUTH_USER_MODEL,
|
||||
),
|
||||
),
|
||||
],
|
||||
options={
|
||||
"ordering": ["game"],
|
||||
"constraints": [
|
||||
models.UniqueConstraint(
|
||||
fields=("game", "player"), name="unique_answer"
|
||||
)
|
||||
],
|
||||
},
|
||||
),
|
||||
]
|
|
@ -0,0 +1,21 @@
|
|||
# Generated by Django 5.2.3 on 2025-06-15 10:44
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("game", "0018_musicgameanswer"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterModelOptions(
|
||||
name="musikgame",
|
||||
options={"ordering": ["-over", "-date"]},
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="musikgame",
|
||||
name="over",
|
||||
field=models.BooleanField(default=False),
|
||||
),
|
||||
]
|
|
@ -0,0 +1,55 @@
|
|||
# Generated by Django 5.2.3 on 2025-06-15 11:23
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("game", "0019_alter_musikgame_options_musikgame_over"),
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterModelOptions(
|
||||
name="musikgame",
|
||||
options={"ordering": ["over", "-date"]},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name="MusicGameResults",
|
||||
fields=[
|
||||
(
|
||||
"id",
|
||||
models.BigAutoField(
|
||||
auto_created=True,
|
||||
primary_key=True,
|
||||
serialize=False,
|
||||
verbose_name="ID",
|
||||
),
|
||||
),
|
||||
("score", models.PositiveIntegerField(default=0)),
|
||||
(
|
||||
"game",
|
||||
models.ForeignKey(
|
||||
on_delete=django.db.models.deletion.CASCADE, to="game.musikgame"
|
||||
),
|
||||
),
|
||||
(
|
||||
"player",
|
||||
models.ForeignKey(
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
to=settings.AUTH_USER_MODEL,
|
||||
),
|
||||
),
|
||||
],
|
||||
options={
|
||||
"ordering": ["-score"],
|
||||
"constraints": [
|
||||
models.UniqueConstraint(
|
||||
fields=("game", "player"), name="unique_result"
|
||||
)
|
||||
],
|
||||
},
|
||||
),
|
||||
]
|
17
game/migrations/0021_alter_musicgameresults_score.py
Normal file
17
game/migrations/0021_alter_musicgameresults_score.py
Normal file
|
@ -0,0 +1,17 @@
|
|||
# Generated by Django 5.2.3 on 2025-06-15 11:33
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("game", "0020_alter_musikgame_options_musicgameresults"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name="musicgameresults",
|
||||
name="score",
|
||||
field=models.IntegerField(default=0),
|
||||
),
|
||||
]
|
17
game/migrations/0022_musicgameorder_value.py
Normal file
17
game/migrations/0022_musicgameorder_value.py
Normal file
|
@ -0,0 +1,17 @@
|
|||
# Generated by Django 5.2.3 on 2025-06-15 12:49
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("game", "0021_alter_musicgameresults_score"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="musicgameorder",
|
||||
name="value",
|
||||
field=models.PositiveIntegerField(default=0),
|
||||
),
|
||||
]
|
16
game/migrations/0023_alter_musicvideo_options.py
Normal file
16
game/migrations/0023_alter_musicvideo_options.py
Normal file
|
@ -0,0 +1,16 @@
|
|||
# Generated by Django 5.2.3 on 2025-06-15 14:19
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("game", "0022_musicgameorder_value"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterModelOptions(
|
||||
name="musicvideo",
|
||||
options={"ordering": ["blacklisted", "-date_added"]},
|
||||
),
|
||||
]
|
|
@ -1,5 +1,6 @@
|
|||
from django.contrib.auth.models import User
|
||||
from django.db import models
|
||||
from django.db.models import F
|
||||
from django.db.models.functions import Lower
|
||||
from django.db.models.signals import post_delete, post_save
|
||||
from django.dispatch import receiver
|
||||
|
@ -11,6 +12,7 @@ from . import tasks
|
|||
class YoutubeCredentials(models.Model):
|
||||
user = models.OneToOneField(User, on_delete=models.CASCADE)
|
||||
credentials = models.JSONField()
|
||||
title = models.CharField(blank=True)
|
||||
|
||||
|
||||
class Group(models.Model):
|
||||
|
@ -64,6 +66,12 @@ class MusicVideo(models.Model):
|
|||
fields=("yt_id", "owner", "group"), name="unique_music_in_group"
|
||||
)
|
||||
]
|
||||
ordering = ["blacklisted", "-date_added"]
|
||||
|
||||
|
||||
class GameManager(models.Manager):
|
||||
def playing(self):
|
||||
return self.filter(over=False)
|
||||
|
||||
|
||||
class MusikGame(models.Model):
|
||||
|
@ -73,10 +81,16 @@ class MusikGame(models.Model):
|
|||
players = models.ManyToManyField(User, verbose_name="Joueurs")
|
||||
playlist = models.CharField(blank=True, verbose_name="Playlist YouTube")
|
||||
playlist_loading = models.BooleanField(default=False)
|
||||
over = models.BooleanField(default=False)
|
||||
|
||||
objects = GameManager()
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse("game_detail", kwargs={"pk": self.pk})
|
||||
|
||||
class Meta:
|
||||
ordering = ["over", "-date"]
|
||||
|
||||
|
||||
@receiver(post_save, sender=MusikGame)
|
||||
def generateYoutubePlaylist(sender, instance, created, **kwargs):
|
||||
|
@ -85,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)
|
||||
|
@ -101,6 +118,14 @@ class MusicGameOrder(models.Model):
|
|||
player = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||
music_video = models.ForeignKey(MusicVideo, on_delete=models.CASCADE)
|
||||
order = models.PositiveIntegerField()
|
||||
value = models.PositiveIntegerField(default=0)
|
||||
|
||||
def update_value(self):
|
||||
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:
|
||||
constraints = [
|
||||
|
@ -110,3 +135,44 @@ class MusicGameOrder(models.Model):
|
|||
models.UniqueConstraint(fields=("game", "order"), name="unique_order"),
|
||||
]
|
||||
ordering = ["order"]
|
||||
|
||||
|
||||
class AnswerManager(models.Manager):
|
||||
def score(self, game, player):
|
||||
qs = self.filter(game__game=game, player=player)
|
||||
return (
|
||||
qs.exclude(game__player=player)
|
||||
.filter(game__player=F("answer"))
|
||||
.aggregate(score=models.Sum("game__value", default=0))
|
||||
.get("score")
|
||||
- 500
|
||||
* qs.filter(game__player=player).exclude(game__player=F("answer")).count()
|
||||
)
|
||||
|
||||
|
||||
class MusicGameAnswer(models.Model):
|
||||
game = models.ForeignKey(MusicGameOrder, on_delete=models.CASCADE)
|
||||
player = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||
answer = models.ForeignKey(
|
||||
User, on_delete=models.SET_NULL, null=True, related_name="+"
|
||||
)
|
||||
|
||||
objects = AnswerManager()
|
||||
|
||||
class Meta:
|
||||
constraints = [
|
||||
models.UniqueConstraint(fields=("game", "player"), name="unique_answer"),
|
||||
]
|
||||
ordering = ["game"]
|
||||
|
||||
|
||||
class MusicGameResults(models.Model):
|
||||
game = models.ForeignKey(MusikGame, on_delete=models.CASCADE)
|
||||
player = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||
score = models.IntegerField(default=0)
|
||||
|
||||
class Meta:
|
||||
constraints = [
|
||||
models.UniqueConstraint(fields=("game", "player"), name="unique_result")
|
||||
]
|
||||
ordering = ["-score"]
|
||||
|
|
|
@ -18,7 +18,7 @@ def generate_playlist(creds, game_pk):
|
|||
"description": "Playlist générée par Musik",
|
||||
},
|
||||
"status": {
|
||||
"privacyStatus": "private",
|
||||
"privacyStatus": "unlisted",
|
||||
},
|
||||
},
|
||||
)
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
{% extends "base.html" %}
|
||||
{% load form %}
|
||||
{% block content %}
|
||||
<dialog open>
|
||||
<article>
|
||||
|
|
|
@ -10,115 +10,7 @@
|
|||
{{ group.name }}
|
||||
</h1>
|
||||
{% include "game/include/group_buttons.html" %}
|
||||
{% if group.musikgame_set.exists %}
|
||||
<h2>
|
||||
<i class="ri-play-circle-fill"></i> Parties
|
||||
</h2>
|
||||
<form method="post">
|
||||
{% csrf_token %}
|
||||
<table>
|
||||
<thead>
|
||||
{% if group.owner == user %}<th></th>{% endif %}
|
||||
<th>Date</th>
|
||||
<th>
|
||||
<i class="ri-youtube-fill"></i> Playlists
|
||||
</th>
|
||||
<th>Joueurs</th>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for game in group.musikgame_set.all %}
|
||||
<tr>
|
||||
{% if group.owner == user %}
|
||||
<td>
|
||||
<input type="checkbox" name="game" value="{{ game.pk }}">
|
||||
</td>
|
||||
{% endif %}
|
||||
<td>
|
||||
<a href="{% url "game_detail" pk=game.pk %}">{{ game.date }}</a>
|
||||
</td>
|
||||
<td>
|
||||
{% if game.playlist %}
|
||||
<a href="{% yt_playlist game %}"
|
||||
{% if game.playlist_loading %}aria-busy="true"{% endif %}><i class="ri-youtube-fill"></i> Playlist</a>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>{{ game.players.all|join:", " }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% if group.owner == user %}
|
||||
<button type="submit"
|
||||
class="secondary"
|
||||
formaction="{% url "group_remove_game" pk=group.pk %}">
|
||||
<i class="ri-delete-bin-fill"></i> Supprimer les parties sélectionnées
|
||||
</button>
|
||||
{% endif %}
|
||||
</form>
|
||||
{% endif %}
|
||||
{% include "game/include/group_games.html" %}
|
||||
{% include "game/include/group_members.html" %}
|
||||
<h2>
|
||||
<i class="ri-music-2-fill"></i> Mes musiques <span class="music-count">{{ musics.count }}</span>
|
||||
</h2>
|
||||
<details>
|
||||
<summary role="button">
|
||||
<i class="ri-music-2-fill"></i> Liste des musiques
|
||||
</summary>
|
||||
<form method="post">
|
||||
{% csrf_token %}
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<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>
|
||||
<input type="checkbox" disabled {% if music.blacklisted %}checked{% endif %}>
|
||||
</td>
|
||||
</tr>
|
||||
{% empty %}
|
||||
<tr>
|
||||
<td colspan="4">Aucune musique.</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% if musics %}
|
||||
<fieldset role="group">
|
||||
<button type="submit"
|
||||
formaction="{% url "group_remove_music" pk=group.pk %}"
|
||||
class="secondary">
|
||||
<i class="ri-delete-bin-fill"></i> Supprimer
|
||||
</button>
|
||||
<button type="submit"
|
||||
class="secondary"
|
||||
formaction="{% url "group_unblacklist_music" pk=group.pk %}">
|
||||
<i class="ri-history-fill"></i> Retirer de la blacklist
|
||||
</button>
|
||||
</fieldset>
|
||||
{% endif %}
|
||||
</form>
|
||||
</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>
|
||||
{% include "game/include/group_musics.html" %}
|
||||
{% endblock content %}
|
||||
|
|
|
@ -1,26 +1,30 @@
|
|||
<p>Bienvenue {{ user.username }} !</p>
|
||||
<h2>
|
||||
<i class="ri-group-2-fill"></i> Mes groupes
|
||||
</h2>
|
||||
<p>
|
||||
<a href="{% url "group_create" %}" role="button"><i class="ri-add-box-fill"></i> Créer un groupe</a>
|
||||
{% if not user.youtubecredentials.credentials %}
|
||||
<a href="{% url "youtube_login" %}" role="button"><i class="ri-youtube-fill"></i> Me connecter au compte Youtube</a>
|
||||
{% extends "base.html" %}
|
||||
{% load form %}
|
||||
{% block content %}
|
||||
<h1>
|
||||
<i class="ri-music-ai-fill"></i> Musik
|
||||
</h1>
|
||||
<p>
|
||||
Bienvenue <strong>{{ user.username }}</strong> !
|
||||
</p>
|
||||
<h2>
|
||||
<i class="ri-group-2-fill"></i> Mes groupes
|
||||
</h2>
|
||||
{% if user.owned_group_set.exists or user.group_set.exists %}
|
||||
{% for group in user.owned_group_set.all %}
|
||||
<a class="group" href="{{ group.get_absolute_url }}">
|
||||
<article>
|
||||
<i class="ri-vip-crown-fill owner i"></i> {{ group.name }}
|
||||
</article>
|
||||
</a>
|
||||
{% endfor %}
|
||||
{% for group in user.group_set.all %}
|
||||
<a class="group" href="{{ group.get_absolute_url }}">
|
||||
<article>
|
||||
<i class="ri-group-2-fill i"></i> {{ group.name }} <span class="group-owner">{{ group.owner }}</span>
|
||||
</article>
|
||||
</a>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
</p>
|
||||
{% if user.owned_group_set.exists or user.group_set.exists %}
|
||||
{% for group in user.owned_group_set.all %}
|
||||
<a class="group" href="{{ group.get_absolute_url }}">
|
||||
<article>
|
||||
<i class="ri-vip-crown-fill owner i"></i> {{ group.name }}
|
||||
</article>
|
||||
</a>
|
||||
{% endfor %}
|
||||
{% for group in user.group_set.all %}
|
||||
<a class="group" href="{{ group.get_absolute_url }}">
|
||||
<article>
|
||||
<i class="ri-group-2-fill i"></i> {{ group.name }} <span class="group-owner">{{ group.owner }}</span>
|
||||
</article>
|
||||
</a>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% inline_form group_form action="group_create" submit="Créer" %}
|
||||
{% endblock content %}
|
||||
|
|
49
game/templates/game/include/game_results.html
Normal file
49
game/templates/game/include/game_results.html
Normal file
|
@ -0,0 +1,49 @@
|
|||
{% load game %}
|
||||
{% if musikgame.over %}
|
||||
<h2>
|
||||
<i class="ri-list-ordered"></i> Résultats
|
||||
</h2>
|
||||
<details open>
|
||||
<summary role="button">
|
||||
<i class="ri-list-ordered-2"></i> Résultats
|
||||
</summary>
|
||||
<div class="overflow-auto">
|
||||
<table class="striped results">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
<i class="ri-list-ordered-2"></i>
|
||||
</th>
|
||||
<th>
|
||||
<i class="ri-music-2-fill"></i> Musique
|
||||
</th>
|
||||
<th>
|
||||
<i class="ri-user-line"></i> Joueur
|
||||
</th>
|
||||
{% for player in musikgame.musicgameresults_set.all %}
|
||||
<th {% if user == player.player %}class="me"{% endif %}>{{ player.player.username }}</th>
|
||||
<th class="sc">
|
||||
{% if forloop.first %}<i class="ri-medal-fill gold"></i>{% endif %}
|
||||
<span class="score">{{ player.score }}</span>
|
||||
</th>
|
||||
{% endfor %}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for music in musikgame.musicgameorder_set.all %}
|
||||
<tr>
|
||||
<td>{{ music.order }}</td>
|
||||
<td>
|
||||
<a href="https://youtu.be/{{ music.music_video.yt_id }}">{{ music.music_video.title }}</a>
|
||||
</td>
|
||||
<td>{{ music.player }}</td>
|
||||
{% for player in musikgame.musicgameresults_set.all %}
|
||||
{% answer player music %}
|
||||
{% endfor %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</details>
|
||||
{% endif %}
|
62
game/templates/game/include/group_games.html
Normal file
62
game/templates/game/include/group_games.html
Normal file
|
@ -0,0 +1,62 @@
|
|||
{% load form youtube %}
|
||||
{% if group.musikgame_set.exists %}
|
||||
{% for game in group.musikgame_set.playing %}
|
||||
<a class="running" href="{{ game.get_absolute_url }}">
|
||||
<article><i class="ri-play-circle-fill i"></i>{{ game.date }}</article>
|
||||
</a>
|
||||
{% endfor %}
|
||||
<h2>
|
||||
<i class="ri-play-circle-fill"></i> Parties
|
||||
</h2>
|
||||
<form method="post">
|
||||
{% csrf_token %}
|
||||
<table>
|
||||
<thead>
|
||||
{% if group.owner == user %}<th></th>{% endif %}
|
||||
<th>
|
||||
<i class="ri-play-circle-fill"></i>
|
||||
</th>
|
||||
<th>Date</th>
|
||||
<th>
|
||||
<i class="ri-youtube-fill"></i> Playlists
|
||||
</th>
|
||||
<th>Joueurs</th>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for game in group.musikgame_set.all %}
|
||||
<tr>
|
||||
{% if group.owner == user %}
|
||||
<td>
|
||||
<input type="checkbox" name="game" value="{{ game.pk }}">
|
||||
</td>
|
||||
{% endif %}
|
||||
<td>
|
||||
{% if game.over %}
|
||||
<i class="ri-stop-circle-fill"></i>
|
||||
{% else %}
|
||||
<i class="ri-play-circle-fill hl"></i>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
<a href="{% url "game_detail" pk=game.pk %}">{{ game.date }}</a>
|
||||
</td>
|
||||
<td>
|
||||
{% if game.playlist %}
|
||||
<a href="{% yt_playlist game %}"
|
||||
{% if game.playlist_loading %}aria-busy="true"{% endif %}><i class="ri-youtube-fill"></i> Playlist</a>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>{{ game.players.all|join:", " }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% if group.owner == user %}
|
||||
<button type="submit"
|
||||
class="secondary"
|
||||
formaction="{% url "group_remove_game" pk=group.pk %}">
|
||||
<i class="ri-delete-bin-fill"></i> Supprimer les parties sélectionnées
|
||||
</button>
|
||||
{% endif %}
|
||||
</form>
|
||||
{% endif %}
|
|
@ -12,7 +12,7 @@
|
|||
<i class="ri-vip-crown-fill"></i>
|
||||
</th>
|
||||
<th>
|
||||
<i class="ri-mv-line"></i>
|
||||
<i class="ri-mv-fill"></i>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
|
66
game/templates/game/include/group_musics.html
Normal file
66
game/templates/game/include/group_musics.html
Normal file
|
@ -0,0 +1,66 @@
|
|||
<h2>
|
||||
<i class="ri-music-2-fill"></i> Mes musiques <span class="music-count">{{ musics.count }}</span>
|
||||
</h2>
|
||||
<details>
|
||||
<summary role="button">
|
||||
<i class="ri-music-2-fill"></i> Liste des musiques
|
||||
</summary>
|
||||
<form method="post">
|
||||
{% csrf_token %}
|
||||
<div class="overflow-auto">
|
||||
<table class="musics">
|
||||
<thead>
|
||||
<tr>
|
||||
<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>
|
||||
<input type="checkbox" disabled {% if music.blacklisted %}checked{% endif %}>
|
||||
</td>
|
||||
</tr>
|
||||
{% empty %}
|
||||
<tr>
|
||||
<td colspan="4">Aucune musique.</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{% if musics %}
|
||||
<fieldset role="group">
|
||||
<button type="submit"
|
||||
formaction="{% url "group_remove_music" pk=group.pk %}"
|
||||
class="secondary">
|
||||
<i class="ri-delete-bin-fill"></i> Supprimer
|
||||
</button>
|
||||
<button type="submit"
|
||||
class="secondary"
|
||||
formaction="{% url "group_unblacklist_music" pk=group.pk %}">
|
||||
<i class="ri-history-fill"></i> Retirer de la blacklist
|
||||
</button>
|
||||
</fieldset>
|
||||
{% endif %}
|
||||
</form>
|
||||
</details>
|
||||
<form method="post" action="{% url "group_add_music" pk=group.pk %}">
|
||||
{% csrf_token %}
|
||||
<fieldset>
|
||||
<textarea name="yt_id" id="yt_id" placeholder="Musiques" required></textarea>
|
||||
<button type="submit">Ajouter</button>
|
||||
</fieldset>
|
||||
</form>
|
26
game/templates/game/musikgame_answer.html
Normal file
26
game/templates/game/musikgame_answer.html
Normal file
|
@ -0,0 +1,26 @@
|
|||
{% extends "base.html" %}
|
||||
{% block content %}
|
||||
<h2>Mes réponses</h2>
|
||||
<form method="post">
|
||||
{% csrf_token %}
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
<i class="ri-mv-fill" alt="Musique"></i>
|
||||
</th>
|
||||
<th>Réponse</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for field in form %}
|
||||
<tr>
|
||||
<td>{{ field.label }}</td>
|
||||
<td>{{ field }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% if not musikgame.over %}<button type="submit">Sauvegarder mes réponses</button>{% endif %}
|
||||
</form>
|
||||
{% endblock content %}
|
|
@ -2,20 +2,52 @@
|
|||
{% load youtube %}
|
||||
{% block content %}
|
||||
<h1>
|
||||
<i class="ri-play-circle-fill"></i> {{ musikgame.date }}
|
||||
{% if musikgame.over %}
|
||||
<i class="ri-stop-circle-fill"></i>
|
||||
{% else %}
|
||||
<i class="ri-play-circle-fill hl"></i>
|
||||
{% endif %}
|
||||
{{ musikgame.date }}
|
||||
</h1>
|
||||
{% if musikgame.playlist or musikgame.playlist_loading %}
|
||||
<p>
|
||||
<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>
|
||||
</p>
|
||||
{% endif %}
|
||||
<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>
|
||||
{% 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>
|
||||
<p>{{ musikgame.players.all|join:", " }}</p>
|
||||
{% if musikgame.over %}
|
||||
<ol class="podium">
|
||||
{% for player in musikgame.musicgameresults_set.all %}
|
||||
<li {% if user == player.player %}class="me"{% endif %}>
|
||||
{{ player.player.username }} <span class="score">{{ player.score }}</span>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ol>
|
||||
{% else %}
|
||||
<p>{{ musikgame.players.all|join:", " }}</p>
|
||||
{% endif %}
|
||||
<h2>
|
||||
<i class="ri-music-2-fill"></i> Musiques
|
||||
</h2>
|
||||
|
@ -31,38 +63,5 @@
|
|||
{% endfor %}
|
||||
</ol>
|
||||
</details>
|
||||
<h2>
|
||||
<i class="ri-list-ordered"></i> Résultats
|
||||
</h2>
|
||||
<details>
|
||||
<summary role="button">
|
||||
<i class="ri-list-ordered-2"></i> Résultats
|
||||
</summary>
|
||||
<table class="striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
<i class="ri-list-ordered-2"></i>
|
||||
</th>
|
||||
<th>
|
||||
<i class="ri-music-2-fill"></i> Musique
|
||||
</th>
|
||||
<th>
|
||||
<i class="ri-user-line"></i> Joueur
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for music in musikgame.musicgameorder_set.all %}
|
||||
<tr>
|
||||
<td>{{ music.order }}</td>
|
||||
<td>
|
||||
<a href="https://youtu.be/{{ music.music_video.yt_id }}">{{ music.music_video.title }}</a>
|
||||
</td>
|
||||
<td>{{ music.player }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</details>
|
||||
{% include "game/include/game_results.html" %}
|
||||
{% endblock content %}
|
||||
|
|
|
@ -4,5 +4,14 @@
|
|||
<h1>
|
||||
<i class="ri-group-2-fill"></i> {{ group.name }}
|
||||
</h1>
|
||||
<p>
|
||||
{% 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 %}
|
||||
<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 %}
|
||||
{% endblock content %}
|
||||
|
|
16
game/templates/tags/game/answer.html
Normal file
16
game/templates/tags/game/answer.html
Normal file
|
@ -0,0 +1,16 @@
|
|||
{% if empty %}
|
||||
<td class="empty"></td>
|
||||
<td class="empty sc">
|
||||
<i class="ri-checkbox-blank-circle-fill"></i><span class="score">{{ score }}</span>
|
||||
</td>
|
||||
{% elif correct %}
|
||||
<td class="correct">{{ answer }}</td>
|
||||
<td class="correct sc">
|
||||
<i class="ri-checkbox-circle-fill"></i><span class="score">{{ score }}</span>
|
||||
</td>
|
||||
{% else %}
|
||||
<td class="wrong">{{ answer }}</td>
|
||||
<td class="wrong sc">
|
||||
<i class="ri-close-circle-fill"></i><span class="score">{{ score }}</span>
|
||||
</td>
|
||||
{% endif %}
|
30
game/templatetags/game.py
Normal file
30
game/templatetags/game.py
Normal file
|
@ -0,0 +1,30 @@
|
|||
from django import template
|
||||
|
||||
from .. import models
|
||||
|
||||
register = template.Library()
|
||||
|
||||
|
||||
@register.inclusion_tag("tags/game/answer.html")
|
||||
def answer(player, music):
|
||||
res = {
|
||||
"answer": "",
|
||||
"correct": False,
|
||||
"score": 0,
|
||||
"empty": False,
|
||||
}
|
||||
|
||||
answer = models.MusicGameAnswer.objects.filter(
|
||||
player=player.player, game=music
|
||||
).first()
|
||||
if answer:
|
||||
res["answer"] = answer.answer
|
||||
res["correct"] = answer.answer == music.player
|
||||
if music.player == player.player:
|
||||
res["score"] = 0 if res["correct"] else "−500"
|
||||
else:
|
||||
res["score"] = music.value if res["correct"] else 0
|
||||
else:
|
||||
res["empty"] = True
|
||||
|
||||
return res
|
|
@ -3,6 +3,7 @@ from django.urls import path
|
|||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
path("home", views.HomeView.as_view(), name="home"),
|
||||
path("group/create/", views.GroupCreateView.as_view(), name="group_create"),
|
||||
path(
|
||||
"group/<int:pk>/update/", views.GroupUpdateView.as_view(), name="group_update"
|
||||
|
@ -51,6 +52,7 @@ urlpatterns = [
|
|||
),
|
||||
path("group/game/<int:pk>/", views.GameDetailView.as_view(), name="game_detail"),
|
||||
path("youtube_login/", views.YoutubeLoginView.as_view(), name="youtube_login"),
|
||||
path("youtube_logout/", views.YoutubeLogoutView.as_view(), name="youtube_logout"),
|
||||
path(
|
||||
"youtube_callback/",
|
||||
views.YoutubeCallbackView.as_view(),
|
||||
|
@ -61,4 +63,10 @@ urlpatterns = [
|
|||
views.GroupClearBlacklistView.as_view(),
|
||||
name="group_clear_blacklist",
|
||||
),
|
||||
path(
|
||||
"group/game/<int:pk>/answer/",
|
||||
views.GameAnswerView.as_view(),
|
||||
name="game_answer",
|
||||
),
|
||||
path("group/game/<int:pk>/end/", views.GameEndView.as_view(), name="game_end"),
|
||||
]
|
||||
|
|
178
game/views.py
178
game/views.py
|
@ -1,6 +1,7 @@
|
|||
import random
|
||||
|
||||
import google_auth_oauthlib
|
||||
import googleapiclient
|
||||
from django.conf import settings
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
|
@ -11,12 +12,22 @@ from django.db import IntegrityError
|
|||
from django.db.models import Count, Q
|
||||
from django.shortcuts import get_object_or_404, redirect
|
||||
from django.views import View
|
||||
from django.views.generic import TemplateView
|
||||
from django.views.generic.detail import DetailView, SingleObjectMixin
|
||||
from django.views.generic.edit import CreateView, DeleteView, UpdateView
|
||||
|
||||
from . import forms, models, utils
|
||||
|
||||
|
||||
class HomeView(LoginRequiredMixin, TemplateView):
|
||||
template_name = "game/home.html"
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
data = super().get_context_data(**kwargs)
|
||||
data["group_form"] = forms.GroupForm()
|
||||
return data
|
||||
|
||||
|
||||
class OwnerFilterMixin(LoginRequiredMixin):
|
||||
def get_queryset(self):
|
||||
return super().get_queryset().filter(owner=self.request.user)
|
||||
|
@ -71,7 +82,9 @@ class GroupDetailView(MemberFilterMixin, GroupMixin, DetailView):
|
|||
.musicvideo_set.filter(owner=data["group"].owner, blacklisted=False)
|
||||
.count()
|
||||
)
|
||||
data["members"] = data["group"].members.through.objects.annotate(
|
||||
data["members"] = models.Group.members.through.objects.filter(
|
||||
group=data["group"]
|
||||
).annotate(
|
||||
count=Count(
|
||||
"user__musicvideo",
|
||||
filter=Q(
|
||||
|
@ -91,28 +104,31 @@ class GroupAddMusicView(MemberFilterMixin, SingleObjectMixin, View):
|
|||
|
||||
def post(self, request, pk):
|
||||
group = self.get_object()
|
||||
yt_id = request.POST.get("yt_id")
|
||||
if not yt_id:
|
||||
messages.add_message(request, messages.ERROR, "Aucun identifiant donné")
|
||||
return redirect(group)
|
||||
yt_id = utils.parse_musik(yt_id)
|
||||
ids = request.POST.get("yt_id")
|
||||
for yt_id in ids.split():
|
||||
if not yt_id:
|
||||
messages.add_message(request, messages.ERROR, "Aucun identifiant donné")
|
||||
return redirect(group)
|
||||
yt_id = utils.parse_musik(yt_id)
|
||||
|
||||
title = utils.get_yt_title(yt_id)
|
||||
if not title:
|
||||
messages.add_message(
|
||||
request, messages.ERROR, f"Vidéo Youtube invalide : {yt_id}"
|
||||
)
|
||||
return redirect(group)
|
||||
try:
|
||||
group.musicvideo_set.create(yt_id=yt_id, title=title, owner=request.user)
|
||||
except IntegrityError:
|
||||
messages.add_message(
|
||||
request, messages.ERROR, f"Vidéo Youtube déjà ajoutée : {yt_id}"
|
||||
)
|
||||
title = utils.get_yt_title(yt_id)
|
||||
if not title:
|
||||
messages.add_message(
|
||||
request, messages.ERROR, f"Vidéo Youtube invalide : {yt_id}"
|
||||
)
|
||||
else:
|
||||
try:
|
||||
group.musicvideo_set.create(
|
||||
yt_id=yt_id, title=title, owner=request.user
|
||||
)
|
||||
except IntegrityError:
|
||||
messages.add_message(
|
||||
request, messages.ERROR, f"Vidéo Youtube déjà ajoutée : {yt_id}"
|
||||
)
|
||||
|
||||
messages.add_message(
|
||||
request, messages.SUCCESS, f"Vidéo Youtube ajoutée : {yt_id}"
|
||||
)
|
||||
messages.add_message(
|
||||
request, messages.SUCCESS, f"Vidéo Youtube ajoutée : {yt_id}"
|
||||
)
|
||||
return redirect(group)
|
||||
|
||||
|
||||
|
@ -123,19 +139,24 @@ class GroupAddMemberView(MemberFilterMixin, SingleObjectMixin, View):
|
|||
group = self.get_object()
|
||||
if not group.is_leader(request.user):
|
||||
raise PermissionDenied()
|
||||
username = request.POST.get("username")
|
||||
user = User.objects.get(username=username)
|
||||
if user == group.owner:
|
||||
messages.add_message(
|
||||
request, messages.WARNING, f"{user} est le propriétaire du groupe."
|
||||
)
|
||||
return redirect(group)
|
||||
if user in group.members.all():
|
||||
messages.add_message(
|
||||
request, messages.WARNING, f"{user} est déjà membre du groupe."
|
||||
)
|
||||
usernames = request.POST.get("username")
|
||||
for username in usernames.split():
|
||||
user = User.objects.filter(username=username).first()
|
||||
if not user:
|
||||
messages.add_message(
|
||||
request, messages.ERROR, f"{username} n'existe pas."
|
||||
)
|
||||
elif user == group.owner:
|
||||
messages.add_message(
|
||||
request, messages.WARNING, f"{user} est le propriétaire du groupe."
|
||||
)
|
||||
elif user in group.members.all():
|
||||
messages.add_message(
|
||||
request, messages.WARNING, f"{user} est déjà membre du groupe."
|
||||
)
|
||||
else:
|
||||
group.members.add(user)
|
||||
|
||||
group.members.add(user)
|
||||
return redirect(group)
|
||||
|
||||
|
||||
|
@ -306,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
|
||||
|
||||
|
||||
|
@ -331,6 +349,12 @@ class GameDetailView(LoginRequiredMixin, DetailView):
|
|||
.distinct()
|
||||
)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
data = super().get_context_data(**kwargs)
|
||||
data["is_leader"] = data["musikgame"].group.is_leader(self.request.user)
|
||||
data["is_owner"] = data["musikgame"].group.is_owner(self.request.user)
|
||||
return data
|
||||
|
||||
|
||||
class YoutubeCallbackView(LoginRequiredMixin, View):
|
||||
def get(self, request):
|
||||
|
@ -351,6 +375,13 @@ class YoutubeCallbackView(LoginRequiredMixin, View):
|
|||
flow.fetch_token(code=request.GET.get("code"))
|
||||
|
||||
credentials = flow.credentials
|
||||
|
||||
yt_api = googleapiclient.discovery.build(
|
||||
"youtube", "v3", credentials=credentials
|
||||
)
|
||||
channel_request = yt_api.channels().list(part="snippet", mine=True)
|
||||
res = channel_request.execute()
|
||||
|
||||
models.YoutubeCredentials.objects.update_or_create(
|
||||
user=request.user,
|
||||
defaults={
|
||||
|
@ -361,10 +392,10 @@ class YoutubeCallbackView(LoginRequiredMixin, View):
|
|||
"client_id": credentials.client_id,
|
||||
"client_secret": credentials.client_secret,
|
||||
"granted_scopes": credentials.granted_scopes,
|
||||
}
|
||||
},
|
||||
"title": res["items"][0]["snippet"]["title"],
|
||||
},
|
||||
)
|
||||
|
||||
messages.add_message(request, messages.SUCCESS, "Connexion à Youtube réussie.")
|
||||
return redirect("/")
|
||||
|
||||
|
@ -385,6 +416,12 @@ class YoutubeLoginView(LoginRequiredMixin, View):
|
|||
return redirect(auth_url)
|
||||
|
||||
|
||||
class YoutubeLogoutView(LoginRequiredMixin, View):
|
||||
def post(self, request):
|
||||
request.user.youtubecredentials.delete()
|
||||
return redirect("account_settings")
|
||||
|
||||
|
||||
class GroupClearBlacklistView(MemberFilterMixin, SingleObjectMixin, View):
|
||||
model = models.Group
|
||||
|
||||
|
@ -395,3 +432,64 @@ class GroupClearBlacklistView(MemberFilterMixin, SingleObjectMixin, View):
|
|||
group.musicvideo_set.filter(blacklisted=True).update(blacklisted=False)
|
||||
messages.add_message(request, messages.SUCCESS, "La blacklist a été effacée.")
|
||||
return redirect(group)
|
||||
|
||||
|
||||
class GameAnswerView(LoginRequiredMixin, DetailView):
|
||||
model = models.MusikGame
|
||||
template_name = "game/musikgame_answer.html"
|
||||
|
||||
def get_queryset(self):
|
||||
return super().get_queryset().filter(players=self.request.user)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
return super().get_context_data(**kwargs) | {
|
||||
"form": forms.AnswerForm(game=self.object, user=self.request.user)
|
||||
}
|
||||
|
||||
def post(self, request, pk):
|
||||
game = self.get_object()
|
||||
if game.over:
|
||||
raise PermissionDenied()
|
||||
for music in game.musicgameorder_set.all():
|
||||
answer = request.POST.get(f"answer-{music.order}")
|
||||
if answer:
|
||||
models.MusicGameAnswer.objects.update_or_create(
|
||||
game=music,
|
||||
player=request.user,
|
||||
defaults={"answer": game.players.get(pk=answer)},
|
||||
)
|
||||
else:
|
||||
models.MusicGameAnswer.objects.update_or_create(
|
||||
game=music,
|
||||
player=request.user,
|
||||
defaults={"answer": None},
|
||||
)
|
||||
return redirect("game_answer", pk)
|
||||
|
||||
|
||||
class GameEndView(LoginRequiredMixin, SingleObjectMixin, View):
|
||||
model = models.MusikGame
|
||||
|
||||
def get_queryset(self):
|
||||
return super().get_queryset().filter(over=False)
|
||||
|
||||
def post(self, request, pk):
|
||||
game = self.get_object()
|
||||
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()
|
||||
|
||||
for player in game.players.all():
|
||||
score = player.musicgameanswer_set.score(game, player)
|
||||
models.MusicGameResults.objects.create(
|
||||
game=game, player=player, score=score
|
||||
)
|
||||
|
||||
game.save()
|
||||
return redirect("game_detail", pk)
|
||||
|
|
5
musik/context_processors.py
Normal file
5
musik/context_processors.py
Normal file
|
@ -0,0 +1,5 @@
|
|||
from django.conf import settings
|
||||
|
||||
|
||||
def version(request):
|
||||
return {"VERSION": settings.VERSION}
|
|
@ -13,6 +13,8 @@ https://docs.djangoproject.com/en/5.2/ref/settings/
|
|||
import os
|
||||
from pathlib import Path
|
||||
|
||||
VERSION = "0.4.4"
|
||||
|
||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||
|
||||
|
@ -71,6 +73,7 @@ TEMPLATES = [
|
|||
"django.template.context_processors.request",
|
||||
"django.contrib.auth.context_processors.auth",
|
||||
"django.contrib.messages.context_processors.messages",
|
||||
"musik.context_processors.version",
|
||||
],
|
||||
},
|
||||
},
|
||||
|
@ -141,3 +144,12 @@ YOUTUBE_API_KEY = os.getenv("YOUTUBE_API_KEY", "")
|
|||
YOUTUBE_OAUTH_SECRETS = os.getenv("YOUTUBE_OAUTH_SECRETS", "")
|
||||
|
||||
CELERY_BROKER_URL = os.getenv("CELERY_BROKER_URL", None)
|
||||
|
||||
EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
|
||||
EMAIL_HOST = os.getenv("EMAIL_HOST")
|
||||
EMAIL_PORT = os.getenv("EMAIL_PORT", 587)
|
||||
EMAIL_HOST_USER = os.getenv("EMAIL_HOST_USER")
|
||||
EMAIL_HOST_PASSWORD = os.getenv("EMAIL_HOST_PASSWORD")
|
||||
EMAIL_USE_SSL = os.getenv("EMAIL_USE_SSL", False)
|
||||
EMAIL_USE_TLS = os.getenv("EMAIL_USE_TLS", not EMAIL_USE_SSL)
|
||||
DEFAULT_FROM_EMAIL = os.getenv("DEFAULT_FROM_EMAIL", EMAIL_HOST_USER)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[project]
|
||||
name = "musik"
|
||||
version = "0.1.3"
|
||||
version = "0.4.4"
|
||||
description = "Le jeu de Musik."
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.12"
|
||||
|
|
8
uv.lock
generated
8
uv.lock
generated
|
@ -66,11 +66,11 @@ wheels = [
|
|||
|
||||
[[package]]
|
||||
name = "certifi"
|
||||
version = "2025.4.26"
|
||||
version = "2025.6.15"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/e8/9e/c05b3920a3b7d20d3d3310465f50348e5b3694f4f88c6daf736eef3024c4/certifi-2025.4.26.tar.gz", hash = "sha256:0a816057ea3cdefcef70270d2c515e4506bbc954f417fa5ade2021213bb8f0c6", size = 160705, upload-time = "2025-04-26T02:12:29.51Z" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/73/f7/f14b46d4bcd21092d7d3ccef689615220d8a08fb25e564b65d20738e672e/certifi-2025.6.15.tar.gz", hash = "sha256:d747aa5a8b9bbbb1bb8c22bb13e22bd1f18e9796defa16bab421f7f7a317323b", size = 158753, upload-time = "2025-06-15T02:45:51.329Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/4a/7e/3db2bd1b1f9e95f7cddca6d6e75e2f2bd9f51b1246e546d88addca0106bd/certifi-2025.4.26-py3-none-any.whl", hash = "sha256:30350364dfe371162649852c63336a15c70c6510c2ad5015b21c2345311805f3", size = 159618, upload-time = "2025-04-26T02:12:27.662Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/84/ae/320161bd181fc06471eed047ecce67b693fd7515b16d495d8932db763426/certifi-2025.6.15-py3-none-any.whl", hash = "sha256:2e0c7ce7cb5d8f8634ca55d2ba7e6ec2689a2fd6537d8dec1296a477a4910057", size = 157650, upload-time = "2025-06-15T02:45:49.977Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -423,7 +423,7 @@ wheels = [
|
|||
|
||||
[[package]]
|
||||
name = "musik"
|
||||
version = "0.1.1"
|
||||
version = "0.4.4"
|
||||
source = { virtual = "." }
|
||||
dependencies = [
|
||||
{ name = "celery" },
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue