mirror of https://github.com/snachodog/mybuddy.git
Add Child dashboard logic.
This commit is contained in:
parent
5d4beea512
commit
b6ba6d440f
|
@ -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 %}
|
|
@ -6,10 +6,13 @@ from django.conf.urls import url
|
||||||
from . import views
|
from . import views
|
||||||
|
|
||||||
urlpatterns = [
|
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/$', views.ChildList.as_view(), name='child-list'),
|
||||||
url(r'children/add/$', views.ChildAdd.as_view(), name='child-add'),
|
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(),
|
url(r'children/(?P<pk>[0-9]+)/$', views.ChildUpdate.as_view(),
|
||||||
name='child-update'),
|
name='child-update'),
|
||||||
url(r'children/(?P<slug>[^/.]+)/$', views.ChildUpdate.as_view(),
|
url(r'children/(?P<slug>[^/.]+)/$', views.ChildUpdate.as_view(),
|
||||||
|
|
|
@ -15,10 +15,27 @@ from .forms import (ChildForm, DiaperChangeForm, FeedingForm, SleepForm,
|
||||||
TimerForm, TummyTimeForm)
|
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):
|
class Dashboard(LoginRequiredMixin, TemplateView):
|
||||||
template_name = 'core/dashboard.html'
|
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):
|
class ChildList(PermissionRequiredMixin, ListView):
|
||||||
model = Child
|
model = Child
|
||||||
permission_required = ('core.view_child',)
|
permission_required = ('core.view_child',)
|
||||||
|
|
Loading…
Reference in New Issue