From 68bad13e93f71377504a2024653c6bccc0899c3b Mon Sep 17 00:00:00 2001 From: Christopher Charbonneau Wells Date: Thu, 17 Aug 2017 23:10:07 -0400 Subject: [PATCH] Add navbar-based Timer dropdown. --- .../templates/babyblotter/nav-dropdown.html | 7 ++++++- babyblotter/templates/babyblotter/page.html | 4 ++-- core/templates/timer_nav.html | 20 +++++++++++++++++++ core/templatetags/timers.py | 8 ++++++++ core/urls.py | 2 ++ core/views.py | 12 ++++++++++- 6 files changed, 49 insertions(+), 4 deletions(-) create mode 100644 core/templates/timer_nav.html diff --git a/babyblotter/templates/babyblotter/nav-dropdown.html b/babyblotter/templates/babyblotter/nav-dropdown.html index 0900e93c..6171e3ba 100644 --- a/babyblotter/templates/babyblotter/nav-dropdown.html +++ b/babyblotter/templates/babyblotter/nav-dropdown.html @@ -1,4 +1,5 @@ {% extends 'babyblotter/base.html' %} +{% load timers %} {% block nav %} diff --git a/babyblotter/templates/babyblotter/page.html b/babyblotter/templates/babyblotter/page.html index 35b0d035..b3868dea 100644 --- a/babyblotter/templates/babyblotter/page.html +++ b/babyblotter/templates/babyblotter/page.html @@ -5,10 +5,10 @@ {% block page %}
-
+
{% block content %}{% endblock %}
- {% if perms.core.view_timer %} + {% if false and perms.core.view_timer %}

Timers

{% if perms.core.add_timer %} diff --git a/core/templates/timer_nav.html b/core/templates/timer_nav.html new file mode 100644 index 00000000..89b58222 --- /dev/null +++ b/core/templates/timer_nav.html @@ -0,0 +1,20 @@ + \ No newline at end of file diff --git a/core/templatetags/timers.py b/core/templatetags/timers.py index ecd88c23..84786e0f 100644 --- a/core/templatetags/timers.py +++ b/core/templatetags/timers.py @@ -16,6 +16,14 @@ def list_timers(context, active=True): 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') def add_timer(success_url): return {'success_url': success_url} diff --git a/core/urls.py b/core/urls.py index 8cfa908d..5c4507f2 100644 --- a/core/urls.py +++ b/core/urls.py @@ -46,6 +46,8 @@ urlpatterns = [ name='sleep-delete'), 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/add/$', views.TummyTimeAdd.as_view(), diff --git a/core/views.py b/core/views.py index 5cfb01f6..b9a60acf 100644 --- a/core/views.py +++ b/core/views.py @@ -4,7 +4,7 @@ from __future__ import unicode_literals from django.core.urlresolvers import resolve from django.contrib.auth.mixins import (LoginRequiredMixin, 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.list import ListView @@ -160,6 +160,16 @@ class TimerAdd(PermissionRequiredMixin, CreateView): 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): model = TummyTime permission_required = ('core.view_tummytime',)