diff --git a/babybuddy/settings/base.py b/babybuddy/settings/base.py index 5f365f0f..fa6e3ac9 100644 --- a/babybuddy/settings/base.py +++ b/babybuddy/settings/base.py @@ -144,3 +144,12 @@ REST_FRAMEWORK = { 'rest_framework.pagination.LimitOffsetPagination', 'PAGE_SIZE': 100 } + +# Baby Buddy configuration + +BABY_BUDDY = { + # A sleep entry with a start time between NAP_START_MIN and NAP_START_MAX + # (in the current TZ) will be categorized as a nap. Use the format %H:%M. + 'NAP_START_MIN': '06:00', + 'NAP_START_MAX': '18:00' +} diff --git a/core/admin.py b/core/admin.py index 544ea2a2..ed182d64 100644 --- a/core/admin.py +++ b/core/admin.py @@ -39,7 +39,7 @@ class NoteAdmin(admin.ModelAdmin): @admin.register(Sleep) class SleepAdmin(admin.ModelAdmin): - list_display = ('start', 'end', 'duration', 'child',) + list_display = ('start', 'end', 'duration', 'child', 'nap') list_filter = ('child',) search_fields = ('child__first_name', 'child__last_name',) diff --git a/core/models.py b/core/models.py index f4b0024f..aac813c2 100644 --- a/core/models.py +++ b/core/models.py @@ -3,6 +3,7 @@ from __future__ import unicode_literals from datetime import timedelta +from django.conf import settings from django.core.exceptions import ValidationError from django.db import models from django.template.defaultfilters import slugify @@ -190,6 +191,15 @@ class Sleep(models.Model): def __str__(self): return 'Sleep' + def nap(self): + # TODO: Add a way to filter naps from Sleep.objects() easily. + nap_start_min = timezone.datetime.strptime( + settings.BABY_BUDDY['NAP_START_MIN'], '%H:%M').time() + nap_start_max = timezone.datetime.strptime( + settings.BABY_BUDDY['NAP_START_MAX'], '%H:%M').time() + local_start_time = timezone.localtime(self.start).time() + return nap_start_min <= local_start_time <= nap_start_max + def save(self, *args, **kwargs): if self.start and self.end: self.duration = self.end - self.start diff --git a/core/templates/core/sleep_list.html b/core/templates/core/sleep_list.html index be1f7920..a5757472 100644 --- a/core/templates/core/sleep_list.html +++ b/core/templates/core/sleep_list.html @@ -1,6 +1,5 @@ {% extends 'babybuddy/page.html' %} -{% load widget_tweaks %} -{% load duration %} +{% load bootstrap duration widget_tweaks %} {% block title %}Sleep{% endblock %} @@ -19,6 +18,7 @@