Add Child dashboard logic.

This commit is contained in:
Christopher Charbonneau Wells 2017-08-18 08:29:40 -04:00
parent 5d4beea512
commit b6ba6d440f
3 changed files with 52 additions and 1 deletions

View File

@ -0,0 +1,31 @@
{% extends 'babyblotter/page.html' %}
{% block title %}Dashboard - {{ object }}{% endblock %}
{% block content %}
<h1 class="text-center">{{ object }}</h1>
<div class="container">
<div class="row align-items-start text-center">
<div class="col-sm-12 col-md-4 border">
awake time
</div>
<div class="col-sm-12 col-md-4 border">
last feeding
</div>
<div class="col-sm-12 col-md-4 border">
change statistics
</div>
</div>
<div class="row align-items-start text-center">
<div class="col-sm-12 col-md-4 border">
tummy time for the day
</div>
<div class="col-sm-12 col-md-4 border">
available
</div>
<div class="col-sm-12 col-md-4 border">
available
</div>
</div>
</div>
{% endblock %}

View File

@ -6,10 +6,13 @@ from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.Dashboard.as_view(), name='dashboard'),
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<slug>[^/.]+)/dashboard/$',
views.ChildDashboard.as_view(), name='child-dashboard'),
url(r'children/(?P<pk>[0-9]+)/$', views.ChildUpdate.as_view(),
name='child-update'),
url(r'children/(?P<slug>[^/.]+)/$', views.ChildUpdate.as_view(),

View File

@ -15,10 +15,27 @@ 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',)