Add a very basic prototype dashboard for multiple children.

This commit is contained in:
Christopher Charbonneau Wells 2017-08-24 13:09:41 -04:00
parent e4a92e0614
commit eefa00bfd3
5 changed files with 33 additions and 23 deletions

View File

@ -26,6 +26,12 @@ class Child(models.Model):
self.slug = slugify(self) self.slug = slugify(self)
super(Child, self).save(*args, **kwargs) super(Child, self).save(*args, **kwargs)
def name(self, reverse=False):
if reverse:
return '{}, {}'.format(self.last_name, self.first_name)
else:
return '{} {}'.format(self.first_name, self.last_name)
class DiaperChange(models.Model): class DiaperChange(models.Model):
child = models.ForeignKey('Child', related_name='diaper_change') child = models.ForeignKey('Child', related_name='diaper_change')

View File

@ -24,7 +24,7 @@
<td class="text-center"> <td class="text-center">
<div class="btn-group btn-group-sm" role="group" aria-label="Actions"> <div class="btn-group btn-group-sm" role="group" aria-label="Actions">
{% if perms.core.change_child %} {% if perms.core.view_child %}
<a href="{% url 'dashboard-child' child.slug %}" class="btn btn-success"> <a href="{% url 'dashboard-child' child.slug %}" class="btn btn-success">
<i class="fa fa-tachometer" aria-hidden="true"></i> <i class="fa fa-tachometer" aria-hidden="true"></i>
</a> </a>

View File

@ -3,28 +3,27 @@
{% block title %}Welcome!{% endblock %} {% block title %}Welcome!{% endblock %}
{% block content %} {% block content %}
<div class="container"> <div class="card-group">
<div class="row align-items-start text-center"> {% for child in objects %}
<div class="col-sm-12 col-md-4 border"> <div class="card">
awake time <img class="card-img-top" style="height: 180px; width: 100%; display: block;" src="data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%22259%22%20height%3D%22180%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20259%20180%22%20preserveAspectRatio%3D%22none%22%3E%3Cdefs%3E%3Cstyle%20type%3D%22text%2Fcss%22%3E%23holder_15e152b1929%20text%20%7B%20fill%3Argba(255%2C255%2C255%2C.75)%3Bfont-weight%3Anormal%3Bfont-family%3AHelvetica%2C%20monospace%3Bfont-size%3A13pt%20%7D%20%3C%2Fstyle%3E%3C%2Fdefs%3E%3Cg%20id%3D%22holder_15e152b1929%22%3E%3Crect%20width%3D%22259%22%20height%3D%22180%22%20fill%3D%22%23777%22%3E%3C%2Frect%3E%3Cg%3E%3Ctext%20x%3D%2296.26666641235352%22%20y%3D%2296%22%3E259x180%3C%2Ftext%3E%3C%2Fg%3E%3C%2Fg%3E%3C%2Fsvg%3E" data-holder-rendered="true">
<div class="card-body">
<h4 class="card-title">
{{ child.name }}
<small class="text-muted">{{ child.birth_date }}</small>
</h4>
<p class="card-text">
{% if perms.core.view_child %}
<a href="{% url 'dashboard-child' child.slug %}" class="btn btn-success">
<i class="fa fa-tachometer" aria-hidden="true"></i>
</a>
{% endif %}
</p>
</div> </div>
<div class="col-sm-12 col-md-4 border"> <div class="card-footer">
last feeding <small class="text-muted">...</small>
</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> </div>
{% endfor %}
</div> </div>
{% endblock %} {% endblock %}

View File

@ -6,8 +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'^$', views.DashboardRedirect.as_view(), name='dashboard-redirect'),
url(r'^dashboard/$', views.Dashboard.as_view(), name='dashboard-all'), url(r'^dashboard/$', views.Dashboard.as_view(), name='dashboard'),
url(r'^children/(?P<slug>[^/.]+)/dashboard/$', url(r'^children/(?P<slug>[^/.]+)/dashboard/$',
views.ChildDashboard.as_view(), name='dashboard-child'), views.ChildDashboard.as_view(), name='dashboard-child'),
] ]

View File

@ -28,6 +28,11 @@ class DashboardRedirect(LoginRequiredMixin, RedirectView):
class Dashboard(LoginRequiredMixin, TemplateView): class Dashboard(LoginRequiredMixin, TemplateView):
template_name = 'dashboard/dashboard.html' template_name = 'dashboard/dashboard.html'
def get_context_data(self, **kwargs):
context = super(Dashboard, self).get_context_data(**kwargs)
context['objects'] = Child.objects.all().order_by('last_name')
return context
class ChildDashboard(PermissionRequiredMixin, DetailView): class ChildDashboard(PermissionRequiredMixin, DetailView):
model = Child model = Child