Linting and faker changes

This commit is contained in:
Yulian Kuncheff 2021-12-29 19:32:55 -08:00 committed by Christopher Charbonneau Wells
parent 9b604627a1
commit 0af4521005
11 changed files with 82 additions and 21 deletions

View File

@ -174,17 +174,20 @@ class WeightSerializer(CoreModelSerializer):
model = models.Weight model = models.Weight
fields = ('id', 'child', 'weight', 'date', 'notes') fields = ('id', 'child', 'weight', 'date', 'notes')
class HeightSerializer(CoreModelSerializer): class HeightSerializer(CoreModelSerializer):
class Meta: class Meta:
model = models.Height model = models.Height
fields = ('id', 'child', 'height', 'date', 'notes') fields = ('id', 'child', 'height', 'date', 'notes')
class HeadCircumferenceSerializer(CoreModelSerializer): class HeadCircumferenceSerializer(CoreModelSerializer):
class Meta: class Meta:
model = models.HeadCircumference model = models.HeadCircumference
fields = ('id', 'child', 'head_circumference', 'date', 'notes') fields = ('id', 'child', 'head_circumference', 'date', 'notes')
class BMISerializer(CoreModelSerializer): class BMISerializer(CoreModelSerializer):
class Meta: class Meta:
model = models.BMI model = models.BMI
fields = ('id', 'child', 'bmi', 'date', 'notes') fields = ('id', 'child', 'bmi', 'date', 'notes')

View File

@ -61,16 +61,19 @@ class WeightViewSet(viewsets.ModelViewSet):
serializer_class = serializers.WeightSerializer serializer_class = serializers.WeightSerializer
filterset_fields = ('child', 'date') filterset_fields = ('child', 'date')
class HeightViewSet(viewsets.ModelViewSet): class HeightViewSet(viewsets.ModelViewSet):
queryset = models.Height.objects.all() queryset = models.Height.objects.all()
serializer_class = serializers.HeightSerializer serializer_class = serializers.HeightSerializer
filterset_fields = ('child', 'date') filterset_fields = ('child', 'date')
class HeadCircumferenceViewSet(viewsets.ModelViewSet): class HeadCircumferenceViewSet(viewsets.ModelViewSet):
queryset = models.HeadCircumference.objects.all() queryset = models.HeadCircumference.objects.all()
serializer_class = serializers.HeadCircumferenceSerializer serializer_class = serializers.HeadCircumferenceSerializer
filterset_fields = ('child', 'date') filterset_fields = ('child', 'date')
class BMIViewSet(viewsets.ModelViewSet): class BMIViewSet(viewsets.ModelViewSet):
queryset = models.BMI.objects.all() queryset = models.BMI.objects.all()
serializer_class = serializers.BMISerializer serializer_class = serializers.BMISerializer

View File

@ -74,6 +74,18 @@ class Command(BaseCommand):
self._add_weight_entry() self._add_weight_entry()
last_weight_entry_time = self.time last_weight_entry_time = self.time
self.height = round(uniform(8.0, 12.0), 2)
self._add_height_entry()
last_height_entry_time = self.time
self.head_circumference = round(uniform(8.0, 12.0), 2)
self._add_head_circumference_entry()
last_head_circumference_entry_time = self.time
self.bmi = round(uniform(8.0, 12.0), 2)
self._add_bmi_entry()
last_bmi_entry_time = self.time
self._add_note_entry() self._add_note_entry()
while self.time < self.time_now: while self.time < self.time_now:
self._add_sleep_entry() self._add_sleep_entry()
@ -91,6 +103,15 @@ class Command(BaseCommand):
if (self.time - last_weight_entry_time).days > 6: if (self.time - last_weight_entry_time).days > 6:
self._add_weight_entry() self._add_weight_entry()
last_weight_entry_time = self.time last_weight_entry_time = self.time
if (self.time - last_height_entry_time).days > 6:
self._add_height_entry()
last_height_entry_time = self.time
if (self.time - last_head_circumference_entry_time).days > 6:
self._add_head_circumference_entry()
last_head_circumference_entry_time = self.time
if (self.time - last_bmi_entry_time).days > 6:
self._add_bmi_entry()
last_bmi_entry_time = self.time
@transaction.atomic @transaction.atomic
def _add_diaperchange_entry(self): def _add_diaperchange_entry(self):
@ -268,7 +289,7 @@ class Command(BaseCommand):
date=self.time.date(), date=self.time.date(),
notes=notes notes=notes
).save() ).save()
@transaction.atomic @transaction.atomic
def _add_head_circumference_entry(self): def _add_head_circumference_entry(self):
""" """
@ -300,7 +321,7 @@ class Command(BaseCommand):
if choice([True, False, False, False]): if choice([True, False, False, False]):
notes = ' '.join(self.faker.sentences(randint(1, 5))) notes = ' '.join(self.faker.sentences(randint(1, 5)))
models.bmi.objects.create( models.BMI.objects.create(
child=self.child, child=self.child,
bmi=round(self.bmi, 2), bmi=round(self.bmi, 2),
date=self.time.date(), date=self.time.date(),

View File

@ -242,6 +242,7 @@ class WeightForm(CoreModelForm):
'notes': forms.Textarea(attrs={'rows': 5}), 'notes': forms.Textarea(attrs={'rows': 5}),
} }
class HeightForm(CoreModelForm): class HeightForm(CoreModelForm):
class Meta: class Meta:
model = models.Height model = models.Height
@ -254,6 +255,7 @@ class HeightForm(CoreModelForm):
'notes': forms.Textarea(attrs={'rows': 5}), 'notes': forms.Textarea(attrs={'rows': 5}),
} }
class HeadCircumferenceForm(CoreModelForm): class HeadCircumferenceForm(CoreModelForm):
class Meta: class Meta:
model = models.HeadCircumference model = models.HeadCircumference
@ -266,6 +268,7 @@ class HeadCircumferenceForm(CoreModelForm):
'notes': forms.Textarea(attrs={'rows': 5}), 'notes': forms.Textarea(attrs={'rows': 5}),
} }
class BMIForm(CoreModelForm): class BMIForm(CoreModelForm):
class Meta: class Meta:
model = models.BMI model = models.BMI
@ -276,4 +279,4 @@ class BMIForm(CoreModelForm):
'data-target': '#datetimepicker_date', 'data-target': '#datetimepicker_date',
}), }),
'notes': forms.Textarea(attrs={'rows': 5}), 'notes': forms.Textarea(attrs={'rows': 5}),
} }

View File

@ -592,6 +592,7 @@ class Weight(models.Model):
def clean(self): def clean(self):
validate_date(self.date, 'date') validate_date(self.date, 'date')
class Height(models.Model): class Height(models.Model):
model_name = 'height' model_name = 'height'
child = models.ForeignKey( child = models.ForeignKey(
@ -626,6 +627,7 @@ class Height(models.Model):
def clean(self): def clean(self):
validate_date(self.date, 'date') validate_date(self.date, 'date')
class HeadCircumference(models.Model): class HeadCircumference(models.Model):
model_name = 'head_circumference' model_name = 'head_circumference'
child = models.ForeignKey( child = models.ForeignKey(
@ -660,6 +662,7 @@ class HeadCircumference(models.Model):
def clean(self): def clean(self):
validate_date(self.date, 'date') validate_date(self.date, 'date')
class BMI(models.Model): class BMI(models.Model):
model_name = 'bmi' model_name = 'bmi'
child = models.ForeignKey( child = models.ForeignKey(
@ -692,4 +695,4 @@ class BMI(models.Model):
return str(_('BMI')) return str(_('BMI'))
def clean(self): def clean(self):
validate_date(self.date, 'date') validate_date(self.date, 'date')

View File

@ -172,8 +172,16 @@ urlpatterns = [
name='height-delete' name='height-delete'
), ),
path('head-circumference/', views.HeadCircumferenceList.as_view(), name='head-circumference-list'), path(
path('head-circumference/add/', views.HeadCircumferenceAdd.as_view(), name='head-circumference-add'), 'head-circumference/',
views.HeadCircumferenceList.as_view(),
name='head-circumference-list'
),
path(
'head-circumference/add/',
views.HeadCircumferenceAdd.as_view(),
name='head-circumference-add'
),
path( path(
'head-circumference/<int:pk>/', 'head-circumference/<int:pk>/',
views.HeadCircumferenceUpdate.as_view(), views.HeadCircumferenceUpdate.as_view(),

View File

@ -470,6 +470,7 @@ class WeightDelete(CoreDeleteView):
permission_required = ('core.delete_weight',) permission_required = ('core.delete_weight',)
success_url = reverse_lazy('core:weight-list') success_url = reverse_lazy('core:weight-list')
class HeightList(PermissionRequiredMixin, BabyBuddyFilterView): class HeightList(PermissionRequiredMixin, BabyBuddyFilterView):
model = models.Height model = models.Height
template_name = 'core/height_list.html' template_name = 'core/height_list.html'
@ -497,6 +498,7 @@ class HeightDelete(CoreDeleteView):
permission_required = ('core.delete_height',) permission_required = ('core.delete_height',)
success_url = reverse_lazy('core:height-list') success_url = reverse_lazy('core:height-list')
class HeadCircumferenceList(PermissionRequiredMixin, BabyBuddyFilterView): class HeadCircumferenceList(PermissionRequiredMixin, BabyBuddyFilterView):
model = models.HeadCircumference model = models.HeadCircumference
template_name = 'core/head_circumference_list.html' template_name = 'core/head_circumference_list.html'
@ -527,6 +529,7 @@ class HeadCircumferenceDelete(CoreDeleteView):
permission_required = ('core.delete_head_circumference',) permission_required = ('core.delete_head_circumference',)
success_url = reverse_lazy('core:head-circumference-list') success_url = reverse_lazy('core:head-circumference-list')
class BMIList(PermissionRequiredMixin, BabyBuddyFilterView): class BMIList(PermissionRequiredMixin, BabyBuddyFilterView):
model = models.BMI model = models.BMI
template_name = 'core/bmi_list.html' template_name = 'core/bmi_list.html'
@ -552,4 +555,4 @@ class BMIUpdate(CoreUpdateView):
class BMIDelete(CoreDeleteView): class BMIDelete(CoreDeleteView):
model = models.BMI model = models.BMI
permission_required = ('core.delete_bmi',) permission_required = ('core.delete_bmi',)
success_url = reverse_lazy('core:bmi-list') success_url = reverse_lazy('core:bmi-list')

View File

@ -312,7 +312,7 @@ def card_statistics(context, child):
'type': 'float', 'type': 'float',
'stat': weight['change_weekly'], 'stat': weight['change_weekly'],
'title': _('Weight change per week')}) 'title': _('Weight change per week')})
height = _height_statistics(child) height = _height_statistics(child)
if height: if height:
stats.append({ stats.append({
@ -497,6 +497,7 @@ def _weight_statistics(child):
return weight return weight
def _height_statistics(child): def _height_statistics(child):
""" """
Statistical height data. Statistical height data.
@ -519,6 +520,7 @@ def _height_statistics(child):
return height return height
def _head_circumference_statistics(child): def _head_circumference_statistics(child):
""" """
Statistical head circumference data. Statistical head circumference data.
@ -527,7 +529,9 @@ def _head_circumference_statistics(child):
""" """
head_circumference = {'change_weekly': 0.0} head_circumference = {'change_weekly': 0.0}
instances = models.HeadCircumference.objects.filter(child=child).order_by('-date') instances = models.HeadCircumference.objects.filter(
child=child
).order_by('-date')
if len(instances) == 0: if len(instances) == 0:
return False return False
@ -535,12 +539,13 @@ def _head_circumference_statistics(child):
oldest = instances.last() oldest = instances.last()
if newest != oldest: if newest != oldest:
head_circumference_change = newest.head_circumference - oldest.head_circumference hc_change = newest.head_circumference - oldest.head_circumference
weeks = (newest.date - oldest.date).days/7 weeks = (newest.date - oldest.date).days/7
head_circumference['change_weekly'] = head_circumference_change/weeks head_circumference['change_weekly'] = hc_change/weeks
return head_circumference return head_circumference
def _bmi_statistics(child): def _bmi_statistics(child):
""" """
Statistical BMI data. Statistical BMI data.
@ -563,6 +568,7 @@ def _bmi_statistics(child):
return bmi return bmi
@register.inclusion_tag('cards/timer_list.html', takes_context=True) @register.inclusion_tag('cards/timer_list.html', takes_context=True)
def card_timer_list(context, child=None): def card_timer_list(context, child=None):
""" """

View File

@ -7,6 +7,6 @@ from .sleep_pattern import sleep_pattern # NOQA
from .sleep_totals import sleep_totals # NOQA from .sleep_totals import sleep_totals # NOQA
from .tummytime_duration import tummytime_duration # NOQA from .tummytime_duration import tummytime_duration # NOQA
from .weight_weight import weight_weight # NOQA from .weight_weight import weight_weight # NOQA
from .height_height import height_height #NOQA from .height_height import height_height # NOQA
from .head_circumference_head_circumference import head_circumference_head_circumference #NOQA from .head_circumference_head_circumference import head_circumference_head_circumference # NOQA
from .bmi_bmi import bmi_bmi #NOQA from .bmi_bmi import bmi_bmi # NOQA

View File

@ -56,7 +56,9 @@ class ViewsTestCase(TestCase):
page = self.c.get('{}/height/height/'.format(base_url)) page = self.c.get('{}/height/height/'.format(base_url))
self.assertEqual(page.status_code, 200) self.assertEqual(page.status_code, 200)
page = self.c.get('{}/head-circumference/head-circumference/'.format(base_url)) page = self.c.get(
'{}/head-circumference/head-circumference/'.format(base_url)
)
self.assertEqual(page.status_code, 200) self.assertEqual(page.status_code, 200)
page = self.c.get('{}/bmi/bmi/'.format(base_url)) page = self.c.get('{}/bmi/bmi/'.format(base_url))

View File

@ -196,6 +196,7 @@ class WeightWeightChildReport(PermissionRequiredMixin, DetailView):
context['html'], context['js'] = graphs.weight_weight(objects) context['html'], context['js'] = graphs.weight_weight(objects)
return context return context
class HeightHeightChildReport(PermissionRequiredMixin, DetailView): class HeightHeightChildReport(PermissionRequiredMixin, DetailView):
""" """
Graph of height change over time. Graph of height change over time.
@ -213,7 +214,10 @@ class HeightHeightChildReport(PermissionRequiredMixin, DetailView):
context['html'], context['js'] = graphs.height_height(objects) context['html'], context['js'] = graphs.height_height(objects)
return context return context
class HeadCircumferenceHeadCircumferenceChildReport(PermissionRequiredMixin, DetailView):
class HeadCircumferenceHeadCircumferenceChildReport(
PermissionRequiredMixin, DetailView
):
""" """
Graph of head circumference change over time. Graph of head circumference change over time.
""" """
@ -222,14 +226,19 @@ class HeadCircumferenceHeadCircumferenceChildReport(PermissionRequiredMixin, Det
template_name = 'reports/head_circumference_change.html' template_name = 'reports/head_circumference_change.html'
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super(HeadCircumferenceHeadCircumferenceChildReport, self).get_context_data( context = super(
**kwargs) HeadCircumferenceHeadCircumferenceChildReport,
self
).get_context_data(**kwargs)
child = context['object'] child = context['object']
objects = models.HeadCircumference.objects.filter(child=child) objects = models.HeadCircumference.objects.filter(child=child)
if objects: if objects:
context['html'], context['js'] = graphs.head_circumference_head_circumference(objects) context['html'], context['js'] = (
graphs.head_circumference_head_circumference(objects)
)
return context return context
class BMIBMIChildReport(PermissionRequiredMixin, DetailView): class BMIBMIChildReport(PermissionRequiredMixin, DetailView):
""" """
Graph of BMI change over time. Graph of BMI change over time.
@ -245,4 +254,4 @@ class BMIBMIChildReport(PermissionRequiredMixin, DetailView):
objects = models.BMI.objects.filter(child=child) objects = models.BMI.objects.filter(child=child)
if objects: if objects:
context['html'], context['js'] = graphs.bmi_bmi(objects) context['html'], context['js'] = graphs.bmi_bmi(objects)
return context return context