Merge pull request #893 from Benbb96/fix-739

Redirect to dashboard after deleting a ticket from there, to fix #739
This commit is contained in:
Garret Wassermann 2020-10-23 09:30:45 -04:00 committed by GitHub
commit fe785bd701
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 4 deletions

View File

@ -20,6 +20,8 @@
<p><a href='../'><button class="btn btn-primary btn-lg">{% trans "No, Don't Delete It" %}</button></a></p>
<form method='post' action='./'>
{% csrf_token %}
<input type="hidden" name="next" value="{{ next }}">
<button class="btn btn-danger" type='submit'>{% trans "Yes I Understand - Delete It Anyway" %}</button>
{% csrf_token %}</form>
</form>
{% endblock %}

View File

@ -26,7 +26,7 @@
<td><span title='{{ ticket.created|date:"r" }}'>{{ ticket.created|naturaltime }}</span></td>
<td class="text-center">
<a href='{{ ticket.get_absolute_url }}?take'><button class='btn btn-primary btn-sm'><i class="fas fa-hand-paper"></i>&nbsp;{% trans "Take" %}</button></a>
<a href='{% url 'helpdesk:delete' ticket.id %}'><button class='btn btn-danger btn-sm'><i class="fas fa-trash"></i>&nbsp;{% trans "Delete" %}</button></a>
<a href='{% url 'helpdesk:delete' ticket.id %}?next=dashboard'><button class='btn btn-danger btn-sm'><i class="fas fa-trash"></i>&nbsp;{% trans "Delete" %}</button></a>
</td>
</tr>
{% empty %}
@ -66,7 +66,7 @@
<td><span title='{{ ticket.created|date:"r" }}'>{{ ticket.created|naturaltime }}</span></td>
<td class="text-center">
<a href='{{ ticket.get_absolute_url }}?take'><button class='btn btn-primary btn-sm'><i class="fas fa-hand-paper"></i>&nbsp;{% trans "Take" %}</button></a>
<a href='{% url 'helpdesk:delete' ticket.id %}'><button class='btn btn-danger btn-sm'><i class="fas fa-trash"></i>&nbsp;{% trans "Delete" %}</button></a>
<a href='{% url 'helpdesk:delete' ticket.id %}?next=dashboard'><button class='btn btn-danger btn-sm'><i class="fas fa-trash"></i>&nbsp;{% trans "Delete" %}</button></a>
</td>
</tr>
{% empty %}

View File

@ -227,10 +227,14 @@ def delete_ticket(request, ticket_id):
if request.method == 'GET':
return render(request, 'helpdesk/delete_ticket.html', {
'ticket': ticket,
'next': request.GET.get('next', 'home')
})
else:
ticket.delete()
return HttpResponseRedirect(reverse('helpdesk:home'))
redirect_to = 'helpdesk:home'
if request.POST.get('next') == 'dashboard':
redirect_to = 'helpdesk:dashboard'
return HttpResponseRedirect(reverse(redirect_to))
delete_ticket = staff_member_required(delete_ticket)