diff --git a/babyblotter/settings.py b/babyblotter/settings.py index 1078655c..aab583ad 100644 --- a/babyblotter/settings.py +++ b/babyblotter/settings.py @@ -22,6 +22,7 @@ INSTALLED_APPS = [ 'api', 'babyblotter', 'core', + 'dashboard', 'rest_framework', 'widget_tweaks', diff --git a/babyblotter/urls.py b/babyblotter/urls.py index 5d190573..6e36194f 100644 --- a/babyblotter/urls.py +++ b/babyblotter/urls.py @@ -15,4 +15,5 @@ urlpatterns = [ url(r'', include('api.urls', namespace='api')), url(r'', include('core.urls')), + url(r'', include('dashboard.urls')), ] diff --git a/core/urls.py b/core/urls.py index e19ce0ea..34127098 100644 --- a/core/urls.py +++ b/core/urls.py @@ -6,13 +6,8 @@ from django.conf.urls import url from . import views urlpatterns = [ - url(r'^$', views.DashboardRedirect.as_view(), name='dashboard'), - url(r'^dashboard/$', views.Dashboard.as_view(), name='dashboard'), - url(r'children/$', views.ChildList.as_view(), name='child-list'), url(r'children/add/$', views.ChildAdd.as_view(), name='child-add'), - url(r'children/(?P[^/.]+)/dashboard/$', - views.ChildDashboard.as_view(), name='child-dashboard'), url(r'children/(?P[0-9]+)/$', views.ChildUpdate.as_view(), name='child-update'), url(r'children/(?P[^/.]+)/$', views.ChildUpdate.as_view(), diff --git a/core/views.py b/core/views.py index c87b78c6..24bf8fb9 100644 --- a/core/views.py +++ b/core/views.py @@ -2,10 +2,9 @@ from __future__ import unicode_literals from django.core.urlresolvers import resolve -from django.contrib.auth.mixins import (LoginRequiredMixin, - PermissionRequiredMixin) +from django.contrib.auth.mixins import PermissionRequiredMixin from django.urls import reverse -from django.views.generic.base import TemplateView, RedirectView +from django.views.generic.base import RedirectView from django.views.generic.detail import DetailView from django.views.generic.edit import CreateView, UpdateView, DeleteView from django.views.generic.list import ListView @@ -15,27 +14,6 @@ from .forms import (ChildForm, DiaperChangeForm, FeedingForm, SleepForm, TimerForm, TummyTimeForm) -class DashboardRedirect(LoginRequiredMixin, RedirectView): - # Show the overall dashboard or a child dashboard if one Child instance. - def get(self, request, *args, **kwargs): - if Child.objects.count() == 1: - child_instance = Child.objects.first() - self.url = reverse('child-dashboard', args={child_instance.slug}) - else: - self.url = reverse('dashboard') - return super(DashboardRedirect, self).get(request, *args, **kwargs) - - -class Dashboard(LoginRequiredMixin, TemplateView): - template_name = 'core/dashboard.html' - - -class ChildDashboard(PermissionRequiredMixin, DetailView): - model = Child - permission_required = ('core.view_child',) - template_name = 'core/child_dashboard.html' - - class ChildList(PermissionRequiredMixin, ListView): model = Child permission_required = ('core.view_child',) diff --git a/dashboard/__init__.py b/dashboard/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/dashboard/migrations/__init__.py b/dashboard/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/core/templates/dashboard_cards/feeding_last.html b/dashboard/templates/cards/feeding_last.html similarity index 100% rename from core/templates/dashboard_cards/feeding_last.html rename to dashboard/templates/cards/feeding_last.html diff --git a/core/templates/core/child_dashboard.html b/dashboard/templates/dashboard/child.html similarity index 91% rename from core/templates/core/child_dashboard.html rename to dashboard/templates/dashboard/child.html index faa919e6..0660df6c 100644 --- a/core/templates/core/child_dashboard.html +++ b/dashboard/templates/dashboard/child.html @@ -1,5 +1,5 @@ {% extends 'babyblotter/page.html' %} -{% load dashboard_cards %} +{% load dashboard %} {% block title %}Dashboard - {{ object }}{% endblock %} @@ -8,7 +8,7 @@
- {% feeding_last object %} + {% card_feeding_last object %}
last feeding diff --git a/core/templates/core/dashboard.html b/dashboard/templates/dashboard/dashboard.html similarity index 100% rename from core/templates/core/dashboard.html rename to dashboard/templates/dashboard/dashboard.html diff --git a/dashboard/templatetags/__init__.py b/dashboard/templatetags/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/core/templatetags/dashboard_cards.py b/dashboard/templatetags/dashboard.py similarity index 75% rename from core/templatetags/dashboard_cards.py rename to dashboard/templatetags/dashboard.py index 1ef0bffd..c459c4bf 100644 --- a/core/templatetags/dashboard_cards.py +++ b/dashboard/templatetags/dashboard.py @@ -9,7 +9,7 @@ from core.models import Feeding register = template.Library() -@register.inclusion_tag('dashboard_cards/feeding_last.html') -def feeding_last(child): +@register.inclusion_tag('cards/feeding_last.html') +def card_feeding_last(child): feeding_instance = Feeding.objects.filter(child=child).last() return {'feeding': feeding_instance} diff --git a/dashboard/tests.py b/dashboard/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/dashboard/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/dashboard/urls.py b/dashboard/urls.py new file mode 100644 index 00000000..2116756d --- /dev/null +++ b/dashboard/urls.py @@ -0,0 +1,13 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.conf.urls import url + +from . import views + +urlpatterns = [ + url(r'^$', views.DashboardRedirect.as_view(), name='dashboard'), + url(r'^dashboard/$', views.Dashboard.as_view(), name='dashboard'), + url(r'children/(?P[^/.]+)/dashboard/$', + views.ChildDashboard.as_view(), name='child-dashboard'), +] diff --git a/dashboard/views.py b/dashboard/views.py new file mode 100644 index 00000000..646108d5 --- /dev/null +++ b/dashboard/views.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.contrib.auth.mixins import (LoginRequiredMixin, + PermissionRequiredMixin) +from django.urls import reverse +from django.views.generic.base import TemplateView, RedirectView +from django.views.generic.detail import DetailView + +from core.models import Child + + +class DashboardRedirect(LoginRequiredMixin, RedirectView): + # Show the overall dashboard or a child dashboard if one Child instance. + def get(self, request, *args, **kwargs): + if Child.objects.count() == 1: + child_instance = Child.objects.first() + self.url = reverse('child-dashboard', args={child_instance.slug}) + else: + self.url = reverse('dashboard') + return super(DashboardRedirect, self).get(request, *args, **kwargs) + + +class Dashboard(LoginRequiredMixin, TemplateView): + template_name = 'dashboard/dashboard.html' + + +class ChildDashboard(PermissionRequiredMixin, DetailView): + model = Child + permission_required = ('core.view_child',) + template_name = 'dashboard/child.html'