parent
546e936f27
commit
b4fd13a897
17
lg/forms.py
17
lg/forms.py
|
@ -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):
|
||||
|
|
15
lg/models.py
15
lg/models.py
|
@ -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(
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
from django.urls import path
|
||||
|
||||
from lg import views
|
||||
|
||||
app_name = 'lg'
|
||||
urlpatterns = [
|
||||
path('new_player', views.NewPlayerView.as_view()),
|
||||
]
|
14
lg/views.py
14
lg/views.py
|
@ -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
|
||||
|
|
|
@ -5,5 +5,5 @@
|
|||
{% block title %}{% trans "Index" %}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
Historique de loup-garou
|
||||
Votre rôle : {{ user.role }}
|
||||
{% endblock %}
|
||||
|
|
|
@ -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 %}
|
|
@ -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'))
|
||||
]
|
||||
|
|
Loading…
Reference in New Issue