Add timer delete functionality and move template back in to core.

This commit is contained in:
Christopher Charbonneau Wells 2017-08-18 00:55:57 -04:00
parent 8cb2c171f2
commit a51d9e4c83
8 changed files with 27 additions and 5 deletions

View File

@ -0,0 +1,13 @@
{% extends 'babyblotter/page.html' %}
{% load widget_tweaks %}
{% block title %}Delete {{ object }}{% endblock %}
{% block content %}
<form role="form" method="post">
{% csrf_token %}
<h1>Are you sure you want to delete <span class="text-info">{{ object }}</span>?</h1>
<input type="submit" value="Delete" class="btn btn-danger" />
<a href="/" class="btn btn-default">Cancel</a>
</form>
{% endblock %}

View File

@ -16,7 +16,7 @@
href="{% url 'tummytime-add' %}?timer={{ timer.id }}"
role="button"><i class="fa fa-smile-o" aria-hidden="true"></i> Tummy Time</a>
<a class="btn btn-danger btn-lg btn-block p-3 mb-3"
href="#"
href="{% url 'timer-delete' timer.id %}"
role="button"><i class="fa fa-times-circle" aria-hidden="true"></i> Delete Timer</a>
</div>
{% endblock %}

View File

@ -9,14 +9,14 @@ from core.models import Timer
register = template.Library()
@register.inclusion_tag('timer_list.html', takes_context=True)
@register.inclusion_tag('core/timer_list.html', takes_context=True)
def list_timers(context, active=True):
request = context['request'] or None
timers = Timer.objects.filter(user=request.user, active=active)
return {'timers': timers}
@register.inclusion_tag('timer_nav.html', takes_context=True)
@register.inclusion_tag('core/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)
@ -25,7 +25,7 @@ def timer_nav(context, active=True):
return {'timers': timers, 'perms': perms, 'next': request.path}
@register.inclusion_tag('timer_add.html')
@register.inclusion_tag('core/timer_add.html')
def add_timer(success_url):
return {'success_url': success_url}

View File

@ -50,6 +50,8 @@ urlpatterns = [
name='timer-add-quick'),
url(r'timer/(?P<pk>[0-9]+)/$', views.TimerDetail.as_view(),
name='timer-detail'),
url(r'timer/(?P<pk>[0-9]+)/delete/$', views.TimerDelete.as_view(),
name='timer-delete'),
url(r'tummy-time/$', views.TummyTimeList.as_view(), name='tummytime-list'),
url(r'tummy-time/add/$', views.TummyTimeAdd.as_view(),

View File

@ -158,7 +158,6 @@ class SleepDelete(PermissionRequiredMixin, DeleteView):
class TimerDetail(PermissionRequiredMixin, DetailView):
model = Timer
template_name = 'timer_detail.html' # To be consistent w/Timer templates.
permission_required = ('core.view_timer',)
@ -191,6 +190,12 @@ class TimerAddQuick(PermissionRequiredMixin, RedirectView):
return super(TimerAddQuick, self).get(request, *args, **kwargs)
class TimerDelete(PermissionRequiredMixin, DeleteView):
model = Timer
permission_required = ('core.delete_timer',)
success_url = '/'
class TummyTimeList(PermissionRequiredMixin, ListView):
model = TummyTime
permission_required = ('core.view_tummytime',)
@ -211,10 +216,12 @@ class TummyTimeAdd(PermissionRequiredMixin, CreateView):
class TummyTimeUpdate(PermissionRequiredMixin, UpdateView):
model = TummyTime
permission_required = ('core.change_tummytime',)
form_class = TummyTimeForm
success_url = '/tummy-time'
class TummyTimeDelete(PermissionRequiredMixin, DeleteView):
model = TummyTime
permission_required = ('core.delete_tummytime',)
success_url = '/tummy-time'