Add a type-to-confirm field for deleting a child.

This commit is contained in:
Christopher Charbonneau Wells 2017-10-30 22:04:00 -04:00
parent b0d2fdd521
commit 8c274ce765
2 changed files with 11 additions and 0 deletions

View File

@ -13,6 +13,10 @@
<form role="form" method="post"> <form role="form" method="post">
{% csrf_token %} {% csrf_token %}
<h1>Are you sure you want to delete <span class="text-info">{{ object }}</span>?</h1> <h1>Are you sure you want to delete <span class="text-info">{{ object }}</span>?</h1>
<div class="form-group">
<label for="confirm_name">To confirm this action. Type the full name of the child below.</label>
<input type="text" id="confirm_name" name="confirm_name" class="form-control" placeholder="{{ object }}" />
</div>
<input type="submit" value="Delete" class="btn btn-danger" /> <input type="submit" value="Delete" class="btn btn-danger" />
<a href="{% url 'child-list' %}" class="btn btn-default">Cancel</a> <a href="{% url 'child-list' %}" class="btn btn-default">Cancel</a>
</form> </form>

View File

@ -2,6 +2,7 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from django.contrib.auth.mixins import PermissionRequiredMixin from django.contrib.auth.mixins import PermissionRequiredMixin
from django.http import HttpResponseRedirect
from django.urls import reverse from django.urls import reverse
from django.views.generic.base import RedirectView from django.views.generic.base import RedirectView
from django.views.generic.detail import DetailView from django.views.generic.detail import DetailView
@ -43,6 +44,12 @@ class ChildDelete(PermissionRequiredMixin, DeleteView):
permission_required = ('core.delete_child',) permission_required = ('core.delete_child',)
success_url = '/children' success_url = '/children'
def post(self, request, *args, **kwargs):
if str(self.get_object()) != self.request.POST.get('confirm_name'):
# TODO: Provide some error feedback.
return HttpResponseRedirect(self.request.path)
return self.delete(request, *args, **kwargs)
class DiaperChangeList(PermissionRequiredMixin, ListView): class DiaperChangeList(PermissionRequiredMixin, ListView):
model = DiaperChange model = DiaperChange