mirror of https://github.com/snachodog/mybuddy.git
Add navbar-based Timer dropdown.
This commit is contained in:
parent
0f73042bfa
commit
68bad13e93
|
@ -1,4 +1,5 @@
|
|||
{% extends 'babyblotter/base.html' %}
|
||||
{% load timers %}
|
||||
|
||||
{% block nav %}
|
||||
<nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top">
|
||||
|
@ -23,7 +24,7 @@
|
|||
id="nav-activity-menu-link"
|
||||
data-toggle="dropdown"
|
||||
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">
|
||||
|
||||
{% if perms.core.view_diaperchange %}
|
||||
|
@ -78,6 +79,10 @@
|
|||
|
||||
</div>
|
||||
</li>
|
||||
|
||||
{% if perms.core.view_timer %}
|
||||
{% timer_nav %}
|
||||
{% endif %}
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
|
|
|
@ -5,10 +5,10 @@
|
|||
{% block page %}
|
||||
<div id="view-{{ request.resolver_match.view_name }}" class="container-fluid">
|
||||
<div class="row justify-content-md-center">
|
||||
<div class="col-lg-10 mb-4">
|
||||
<div class="col-lg-12 mb-4">
|
||||
{% block content %}{% endblock %}
|
||||
</div>
|
||||
{% if perms.core.view_timer %}
|
||||
{% if false and perms.core.view_timer %}
|
||||
<div class="col-lg-2">
|
||||
<h1>Timers</h1>
|
||||
{% if perms.core.add_timer %}
|
||||
|
|
|
@ -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>
|
|
@ -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}
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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',)
|
||||
|
|
Loading…
Reference in New Issue