Verified Commit b4fd13a8 authored by ynerant's avatar ynerant
Browse files

stash


Signed-off-by: ynerant's avatarYohann D'ANELLO <ynerant@crans.org>
parent 546e936f
Pipeline #5566 failed with stages
in 1 minute and 43 seconds
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):
......
......@@ -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(
......
from django.urls import path
from lg import views
app_name = 'lg'
urlpatterns = [
path('new_player', views.NewPlayerView.as_view()),
]
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 %}
{% 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'))
]
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment