Signed-off-by: Yohann D'ANELLO <ynerant@crans.org>
This commit is contained in:
Yohann D'ANELLO 2021-01-28 22:12:35 +01:00
parent 546e936f27
commit b4fd13a897
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85
7 changed files with 64 additions and 5 deletions

View File

@ -1,6 +1,21 @@
from django import forms
from django.utils.translation import gettext_lazy as _
from .models import Action, CupidonAction, DoveAction, HackerAction, RavenAction, WerewolfAction, WitchAction
from .models import Action, Cupidon, CupidonAction, DiscordUser, Dove, DoveAction, Hacker, HackerAction, \
Raven, RavenAction, Werewolf, WerewolfAction, Witch, WitchAction
class PlayerForm(forms.Form):
user = forms.ModelChoiceField(
queryset=DiscordUser.objects.filter(is_superuser=False, player__isnull=True),
label=lambda: _("user").capitalize(),
)
player_type = forms.ChoiceField(
choices=[(model.__name__, model._meta.verbose_name)
for model in [Werewolf, Cupidon, Witch, Raven, Dove, Hacker]],
label=lambda: _("player type").capitalize(),
)
class ActionForm(forms.ModelForm):

View File

@ -22,9 +22,22 @@ class DiscordUser(AbstractUser):
)
@property
def avatar_url(self):
def avatar_url(self) -> str:
return f"https://cdn.discordapp.com/avatars/{self.discord_id}/{self.avatar_id}.png"
@property
def plays(self) -> bool:
return Player.objects.filter(user=self).exists()
@property
def role(self):
if self.plays:
return self.player._meta.verbose_name
elif self.is_superuser:
return _("admin")
else:
return _("spectator")
class Player(PolymorphicModel):
user = models.OneToOneField(

8
lg/urls.py Normal file
View File

@ -0,0 +1,8 @@
from django.urls import path
from lg import views
app_name = 'lg'
urlpatterns = [
path('new_player', views.NewPlayerView.as_view()),
]

View File

@ -1,3 +1,13 @@
from django.shortcuts import render
from django.contrib.auth.mixins import LoginRequiredMixin
from django.views.generic import FormView
# Create your views here.
from lg.forms import PlayerForm
class NewPlayerView(LoginRequiredMixin, FormView):
form_class = PlayerForm
template_name = "lg/new_payer.html"
def form_valid(self, form):
user = form.cleaned_data["user"]
class_name

View File

@ -5,5 +5,5 @@
{% block title %}{% trans "Index" %}{% endblock %}
{% block content %}
Historique de loup-garou
Votre rôle : {{ user.role }}
{% endblock %}

View File

@ -0,0 +1,11 @@
{% extends "base.html" %}
{% load crispy_forms_filters %}
{% block content %}
<form method="post">
{% csrf_token %}
{{ form|crispy }}
<input class="btn btn-success" type="submit">
</form>
{% endblock %}

View File

@ -10,4 +10,6 @@ urlpatterns = [
path('i18n/', include('django.conf.urls.i18n')),
path('accounts/login/', LoginView.as_view()),
path('accounts/', include('django.contrib.auth.urls')),
path('lg/', include('lg.urls'))
]