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,16 +174,19 @@ class WeightSerializer(CoreModelSerializer):
model = models.Weight
fields = ('id', 'child', 'weight', 'date', 'notes')
class HeightSerializer(CoreModelSerializer):
class Meta:
model = models.Height
fields = ('id', 'child', 'height', 'date', 'notes')
class HeadCircumferenceSerializer(CoreModelSerializer):
class Meta:
model = models.HeadCircumference
fields = ('id', 'child', 'head_circumference', 'date', 'notes')
class BMISerializer(CoreModelSerializer):
class Meta:
model = models.BMI

View File

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

View File

@ -74,6 +74,18 @@ class Command(BaseCommand):
self._add_weight_entry()
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()
while self.time < self.time_now:
self._add_sleep_entry()
@ -91,6 +103,15 @@ class Command(BaseCommand):
if (self.time - last_weight_entry_time).days > 6:
self._add_weight_entry()
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
def _add_diaperchange_entry(self):
@ -300,7 +321,7 @@ class Command(BaseCommand):
if choice([True, False, False, False]):
notes = ' '.join(self.faker.sentences(randint(1, 5)))
models.bmi.objects.create(
models.BMI.objects.create(
child=self.child,
bmi=round(self.bmi, 2),
date=self.time.date(),

View File

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

View File

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

View File

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

View File

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

View File

@ -497,6 +497,7 @@ def _weight_statistics(child):
return weight
def _height_statistics(child):
"""
Statistical height data.
@ -519,6 +520,7 @@ def _height_statistics(child):
return height
def _head_circumference_statistics(child):
"""
Statistical head circumference data.
@ -527,7 +529,9 @@ def _head_circumference_statistics(child):
"""
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:
return False
@ -535,12 +539,13 @@ def _head_circumference_statistics(child):
oldest = instances.last()
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
head_circumference['change_weekly'] = head_circumference_change/weeks
head_circumference['change_weekly'] = hc_change/weeks
return head_circumference
def _bmi_statistics(child):
"""
Statistical BMI data.
@ -563,6 +568,7 @@ def _bmi_statistics(child):
return bmi
@register.inclusion_tag('cards/timer_list.html', takes_context=True)
def card_timer_list(context, child=None):
"""

View File

@ -56,7 +56,9 @@ class ViewsTestCase(TestCase):
page = self.c.get('{}/height/height/'.format(base_url))
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)
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)
return context
class HeightHeightChildReport(PermissionRequiredMixin, DetailView):
"""
Graph of height change over time.
@ -213,7 +214,10 @@ class HeightHeightChildReport(PermissionRequiredMixin, DetailView):
context['html'], context['js'] = graphs.height_height(objects)
return context
class HeadCircumferenceHeadCircumferenceChildReport(PermissionRequiredMixin, DetailView):
class HeadCircumferenceHeadCircumferenceChildReport(
PermissionRequiredMixin, DetailView
):
"""
Graph of head circumference change over time.
"""
@ -222,14 +226,19 @@ class HeadCircumferenceHeadCircumferenceChildReport(PermissionRequiredMixin, Det
template_name = 'reports/head_circumference_change.html'
def get_context_data(self, **kwargs):
context = super(HeadCircumferenceHeadCircumferenceChildReport, self).get_context_data(
**kwargs)
context = super(
HeadCircumferenceHeadCircumferenceChildReport,
self
).get_context_data(**kwargs)
child = context['object']
objects = models.HeadCircumference.objects.filter(child=child)
if objects:
context['html'], context['js'] = graphs.head_circumference_head_circumference(objects)
context['html'], context['js'] = (
graphs.head_circumference_head_circumference(objects)
)
return context
class BMIBMIChildReport(PermissionRequiredMixin, DetailView):
"""
Graph of BMI change over time.