mirror of https://github.com/snachodog/mybuddy.git
Refactor dashboard as a separate app.
This commit is contained in:
parent
fe2b704d16
commit
c908ae6e2b
|
@ -22,6 +22,7 @@ INSTALLED_APPS = [
|
||||||
'api',
|
'api',
|
||||||
'babyblotter',
|
'babyblotter',
|
||||||
'core',
|
'core',
|
||||||
|
'dashboard',
|
||||||
|
|
||||||
'rest_framework',
|
'rest_framework',
|
||||||
'widget_tweaks',
|
'widget_tweaks',
|
||||||
|
|
|
@ -15,4 +15,5 @@ urlpatterns = [
|
||||||
|
|
||||||
url(r'', include('api.urls', namespace='api')),
|
url(r'', include('api.urls', namespace='api')),
|
||||||
url(r'', include('core.urls')),
|
url(r'', include('core.urls')),
|
||||||
|
url(r'', include('dashboard.urls')),
|
||||||
]
|
]
|
||||||
|
|
|
@ -6,13 +6,8 @@ from django.conf.urls import url
|
||||||
from . import views
|
from . import views
|
||||||
|
|
||||||
urlpatterns = [
|
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/$', 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(),
|
||||||
|
|
|
@ -2,10 +2,9 @@
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.core.urlresolvers import resolve
|
from django.core.urlresolvers import resolve
|
||||||
from django.contrib.auth.mixins import (LoginRequiredMixin,
|
from django.contrib.auth.mixins import PermissionRequiredMixin
|
||||||
PermissionRequiredMixin)
|
|
||||||
from django.urls import reverse
|
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.detail import DetailView
|
||||||
from django.views.generic.edit import CreateView, UpdateView, DeleteView
|
from django.views.generic.edit import CreateView, UpdateView, DeleteView
|
||||||
from django.views.generic.list import ListView
|
from django.views.generic.list import ListView
|
||||||
|
@ -15,27 +14,6 @@ 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):
|
|
||||||
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',)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
{% extends 'babyblotter/page.html' %}
|
{% extends 'babyblotter/page.html' %}
|
||||||
{% load dashboard_cards %}
|
{% load dashboard %}
|
||||||
|
|
||||||
{% block title %}Dashboard - {{ object }}{% endblock %}
|
{% block title %}Dashboard - {{ object }}{% endblock %}
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="row align-items-start text-center">
|
<div class="row align-items-start text-center">
|
||||||
<div class="col-sm-12 col-md-4">
|
<div class="col-sm-12 col-md-4">
|
||||||
{% feeding_last object %}
|
{% card_feeding_last object %}
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-12 col-md-4">
|
<div class="col-sm-12 col-md-4">
|
||||||
last feeding
|
last feeding
|
|
@ -9,7 +9,7 @@ from core.models import Feeding
|
||||||
register = template.Library()
|
register = template.Library()
|
||||||
|
|
||||||
|
|
||||||
@register.inclusion_tag('dashboard_cards/feeding_last.html')
|
@register.inclusion_tag('cards/feeding_last.html')
|
||||||
def feeding_last(child):
|
def card_feeding_last(child):
|
||||||
feeding_instance = Feeding.objects.filter(child=child).last()
|
feeding_instance = Feeding.objects.filter(child=child).last()
|
||||||
return {'feeding': feeding_instance}
|
return {'feeding': feeding_instance}
|
|
@ -0,0 +1,3 @@
|
||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
# Create your tests here.
|
|
@ -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<slug>[^/.]+)/dashboard/$',
|
||||||
|
views.ChildDashboard.as_view(), name='child-dashboard'),
|
||||||
|
]
|
|
@ -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'
|
Loading…
Reference in New Issue