2017-08-16 18:17:27 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
from django import forms
|
2022-03-08 11:55:50 +00:00
|
|
|
from django.forms import widgets
|
2017-11-19 01:57:29 +00:00
|
|
|
from django.conf import settings
|
2019-04-14 05:51:44 +00:00
|
|
|
from django.utils import timezone
|
2023-10-09 13:40:51 +00:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
2017-08-16 18:17:27 +00:00
|
|
|
|
2022-04-16 21:59:28 +00:00
|
|
|
from taggit.forms import TagField
|
|
|
|
|
2023-10-21 18:16:08 +00:00
|
|
|
from babybuddy.widgets import DateInput, DateTimeInput, TimeInput
|
2017-11-10 00:50:54 +00:00
|
|
|
from core import models
|
2024-01-27 17:32:51 +00:00
|
|
|
from core.models import Timer
|
2024-02-06 06:05:09 +00:00
|
|
|
from core.widgets import TagsEditor, ChildRadioSelect, PillRadioSelect
|
2017-08-16 18:17:27 +00:00
|
|
|
|
2022-02-27 19:00:12 +00:00
|
|
|
|
2020-01-29 18:50:23 +00:00
|
|
|
def set_initial_values(kwargs, form_type):
|
2020-01-29 17:45:26 +00:00
|
|
|
"""
|
2020-01-29 18:50:23 +00:00
|
|
|
Sets initial value for add forms based on provided kwargs.
|
2020-01-29 17:45:26 +00:00
|
|
|
|
2020-01-29 18:50:23 +00:00
|
|
|
:param kwargs: Keyword arguments.
|
|
|
|
:param form_type: Class of the type of form being initialized.
|
|
|
|
:return: Keyword arguments with updated "initial" values.
|
2020-01-29 17:45:26 +00:00
|
|
|
"""
|
|
|
|
|
2020-01-29 18:50:23 +00:00
|
|
|
# Never update initial values for existing instance (e.g. edit operation).
|
2022-02-10 00:00:30 +00:00
|
|
|
if kwargs.get("instance", None):
|
2020-01-29 18:50:23 +00:00
|
|
|
return kwargs
|
2020-01-29 17:45:26 +00:00
|
|
|
|
2020-01-29 18:50:23 +00:00
|
|
|
# Add the "initial" kwarg if it does not already exist.
|
2022-02-10 00:00:30 +00:00
|
|
|
if not kwargs.get("initial"):
|
2017-08-18 04:42:37 +00:00
|
|
|
kwargs.update(initial={})
|
2020-01-29 17:45:26 +00:00
|
|
|
|
2020-01-29 18:50:23 +00:00
|
|
|
# Set Child based on `child` kwarg or single Chile database.
|
2022-02-10 00:00:30 +00:00
|
|
|
child_slug = kwargs.get("child", None)
|
2020-01-29 18:50:23 +00:00
|
|
|
if child_slug:
|
2022-02-10 00:00:30 +00:00
|
|
|
kwargs["initial"].update(
|
|
|
|
{
|
|
|
|
"child": models.Child.objects.filter(slug=child_slug).first(),
|
|
|
|
}
|
|
|
|
)
|
2020-01-29 18:50:23 +00:00
|
|
|
elif models.Child.count() == 1:
|
2022-02-10 00:00:30 +00:00
|
|
|
kwargs["initial"].update({"child": models.Child.objects.first()})
|
2020-01-29 18:50:23 +00:00
|
|
|
|
|
|
|
# Set start and end time based on Timer from `timer` kwarg.
|
2022-02-10 00:00:30 +00:00
|
|
|
timer_id = kwargs.get("timer", None)
|
2020-01-29 18:50:23 +00:00
|
|
|
if timer_id:
|
2024-01-27 17:32:51 +00:00
|
|
|
try:
|
|
|
|
timer = models.Timer.objects.get(id=timer_id)
|
|
|
|
kwargs["initial"].update(
|
|
|
|
{"timer": timer, "start": timer.start, "end": timezone.now()}
|
|
|
|
)
|
|
|
|
except Timer.DoesNotExist:
|
|
|
|
pass
|
2020-01-29 17:45:26 +00:00
|
|
|
|
2020-03-26 11:15:08 +00:00
|
|
|
# Set type and method values for Feeding instance based on last feed.
|
2022-02-10 00:00:30 +00:00
|
|
|
if form_type == FeedingForm and "child" in kwargs["initial"]:
|
|
|
|
last_feeding = (
|
|
|
|
models.Feeding.objects.filter(child=kwargs["initial"]["child"])
|
|
|
|
.order_by("end")
|
|
|
|
.last()
|
|
|
|
)
|
2020-01-29 18:50:23 +00:00
|
|
|
if last_feeding:
|
2021-05-31 23:58:37 +00:00
|
|
|
last_method = last_feeding.method
|
2022-02-10 00:00:30 +00:00
|
|
|
last_feed_args = {"type": last_feeding.type}
|
|
|
|
if last_method not in ["left breast", "right breast"]:
|
|
|
|
last_feed_args["method"] = last_method
|
|
|
|
kwargs["initial"].update(last_feed_args)
|
2017-08-18 00:59:55 +00:00
|
|
|
|
2023-05-07 22:10:50 +00:00
|
|
|
# Set default "nap" value for Sleep instances.
|
|
|
|
if form_type == SleepForm and "nap" not in kwargs["initial"]:
|
|
|
|
try:
|
|
|
|
start = timezone.localtime(kwargs["initial"]["start"]).time()
|
|
|
|
except KeyError:
|
|
|
|
start = timezone.localtime().time()
|
|
|
|
nap = (
|
|
|
|
models.Sleep.settings.nap_start_min
|
|
|
|
<= start
|
|
|
|
<= models.Sleep.settings.nap_start_max
|
|
|
|
)
|
|
|
|
kwargs["initial"].update({"nap": nap})
|
|
|
|
|
|
|
|
# Remove custom kwargs, so they do not interfere with `super` calls.
|
2022-02-10 00:00:30 +00:00
|
|
|
for key in ["child", "timer"]:
|
2020-01-29 18:50:23 +00:00
|
|
|
try:
|
|
|
|
kwargs.pop(key)
|
|
|
|
except KeyError:
|
|
|
|
pass
|
2017-08-18 00:59:55 +00:00
|
|
|
|
2018-03-14 02:49:21 +00:00
|
|
|
return kwargs
|
|
|
|
|
|
|
|
|
2020-01-29 18:50:23 +00:00
|
|
|
class CoreModelForm(forms.ModelForm):
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
# Set `timer_id` so the Timer can be stopped in the `save` method.
|
2022-02-10 00:00:30 +00:00
|
|
|
self.timer_id = kwargs.get("timer", None)
|
2020-01-29 18:50:23 +00:00
|
|
|
kwargs = set_initial_values(kwargs, type(self))
|
|
|
|
super(CoreModelForm, self).__init__(*args, **kwargs)
|
|
|
|
|
|
|
|
def save(self, commit=True):
|
|
|
|
# If `timer_id` is present, stop the Timer.
|
|
|
|
instance = super(CoreModelForm, self).save(commit=False)
|
|
|
|
if self.timer_id:
|
|
|
|
timer = models.Timer.objects.get(id=self.timer_id)
|
2022-08-14 20:55:57 +00:00
|
|
|
timer.stop()
|
2020-01-29 18:50:23 +00:00
|
|
|
if commit:
|
|
|
|
instance.save()
|
2022-02-15 14:46:07 +00:00
|
|
|
self.save_m2m()
|
2020-01-29 18:50:23 +00:00
|
|
|
return instance
|
|
|
|
|
2024-02-06 06:08:24 +00:00
|
|
|
@property
|
|
|
|
def hydrated_fielsets(self):
|
|
|
|
# for some reason self.fields returns defintions and not bound fields
|
|
|
|
# so until i figure out a better way we can just create a dict here
|
|
|
|
# https://github.com/django/django/blob/main/django/forms/forms.py#L52
|
|
|
|
|
|
|
|
bound_field_dict = {}
|
|
|
|
for field in self:
|
|
|
|
bound_field_dict[field.name] = field
|
|
|
|
|
|
|
|
hydrated_fieldsets = []
|
|
|
|
|
|
|
|
for fieldset in self.fieldsets:
|
|
|
|
hyrdrated_fieldset = {
|
2024-04-15 13:29:30 +00:00
|
|
|
"layout": fieldset.get("layout", "default"),
|
2024-02-06 06:08:24 +00:00
|
|
|
"layout_attrs": fieldset.get("layout_attrs", {}),
|
|
|
|
"fields": [],
|
|
|
|
}
|
|
|
|
for field_name in fieldset["fields"]:
|
|
|
|
hyrdrated_fieldset["fields"].append(bound_field_dict[field_name])
|
|
|
|
|
|
|
|
hydrated_fieldsets.append(hyrdrated_fieldset)
|
|
|
|
|
|
|
|
return hydrated_fieldsets
|
|
|
|
|
2020-01-29 18:50:23 +00:00
|
|
|
|
2024-04-15 13:34:12 +00:00
|
|
|
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}),
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-08-16 18:57:46 +00:00
|
|
|
class ChildForm(forms.ModelForm):
|
2017-08-16 18:17:27 +00:00
|
|
|
class Meta:
|
2017-11-10 00:50:54 +00:00
|
|
|
model = models.Child
|
2023-10-21 18:16:08 +00:00
|
|
|
fields = ["first_name", "last_name", "birth_date", "birth_time"]
|
2022-02-10 00:00:30 +00:00
|
|
|
if settings.BABY_BUDDY["ALLOW_UPLOADS"]:
|
|
|
|
fields.append("picture")
|
2017-08-16 18:17:27 +00:00
|
|
|
widgets = {
|
2022-08-14 19:34:32 +00:00
|
|
|
"birth_date": DateInput(),
|
2023-10-21 18:16:08 +00:00
|
|
|
"birth_time": TimeInput(),
|
2017-08-16 18:17:27 +00:00
|
|
|
}
|
2017-08-16 18:57:46 +00:00
|
|
|
|
|
|
|
|
2017-11-01 00:49:10 +00:00
|
|
|
class ChildDeleteForm(forms.ModelForm):
|
|
|
|
confirm_name = forms.CharField(max_length=511)
|
|
|
|
|
|
|
|
class Meta:
|
2017-11-10 00:50:54 +00:00
|
|
|
model = models.Child
|
2017-11-01 00:49:10 +00:00
|
|
|
fields = []
|
|
|
|
|
|
|
|
def clean_confirm_name(self):
|
2022-02-10 00:00:30 +00:00
|
|
|
confirm_name = self.cleaned_data["confirm_name"]
|
2017-11-01 00:49:10 +00:00
|
|
|
if confirm_name != str(self.instance):
|
2017-11-01 20:14:42 +00:00
|
|
|
raise forms.ValidationError(
|
2022-02-10 00:00:30 +00:00
|
|
|
_("Name does not match child name."), code="confirm_mismatch"
|
|
|
|
)
|
2017-11-01 00:49:10 +00:00
|
|
|
return confirm_name
|
|
|
|
|
|
|
|
def save(self, commit=True):
|
|
|
|
instance = self.instance
|
|
|
|
self.instance.delete()
|
|
|
|
return instance
|
|
|
|
|
|
|
|
|
2022-04-16 21:59:28 +00:00
|
|
|
class DiaperChangeForm(CoreModelForm, TaggableModelForm):
|
2024-02-06 06:10:07 +00:00
|
|
|
fieldsets = [
|
2024-04-15 13:29:30 +00:00
|
|
|
{"fields": ["child", "time"], "layout": "required"},
|
2024-02-06 06:10:07 +00:00
|
|
|
{
|
|
|
|
"fields": ["wet", "solid"],
|
|
|
|
"layout": "choices",
|
|
|
|
"layout_attrs": {"label": "Contents"},
|
|
|
|
},
|
2024-04-15 13:29:30 +00:00
|
|
|
{"fields": ["color", "amount"]},
|
2024-02-06 06:10:07 +00:00
|
|
|
{"layout": "advanced", "fields": ["notes", "tags"]},
|
|
|
|
]
|
|
|
|
|
2017-08-16 18:57:46 +00:00
|
|
|
class Meta:
|
2017-11-10 00:50:54 +00:00
|
|
|
model = models.DiaperChange
|
2022-07-07 11:41:35 +00:00
|
|
|
fields = ["child", "time", "wet", "solid", "color", "amount", "notes", "tags"]
|
2017-08-16 18:57:46 +00:00
|
|
|
widgets = {
|
2022-07-06 19:39:37 +00:00
|
|
|
"child": ChildRadioSelect(),
|
2022-08-14 17:37:02 +00:00
|
|
|
"time": DateTimeInput(),
|
2022-02-10 00:00:30 +00:00
|
|
|
"notes": forms.Textarea(attrs={"rows": 5}),
|
2017-08-16 18:57:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-04-16 21:59:28 +00:00
|
|
|
class FeedingForm(CoreModelForm, TaggableModelForm):
|
2024-02-07 07:18:45 +00:00
|
|
|
fieldsets = [
|
2024-04-15 13:29:30 +00:00
|
|
|
{"fields": ["child", "start", "end", "type", "method"], "layout": "required"},
|
|
|
|
{"fields": ["amount"]},
|
|
|
|
{"fields": ["notes", "tags"], "layout": "advanced"},
|
2024-02-07 07:18:45 +00:00
|
|
|
]
|
|
|
|
|
2017-08-16 18:57:46 +00:00
|
|
|
class Meta:
|
2017-11-10 00:50:54 +00:00
|
|
|
model = models.Feeding
|
2022-07-07 11:41:35 +00:00
|
|
|
fields = ["child", "start", "end", "type", "method", "amount", "notes", "tags"]
|
2017-08-16 18:57:46 +00:00
|
|
|
widgets = {
|
2022-07-02 14:49:21 +00:00
|
|
|
"child": ChildRadioSelect,
|
2022-08-14 17:37:02 +00:00
|
|
|
"start": DateTimeInput(),
|
|
|
|
"end": DateTimeInput(),
|
2024-02-07 07:18:45 +00:00
|
|
|
"type": PillRadioSelect(),
|
|
|
|
"method": PillRadioSelect(),
|
2022-02-10 00:00:30 +00:00
|
|
|
"notes": forms.Textarea(attrs={"rows": 5}),
|
2017-08-16 18:57:46 +00:00
|
|
|
}
|
|
|
|
|
2017-08-18 00:59:55 +00:00
|
|
|
|
2024-04-15 13:34:12 +00:00
|
|
|
class HeadCircumferenceForm(CoreModelForm, TaggableModelForm):
|
2024-02-06 06:10:07 +00:00
|
|
|
fieldsets = [
|
2024-04-15 13:34:12 +00:00
|
|
|
{
|
|
|
|
"fields": ["child", "head_circumference", "date"],
|
|
|
|
"layout": "required",
|
|
|
|
},
|
2024-04-15 13:29:30 +00:00
|
|
|
{"fields": ["notes", "tags"], "layout": "advanced"},
|
2024-02-06 06:10:07 +00:00
|
|
|
]
|
|
|
|
|
2024-04-15 13:34:12 +00:00
|
|
|
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"},
|
|
|
|
]
|
2024-01-26 09:28:24 +00:00
|
|
|
|
|
|
|
class Meta:
|
2024-04-15 13:34:12 +00:00
|
|
|
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": ["notes", "tags"], "layout": "advanced"},
|
|
|
|
]
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = models.Pumping
|
|
|
|
fields = ["child", "start", "end", "amount", "notes", "tags"]
|
2024-01-26 09:28:24 +00:00
|
|
|
widgets = {
|
|
|
|
"child": ChildRadioSelect,
|
|
|
|
"start": DateTimeInput(),
|
2024-04-15 13:34:12 +00:00
|
|
|
"end": DateTimeInput(),
|
2024-01-26 09:28:24 +00:00
|
|
|
"notes": forms.Textarea(attrs={"rows": 5}),
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-04-16 21:59:28 +00:00
|
|
|
class NoteForm(CoreModelForm, TaggableModelForm):
|
2017-11-10 00:50:54 +00:00
|
|
|
class Meta:
|
|
|
|
model = models.Note
|
2022-02-15 09:13:35 +00:00
|
|
|
fields = ["child", "note", "time", "tags"]
|
2023-10-20 23:59:37 +00:00
|
|
|
if settings.BABY_BUDDY["ALLOW_UPLOADS"]:
|
|
|
|
fields.insert(2, "image")
|
2020-08-13 02:47:58 +00:00
|
|
|
widgets = {
|
2022-07-06 19:39:37 +00:00
|
|
|
"child": ChildRadioSelect,
|
2022-08-14 17:37:02 +00:00
|
|
|
"time": DateTimeInput(),
|
2020-08-13 02:47:58 +00:00
|
|
|
}
|
2017-11-10 00:50:54 +00:00
|
|
|
|
|
|
|
|
2022-04-16 21:59:28 +00:00
|
|
|
class SleepForm(CoreModelForm, TaggableModelForm):
|
2024-02-07 07:25:41 +00:00
|
|
|
fieldsets = [
|
|
|
|
{
|
|
|
|
"fields": ["child", "start", "end", "nap"],
|
|
|
|
"layout": "required",
|
|
|
|
},
|
2024-04-15 13:29:30 +00:00
|
|
|
{"fields": ["notes", "tags"], "layout": "advanced"},
|
2024-02-07 07:25:41 +00:00
|
|
|
]
|
|
|
|
|
2017-08-16 18:57:46 +00:00
|
|
|
class Meta:
|
2017-11-10 00:50:54 +00:00
|
|
|
model = models.Sleep
|
2023-05-07 22:10:50 +00:00
|
|
|
fields = ["child", "start", "end", "nap", "notes", "tags"]
|
2017-08-16 18:57:46 +00:00
|
|
|
widgets = {
|
2022-07-06 19:39:37 +00:00
|
|
|
"child": ChildRadioSelect,
|
2022-08-14 17:37:02 +00:00
|
|
|
"start": DateTimeInput(),
|
|
|
|
"end": DateTimeInput(),
|
2022-02-10 00:00:30 +00:00
|
|
|
"notes": forms.Textarea(attrs={"rows": 5}),
|
2017-08-16 18:57:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-15 13:34:12 +00:00
|
|
|
class TagAdminForm(forms.ModelForm):
|
|
|
|
class Meta:
|
|
|
|
widgets = {"color": widgets.TextInput(attrs={"type": "color"})}
|
|
|
|
|
|
|
|
|
2022-04-16 21:59:28 +00:00
|
|
|
class TemperatureForm(CoreModelForm, TaggableModelForm):
|
2024-02-07 07:25:41 +00:00
|
|
|
fieldsets = [
|
|
|
|
{
|
|
|
|
"fields": ["child", "temperature", "time"],
|
|
|
|
"layout": "required",
|
|
|
|
},
|
2024-04-15 13:29:30 +00:00
|
|
|
{"fields": ["notes", "tags"], "layout": "advanced"},
|
2024-02-07 07:25:41 +00:00
|
|
|
]
|
|
|
|
|
2019-05-17 04:33:26 +00:00
|
|
|
class Meta:
|
|
|
|
model = models.Temperature
|
2022-03-08 12:44:35 +00:00
|
|
|
fields = ["child", "temperature", "time", "notes", "tags"]
|
2019-05-17 04:33:26 +00:00
|
|
|
widgets = {
|
2022-07-06 19:39:37 +00:00
|
|
|
"child": ChildRadioSelect,
|
2022-08-14 17:37:02 +00:00
|
|
|
"time": DateTimeInput(),
|
2022-02-10 00:00:30 +00:00
|
|
|
"notes": forms.Textarea(attrs={"rows": 5}),
|
2019-05-17 04:33:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-01-29 18:50:23 +00:00
|
|
|
class TimerForm(CoreModelForm):
|
2017-08-17 01:57:01 +00:00
|
|
|
class Meta:
|
2017-11-10 00:50:54 +00:00
|
|
|
model = models.Timer
|
2022-02-10 00:00:30 +00:00
|
|
|
fields = ["child", "name", "start"]
|
2017-10-28 17:27:33 +00:00
|
|
|
widgets = {
|
2022-07-06 19:39:37 +00:00
|
|
|
"child": ChildRadioSelect,
|
2022-08-14 17:37:02 +00:00
|
|
|
"start": DateTimeInput(),
|
2017-10-28 17:27:33 +00:00
|
|
|
}
|
2017-08-17 01:57:01 +00:00
|
|
|
|
2017-08-18 00:42:47 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
2022-02-10 00:00:30 +00:00
|
|
|
self.user = kwargs.pop("user")
|
2017-08-18 00:42:47 +00:00
|
|
|
super(TimerForm, self).__init__(*args, **kwargs)
|
|
|
|
|
|
|
|
def save(self, commit=True):
|
|
|
|
instance = super(TimerForm, self).save(commit=False)
|
2017-09-10 13:50:16 +00:00
|
|
|
instance.user = self.user
|
2017-08-18 00:42:47 +00:00
|
|
|
instance.save()
|
|
|
|
return instance
|
|
|
|
|
2017-08-17 01:57:01 +00:00
|
|
|
|
2022-04-16 21:59:28 +00:00
|
|
|
class TummyTimeForm(CoreModelForm, TaggableModelForm):
|
2024-02-07 07:25:41 +00:00
|
|
|
fieldsets = [
|
2024-04-15 13:29:30 +00:00
|
|
|
{"fields": ["child", "start", "end"], "layout": "required"},
|
|
|
|
{"fields": ["milestone"]},
|
|
|
|
{"fields": ["tags"], "layout": "advanced"},
|
2024-02-07 07:25:41 +00:00
|
|
|
]
|
|
|
|
|
2017-08-16 18:57:46 +00:00
|
|
|
class Meta:
|
2017-11-10 00:50:54 +00:00
|
|
|
model = models.TummyTime
|
2022-03-08 12:44:35 +00:00
|
|
|
fields = ["child", "start", "end", "milestone", "tags"]
|
2017-08-16 18:57:46 +00:00
|
|
|
widgets = {
|
2022-07-06 19:39:37 +00:00
|
|
|
"child": ChildRadioSelect,
|
2022-08-14 17:37:02 +00:00
|
|
|
"start": DateTimeInput(),
|
|
|
|
"end": DateTimeInput(),
|
2017-08-16 18:57:46 +00:00
|
|
|
}
|
2017-08-18 00:59:55 +00:00
|
|
|
|
2017-11-10 02:15:09 +00:00
|
|
|
|
2022-04-16 21:59:28 +00:00
|
|
|
class WeightForm(CoreModelForm, TaggableModelForm):
|
2024-02-07 07:25:41 +00:00
|
|
|
fieldsets = [
|
|
|
|
{
|
|
|
|
"fields": ["child", "weight", "date"],
|
|
|
|
"layout": "required",
|
|
|
|
},
|
2024-04-15 13:29:30 +00:00
|
|
|
{"fields": ["notes", "tags"], "layout": "advanced"},
|
2024-02-07 07:25:41 +00:00
|
|
|
]
|
|
|
|
|
2017-11-10 02:15:09 +00:00
|
|
|
class Meta:
|
|
|
|
model = models.Weight
|
2022-03-08 12:44:35 +00:00
|
|
|
fields = ["child", "weight", "date", "notes", "tags"]
|
2017-11-10 02:15:09 +00:00
|
|
|
widgets = {
|
2022-07-06 19:39:37 +00:00
|
|
|
"child": ChildRadioSelect,
|
2022-08-14 19:34:32 +00:00
|
|
|
"date": DateInput(),
|
2022-02-10 00:00:30 +00:00
|
|
|
"notes": forms.Textarea(attrs={"rows": 5}),
|
2017-11-10 02:15:09 +00:00
|
|
|
}
|