Add docstrings to existing cards.

This commit is contained in:
Christopher Charbonneau Wells 2017-11-04 06:49:59 -04:00
parent df5c3e98b9
commit c6c603d592
1 changed files with 49 additions and 15 deletions

View File

@ -13,7 +13,10 @@ register = template.Library()
@register.inclusion_tag('cards/averages.html') @register.inclusion_tag('cards/averages.html')
def card_averages(child): def card_averages(child):
"""Averages data for all models. """
Averages data for all models.
:param child: an instance of the Child model.
:returns: a dictionary of Diaper Change, Feeding and Sleep averages data.
""" """
instances = Sleep.objects.filter(child=child).order_by('start') instances = Sleep.objects.filter(child=child).order_by('start')
sleep = { sleep = {
@ -71,7 +74,10 @@ def card_averages(child):
@register.inclusion_tag('cards/diaperchange_last.html') @register.inclusion_tag('cards/diaperchange_last.html')
def card_diaperchange_last(child): def card_diaperchange_last(child):
"""Information about the most recent diaper change. """
Information about the most recent diaper change.
:param child: an instance of the Child model.
:returns: a dictionary with the most recent Diaper Change instance.
""" """
instance = DiaperChange.objects.filter( instance = DiaperChange.objects.filter(
child=child).order_by('-time').first() child=child).order_by('-time').first()
@ -80,7 +86,11 @@ def card_diaperchange_last(child):
@register.inclusion_tag('cards/diaperchange_types.html') @register.inclusion_tag('cards/diaperchange_types.html')
def card_diaperchange_types(child): def card_diaperchange_types(child):
"""Diaper change statistics for the last seven days including today. """
Creates a break down of wet and solid Diaper Change instances for the past
seven days.
:param child: an instance of the Child model.
:returns: a dictionary with the wet/dry statistics.
""" """
stats = {} stats = {}
max_date = (timezone.localtime() + timezone.timedelta( max_date = (timezone.localtime() + timezone.timedelta(
@ -106,15 +116,15 @@ def card_diaperchange_types(child):
stats[key]['wet_pct'] = info['wet'] / total * 100 stats[key]['wet_pct'] = info['wet'] / total * 100
stats[key]['solid_pct'] = info['solid'] / total * 100 stats[key]['solid_pct'] = info['solid'] / total * 100
return { return {'type': 'diaperchange', 'stats': stats}
'type': 'diaperchange',
'stats': stats,
'last_change': instances.first()}
@register.inclusion_tag('cards/feeding_last.html') @register.inclusion_tag('cards/feeding_last.html')
def card_feeding_last(child): def card_feeding_last(child):
"""Information about the most recent feeding. """
Information about the most recent feeding.
:param child: an instance of the Child model.
:returns: a dictionary with the most recent Feeding instance.
""" """
instance = Feeding.objects.filter(child=child).order_by('-end').first() instance = Feeding.objects.filter(child=child).order_by('-end').first()
return {'type': 'feeding', 'feeding': instance} return {'type': 'feeding', 'feeding': instance}
@ -122,7 +132,10 @@ def card_feeding_last(child):
@register.inclusion_tag('cards/feeding_last_method.html') @register.inclusion_tag('cards/feeding_last_method.html')
def card_feeding_last_method(child): def card_feeding_last_method(child):
"""Information about the most recent feeding _method_. """
Information about the most recent feeding method.
:param child: an instance of the Child model.
:returns: a dictionary with the most recent Feeding instance.
""" """
instance = Feeding.objects.filter(child=child).order_by('-end').first() instance = Feeding.objects.filter(child=child).order_by('-end').first()
return {'type': 'feeding', 'feeding': instance} return {'type': 'feeding', 'feeding': instance}
@ -130,7 +143,10 @@ def card_feeding_last_method(child):
@register.inclusion_tag('cards/sleep_last.html') @register.inclusion_tag('cards/sleep_last.html')
def card_sleep_last(child): def card_sleep_last(child):
"""Information about the most recent sleep entry. """
Information about the most recent sleep entry.
:param child: an instance of the Child model.
:returns: a dictionary with the most recent Sleep instance.
""" """
instance = Sleep.objects.filter(child=child).order_by('-end').first() instance = Sleep.objects.filter(child=child).order_by('-end').first()
return {'type': 'sleep', 'sleep': instance} return {'type': 'sleep', 'sleep': instance}
@ -138,7 +154,11 @@ def card_sleep_last(child):
@register.inclusion_tag('cards/sleep_day.html') @register.inclusion_tag('cards/sleep_day.html')
def card_sleep_day(child, date=None): def card_sleep_day(child, date=None):
"""Total sleep time for a child on the current day. """
Filters Sleep instances to get count and total values for a specific date.
:param child: an instance of the Child model.
:param date: a Date object for the day to filter.
:returns: a dictionary with count and total values for the Sleep instances.
""" """
if not date: if not date:
date = timezone.localtime().date() date = timezone.localtime().date()
@ -171,7 +191,12 @@ def card_sleep_day(child, date=None):
@register.inclusion_tag('cards/sleep_naps_day.html') @register.inclusion_tag('cards/sleep_naps_day.html')
def card_sleep_naps_day(child, date=None): def card_sleep_naps_day(child, date=None):
"""Nap information for the current day. """
Filters Sleep instances categorized as naps and generates statistics for a
specific date.
:param child: an instance of the Child model.
:param date: a Date object for the day to filter.
:returns: a dictionary of nap data statistics.
""" """
local = timezone.localtime(date) local = timezone.localtime(date)
start_lower = local.replace( start_lower = local.replace(
@ -188,7 +213,9 @@ def card_sleep_naps_day(child, date=None):
@register.inclusion_tag('cards/timer_list.html') @register.inclusion_tag('cards/timer_list.html')
def card_timer_list(): def card_timer_list():
"""Information about currently active timers. """
Filters for currently active Timer instances.
:returns: a dictionary with a list of active Timer instances.
""" """
instances = Timer.objects.filter(active=True).order_by('-start') instances = Timer.objects.filter(active=True).order_by('-start')
return {'type': 'timer', 'instances': list(instances)} return {'type': 'timer', 'instances': list(instances)}
@ -196,7 +223,10 @@ def card_timer_list():
@register.inclusion_tag('cards/tummytime_last.html') @register.inclusion_tag('cards/tummytime_last.html')
def card_tummytime_last(child): def card_tummytime_last(child):
"""Information about the most recent tummy time. """
Filters the most recent tummy time.
:param child: an instance of the Child model.
:returns: a dictionary with the most recent Tummy Time instance.
""" """
instance = TummyTime.objects.filter(child=child).order_by('-end').first() instance = TummyTime.objects.filter(child=child).order_by('-end').first()
return {'type': 'tummytime', 'tummytime': instance} return {'type': 'tummytime', 'tummytime': instance}
@ -204,7 +234,11 @@ def card_tummytime_last(child):
@register.inclusion_tag('cards/tummytime_day.html') @register.inclusion_tag('cards/tummytime_day.html')
def card_tummytime_day(child, date=None): def card_tummytime_day(child, date=None):
"""Tummy time over the course of `date`. """
Filters Tummy Time instances and generates statistics for a specific date.
:param child: an instance of the Child model.
:param date: a Date object for the day to filter.
:returns: a dictionary of all Tummy Time instances and stats for date.
""" """
if not date: if not date:
date = timezone.localtime().date() date = timezone.localtime().date()