Add navbar-based Timer dropdown.

This commit is contained in:
Christopher Charbonneau Wells 2017-08-17 23:10:07 -04:00
parent 0f73042bfa
commit 68bad13e93
6 changed files with 49 additions and 4 deletions

View File

@ -1,4 +1,5 @@
{% extends 'babyblotter/base.html' %} {% extends 'babyblotter/base.html' %}
{% load timers %}
{% block nav %} {% block nav %}
<nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top"> <nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top">
@ -23,7 +24,7 @@
id="nav-activity-menu-link" id="nav-activity-menu-link"
data-toggle="dropdown" data-toggle="dropdown"
aria-haspopup="true" aria-haspopup="true"
aria-expanded="false"><i class="fa fa-child" aria-hidden="true"></i> Activites</a> aria-expanded="false"><i class="fa fa-child" aria-hidden="true"></i> Activities</a>
<div class="dropdown-menu" aria-labelledby="nav-activity-menu-link"> <div class="dropdown-menu" aria-labelledby="nav-activity-menu-link">
{% if perms.core.view_diaperchange %} {% if perms.core.view_diaperchange %}
@ -78,6 +79,10 @@
</div> </div>
</li> </li>
{% if perms.core.view_timer %}
{% timer_nav %}
{% endif %}
</ul> </ul>
</div> </div>
</nav> </nav>

View File

@ -5,10 +5,10 @@
{% block page %} {% block page %}
<div id="view-{{ request.resolver_match.view_name }}" class="container-fluid"> <div id="view-{{ request.resolver_match.view_name }}" class="container-fluid">
<div class="row justify-content-md-center"> <div class="row justify-content-md-center">
<div class="col-lg-10 mb-4"> <div class="col-lg-12 mb-4">
{% block content %}{% endblock %} {% block content %}{% endblock %}
</div> </div>
{% if perms.core.view_timer %} {% if false and perms.core.view_timer %}
<div class="col-lg-2"> <div class="col-lg-2">
<h1>Timers</h1> <h1>Timers</h1>
{% if perms.core.add_timer %} {% if perms.core.add_timer %}

View File

@ -0,0 +1,20 @@
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle"
id="timer-dropdown-menu-link"
data-toggle="dropdown"
aria-haspopup="true"
aria-expanded="false"><i class="fa fa-clock-o" aria-hidden="true"></i> Timers</a>
<div class="dropdown-menu" aria-labelledby="timer-dropdown-menu-link">
{% if perms.core.add_timer %}
<a class="dropdown-item" href="{% url 'timer-add-quick' %}?next={{ next }}">
<i class="fa fa-plus" aria-hidden="true"></i> Create Timer
</a>
{% if timers %}
<div class="dropdown-divider"></div>
{% endif %}
{% endif %}
{% for timer in timers %}
<button class="dropdown-item" type="button">{{ timer }}</button>
{% endfor %}
</div>
</li>

View File

@ -16,6 +16,14 @@ def list_timers(context, active=True):
return {'timers': timers} return {'timers': timers}
@register.inclusion_tag('timer_nav.html', takes_context=True)
def timer_nav(context, active=True):
request = context['request'] or None
timers = Timer.objects.filter(user=request.user, active=active)
perms = context['perms'] or None
return {'timers': timers, 'perms': perms, 'next': request.path}
@register.inclusion_tag('timer_add.html') @register.inclusion_tag('timer_add.html')
def add_timer(success_url): def add_timer(success_url):
return {'success_url': success_url} return {'success_url': success_url}

View File

@ -46,6 +46,8 @@ urlpatterns = [
name='sleep-delete'), name='sleep-delete'),
url(r'timer/add/$', views.TimerAdd.as_view(), name='timer-add'), url(r'timer/add/$', views.TimerAdd.as_view(), name='timer-add'),
url(r'timer/add/quick/$', views.TimerAddQuick.as_view(),
name='timer-add-quick'),
url(r'tummy-time/$', views.TummyTimeList.as_view(), name='tummytime-list'), url(r'tummy-time/$', views.TummyTimeList.as_view(), name='tummytime-list'),
url(r'tummy-time/add/$', views.TummyTimeAdd.as_view(), url(r'tummy-time/add/$', views.TummyTimeAdd.as_view(),

View File

@ -4,7 +4,7 @@ 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 (LoginRequiredMixin,
PermissionRequiredMixin) PermissionRequiredMixin)
from django.views.generic.base import TemplateView from django.views.generic.base import TemplateView, RedirectView
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
@ -160,6 +160,16 @@ class TimerAdd(PermissionRequiredMixin, CreateView):
return url return url
class TimerAddQuick(PermissionRequiredMixin, RedirectView):
permission_required = ('core.add_timer',)
def get(self, request, *args, **kwargs):
instance = Timer.objects.create(user=request.user)
instance.save()
self.url = request.GET.get('next', '/')
return super(TimerAddQuick, self).get(request, *args, **kwargs)
class TummyTimeList(PermissionRequiredMixin, ListView): class TummyTimeList(PermissionRequiredMixin, ListView):
model = TummyTime model = TummyTime
permission_required = ('core.view_tummytime',) permission_required = ('core.view_tummytime',)