mirror of https://github.com/snachodog/mybuddy.git
Add a type-to-confirm field for deleting a child.
This commit is contained in:
parent
b0d2fdd521
commit
8c274ce765
|
@ -13,6 +13,10 @@
|
|||
<form role="form" method="post">
|
||||
{% csrf_token %}
|
||||
<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" />
|
||||
<a href="{% url 'child-list' %}" class="btn btn-default">Cancel</a>
|
||||
</form>
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
from django.contrib.auth.mixins import PermissionRequiredMixin
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.urls import reverse
|
||||
from django.views.generic.base import RedirectView
|
||||
from django.views.generic.detail import DetailView
|
||||
|
@ -43,6 +44,12 @@ class ChildDelete(PermissionRequiredMixin, DeleteView):
|
|||
permission_required = ('core.delete_child',)
|
||||
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):
|
||||
model = DiaperChange
|
||||
|
|
Loading…
Reference in New Issue