2023-06-10 20:32:45 +00:00
|
|
|
from django import forms
|
2023-08-25 19:42:46 +00:00
|
|
|
from guild.models import NPC, PlaySession, Character, Reward
|
2023-06-19 18:01:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
class PlaySessionCharacterForm(forms.ModelMultipleChoiceField):
|
|
|
|
def label_from_instance(self, character):
|
|
|
|
if character.player:
|
|
|
|
return "{} ({})".format(character.name, character.player.name)
|
|
|
|
else:
|
|
|
|
return character.name
|
2023-06-10 20:32:45 +00:00
|
|
|
|
|
|
|
|
2023-08-25 19:42:46 +00:00
|
|
|
class PlaySessionNPCForm(forms.ModelMultipleChoiceField):
|
|
|
|
def label_from_instance(self, npc):
|
|
|
|
return npc.name
|
|
|
|
|
|
|
|
|
2023-06-10 20:32:45 +00:00
|
|
|
class PlaySessionForm(forms.ModelForm):
|
2023-06-19 18:01:33 +00:00
|
|
|
characters = PlaySessionCharacterForm(
|
|
|
|
queryset=Character.objects.all(), widget=forms.CheckboxSelectMultiple
|
|
|
|
)
|
2023-08-25 19:42:46 +00:00
|
|
|
npcs = PlaySessionNPCForm(
|
|
|
|
queryset=NPC.objects.all(), widget=forms.CheckboxSelectMultiple, required=False
|
|
|
|
)
|
2023-06-19 18:01:33 +00:00
|
|
|
|
2023-06-10 20:32:45 +00:00
|
|
|
class Meta:
|
|
|
|
model = PlaySession
|
2023-08-25 19:42:46 +00:00
|
|
|
fields = ["date", "characters", "summary", "npcs"]
|
2023-06-10 20:32:45 +00:00
|
|
|
# set date wideget to type="date"
|
|
|
|
widgets = {
|
|
|
|
"date": forms.DateInput(attrs={"type": "date"}),
|
2023-06-13 20:09:25 +00:00
|
|
|
"summary": forms.Textarea(attrs={"rows": 32}),
|
2023-06-10 20:32:45 +00:00
|
|
|
}
|
2023-06-20 19:22:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
class RewardForm(forms.ModelForm):
|
|
|
|
character = forms.ModelChoiceField(
|
|
|
|
queryset=Character.objects.all(),
|
|
|
|
empty_label="All Guild Members",
|
|
|
|
required=False,
|
|
|
|
)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Reward
|
|
|
|
fields = ["amount", "resource", "character"]
|