Alpha sort core form classes

This commit is contained in:
Chris Wells 2024-04-15 13:34:12 +00:00 committed by Christopher Charbonneau Wells
parent 041a03df0d
commit fcc6a79924
1 changed files with 103 additions and 103 deletions

View File

@ -133,6 +133,61 @@ class CoreModelForm(forms.ModelForm):
return hydrated_fieldsets return hydrated_fieldsets
class TaggableModelForm(forms.ModelForm):
tags = TagField(
widget=TagsEditor,
required=False,
strip=True,
help_text=_(
"Click on the tags to add (+) or remove (-) tags or use the text editor to create new tags."
),
)
class BMIForm(CoreModelForm, TaggableModelForm):
fieldsets = [
{
"fields": ["child", "bmi", "date"],
"layout": "required",
},
{"fields": ["notes", "tags"], "layout": "advanced"},
]
class Meta:
model = models.BMI
fields = ["child", "bmi", "date", "notes", "tags"]
widgets = {
"child": ChildRadioSelect,
"date": DateInput(),
"notes": forms.Textarea(attrs={"rows": 5}),
}
class BottleFeedingForm(CoreModelForm, TaggableModelForm):
fieldsets = [
{"fields": ["child", "type", "start", "amount"], "layout": "required"},
{"fields": ["amount"]},
{"fields": ["notes", "tags"], "layout": "advanced"},
]
def save(self):
instance = super(BottleFeedingForm, self).save(commit=False)
instance.method = "bottle"
instance.end = instance.start
instance.save()
return instance
class Meta:
model = models.Feeding
fields = ["child", "start", "type", "amount", "notes", "tags"]
widgets = {
"child": ChildRadioSelect,
"start": DateTimeInput(),
"type": PillRadioSelect(),
"notes": forms.Textarea(attrs={"rows": 5}),
}
class ChildForm(forms.ModelForm): class ChildForm(forms.ModelForm):
class Meta: class Meta:
model = models.Child model = models.Child
@ -166,35 +221,6 @@ class ChildDeleteForm(forms.ModelForm):
return instance return instance
class TaggableModelForm(forms.ModelForm):
tags = TagField(
widget=TagsEditor,
required=False,
strip=True,
help_text=_(
"Click on the tags to add (+) or remove (-) tags or use the text editor to create new tags."
),
)
class PumpingForm(CoreModelForm, TaggableModelForm):
fieldsets = [
{"fields": ["child", "start", "end"], "layout": "required"},
{"fields": ["amount"]},
{"fields": ["notes", "tags"], "layout": "advanced"},
]
class Meta:
model = models.Pumping
fields = ["child", "start", "end", "amount", "notes", "tags"]
widgets = {
"child": ChildRadioSelect,
"start": DateTimeInput(),
"end": DateTimeInput(),
"notes": forms.Textarea(attrs={"rows": 5}),
}
class DiaperChangeForm(CoreModelForm, TaggableModelForm): class DiaperChangeForm(CoreModelForm, TaggableModelForm):
fieldsets = [ fieldsets = [
{"fields": ["child", "time"], "layout": "required"}, {"fields": ["child", "time"], "layout": "required"},
@ -237,27 +263,58 @@ class FeedingForm(CoreModelForm, TaggableModelForm):
} }
class BottleFeedingForm(CoreModelForm, TaggableModelForm): class HeadCircumferenceForm(CoreModelForm, TaggableModelForm):
fieldsets = [ fieldsets = [
{"fields": ["child", "type", "start", "amount"], "layout": "required"}, {
"fields": ["child", "head_circumference", "date"],
"layout": "required",
},
{"fields": ["notes", "tags"], "layout": "advanced"},
]
class Meta:
model = models.HeadCircumference
fields = ["child", "head_circumference", "date", "notes", "tags"]
widgets = {
"child": ChildRadioSelect,
"date": DateInput(),
"notes": forms.Textarea(attrs={"rows": 5}),
}
class HeightForm(CoreModelForm, TaggableModelForm):
fieldsets = [
{
"fields": ["child", "height", "date"],
"layout": "required",
},
{"fields": ["notes", "tags"], "layout": "advanced"},
]
class Meta:
model = models.Height
fields = ["child", "height", "date", "notes", "tags"]
widgets = {
"child": ChildRadioSelect,
"date": DateInput(),
"notes": forms.Textarea(attrs={"rows": 5}),
}
class PumpingForm(CoreModelForm, TaggableModelForm):
fieldsets = [
{"fields": ["child", "start", "end"], "layout": "required"},
{"fields": ["amount"]}, {"fields": ["amount"]},
{"fields": ["notes", "tags"], "layout": "advanced"}, {"fields": ["notes", "tags"], "layout": "advanced"},
] ]
def save(self):
instance = super(BottleFeedingForm, self).save(commit=False)
instance.method = "bottle"
instance.end = instance.start
instance.save()
return instance
class Meta: class Meta:
model = models.Feeding model = models.Pumping
fields = ["child", "start", "type", "amount", "notes", "tags"] fields = ["child", "start", "end", "amount", "notes", "tags"]
widgets = { widgets = {
"child": ChildRadioSelect, "child": ChildRadioSelect,
"start": DateTimeInput(), "start": DateTimeInput(),
"type": PillRadioSelect(), "end": DateTimeInput(),
"notes": forms.Textarea(attrs={"rows": 5}), "notes": forms.Textarea(attrs={"rows": 5}),
} }
@ -294,6 +351,11 @@ class SleepForm(CoreModelForm, TaggableModelForm):
} }
class TagAdminForm(forms.ModelForm):
class Meta:
widgets = {"color": widgets.TextInput(attrs={"type": "color"})}
class TemperatureForm(CoreModelForm, TaggableModelForm): class TemperatureForm(CoreModelForm, TaggableModelForm):
fieldsets = [ fieldsets = [
{ {
@ -367,65 +429,3 @@ class WeightForm(CoreModelForm, TaggableModelForm):
"date": DateInput(), "date": DateInput(),
"notes": forms.Textarea(attrs={"rows": 5}), "notes": forms.Textarea(attrs={"rows": 5}),
} }
class HeightForm(CoreModelForm, TaggableModelForm):
fieldsets = [
{
"fields": ["child", "height", "date"],
"layout": "required",
},
{"fields": ["notes", "tags"], "layout": "advanced"},
]
class Meta:
model = models.Height
fields = ["child", "height", "date", "notes", "tags"]
widgets = {
"child": ChildRadioSelect,
"date": DateInput(),
"notes": forms.Textarea(attrs={"rows": 5}),
}
class HeadCircumferenceForm(CoreModelForm, TaggableModelForm):
fieldsets = [
{
"fields": ["child", "head_circumference", "date"],
"layout": "required",
},
{"fields": ["notes", "tags"], "layout": "advanced"},
]
class Meta:
model = models.HeadCircumference
fields = ["child", "head_circumference", "date", "notes", "tags"]
widgets = {
"child": ChildRadioSelect,
"date": DateInput(),
"notes": forms.Textarea(attrs={"rows": 5}),
}
class BMIForm(CoreModelForm, TaggableModelForm):
fieldsets = [
{
"fields": ["child", "bmi", "date"],
"layout": "required",
},
{"fields": ["notes", "tags"], "layout": "advanced"},
]
class Meta:
model = models.BMI
fields = ["child", "bmi", "date", "notes", "tags"]
widgets = {
"child": ChildRadioSelect,
"date": DateInput(),
"notes": forms.Textarea(attrs={"rows": 5}),
}
class TagAdminForm(forms.ModelForm):
class Meta:
widgets = {"color": widgets.TextInput(attrs={"type": "color"})}