Skip to content

Commit

Permalink
Candidate code for deletion confirmation
Browse files Browse the repository at this point in the history
  • Loading branch information
profcturner committed Dec 10, 2018
1 parent 8c81473 commit 201a0ce
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion WAM/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
url(r'^modules/details/(?P<module_id>[0-9]+)$', views.modules_details, name='modules_details'),
url(r'^modules/add_assessment_resource/(?P<module_id>[0-9]+)$', views.add_assessment_resource, name='add_assessment_resource'),
url(r'^modules/download_assessment_resource/(?P<resource_id>[0-9]+)$', views.download_assessment_resource, name='download_assessment_resource'),
url(r'^modules/delete_assessment_resource/(?P<resource_id>[0-9]+)$', views.delete_assessment_resource,
url(r'^modules/delete_assessment_resource/(?P<resource_id>[0-9]+)(/confirm)?$', views.delete_assessment_resource,
name='delete_assessment_resource'),
url(r'^modules/add_assessment_sign_off/(?P<module_id>[0-9]+)$', views.add_assessment_sign_off,
name='add_assessment_sign_off'),
Expand Down
16 changes: 16 additions & 0 deletions loads/templates/loads/modules/delete_assessment_resource.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{% extends "loads/base_automatic.html" %}

{% block content %}

{% if resource.module.package.in_the_past %}
<h1><span style="color:red">Warning: The Work Package for this item is in the Past.</span></h1>
<p><span style="color:red">You should not be deleting resources unless they are a correction.</span></p>
{% endif %}

<h2>Delete Assessment Resource for {{ resource.module }}</h2>

<p>You are deleting {{ resource }}, this cannot be undone. Are you sure?</p>

<p><a href="{% url 'delete_assessment_resource' resource.id confirm=True %}">Confirm</a> | <a href="{% url 'modules_details' resource.module.id %}">Cancel</a></p>

{% endblock content %}
13 changes: 11 additions & 2 deletions loads/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def download_assessment_resource(request, resource_id):


@login_required
def delete_assessment_resource(request, resource_id):
def delete_assessment_resource(request, resource_id, confirm=None):
"""Delete an assessment resource, should not be possible for signed resources, except for superuser"""
# Get the resource object
resource = get_object_or_404(AssessmentResource, pk=resource_id)
Expand Down Expand Up @@ -166,7 +166,15 @@ def delete_assessment_resource(request, resource_id):
return HttpResponseRedirect(reverse('forbidden'))

# Ok, we are allowed to delete
# TODO: Absolutely need confirmation logic
# Check if the deletion is confirmed
if not confirm:
context = {
'resource': resource
}
template = loader.get_template('loads/module/delete_assessment_resource.html')
return HttpResponse(template.render(context, request))

# If we are still here we can delete safely
resource.delete()

url = reverse('modules_details', kwargs={'module_id': resource.module_id})
Expand Down Expand Up @@ -1665,3 +1673,4 @@ def form_valid(self, form):
self.object.package = package
response = super(UpdateActivityView, self).form_valid(form)
return response

0 comments on commit 201a0ce

Please sign in to comment.