71 lines
1.8 KiB
Python
71 lines
1.8 KiB
Python
from django import forms
|
|
from django.utils.translation import gettext_lazy as _
|
|
|
|
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):
|
|
_forms_per_model = dict()
|
|
|
|
def __init_subclass__(cls):
|
|
ActionForm._forms_per_model[cls.Meta.model] = cls
|
|
return super().__init_subclass__()
|
|
|
|
@staticmethod
|
|
def get_form_class(model_class):
|
|
return ActionForm._forms_per_model.get(model_class, ActionForm)
|
|
|
|
class Meta:
|
|
model = Action
|
|
exclude = ('player', 'night',)
|
|
|
|
|
|
class WerewolfActionForm(ActionForm):
|
|
class Meta:
|
|
model = WerewolfAction
|
|
exclude = ('player', 'night',)
|
|
|
|
|
|
class CupidonActionForm(ActionForm):
|
|
class Meta:
|
|
model = CupidonAction
|
|
exclude = ('player', 'night',)
|
|
|
|
|
|
class WitchActionForm(ActionForm):
|
|
class Meta:
|
|
model = WitchAction
|
|
exclude = ('player', 'night',)
|
|
|
|
|
|
class RavenActionForm(ActionForm):
|
|
class Meta:
|
|
model = RavenAction
|
|
exclude = ('player', 'night',)
|
|
|
|
|
|
class DoveActionForm(ActionForm):
|
|
class Meta:
|
|
model = DoveAction
|
|
exclude = ('player', 'night',)
|
|
|
|
|
|
class HackerActionForm(ActionForm):
|
|
class Meta:
|
|
model = HackerAction
|
|
exclude = ('player', 'night',)
|