mirror of
https://gitea.mueller.network/extern/django-helpdesk.git
synced 2024-11-21 23:43:11 +01:00
view_ticket → class based view
This commit is contained in:
parent
a27508bba7
commit
e128cc0d5c
@ -165,7 +165,7 @@ urlpatterns += [
|
||||
public.SuccessIframeView.as_view(),
|
||||
name="success_iframe",
|
||||
),
|
||||
path("view/", public.view_ticket, name="public_view"),
|
||||
path("view/", public.ViewTicket.as_view(), name="public_view"),
|
||||
path("change_language/", public.change_language,
|
||||
name="public_change_language"),
|
||||
]
|
||||
|
@ -180,8 +180,11 @@ def search_for_ticket(request, error_message=None):
|
||||
"Public viewing of tickets without a secret key is forbidden.")
|
||||
|
||||
|
||||
@protect_view
|
||||
def view_ticket(request):
|
||||
class ViewTicket(TemplateView):
|
||||
template_name = 'helpdesk/public_view_ticket.html'
|
||||
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
ticket_req = request.GET.get('ticket', None)
|
||||
email = request.GET.get('email', None)
|
||||
key = request.GET.get('key', '')
|
||||
@ -192,23 +195,15 @@ def view_ticket(request):
|
||||
else:
|
||||
return search_for_ticket(request, _('Missing ticket ID or e-mail address. Please try again.'))
|
||||
|
||||
queue, ticket_id = Ticket.queue_and_id_from_query(ticket_req)
|
||||
try:
|
||||
queue, ticket_id = Ticket.queue_and_id_from_query(ticket_req)
|
||||
if hasattr(settings, 'HELPDESK_VIEW_A_TICKET_PUBLIC') and settings.HELPDESK_VIEW_A_TICKET_PUBLIC:
|
||||
ticket = Ticket.objects.get(
|
||||
id=ticket_id, submitter_email__iexact=email)
|
||||
ticket = Ticket.objects.get(id=ticket_id, submitter_email__iexact=email)
|
||||
else:
|
||||
ticket = Ticket.objects.get(
|
||||
id=ticket_id, submitter_email__iexact=email, secret_key__iexact=key)
|
||||
ticket = Ticket.objects.get(id=ticket_id, submitter_email__iexact=email, secret_key__iexact=key)
|
||||
except (ObjectDoesNotExist, ValueError):
|
||||
return search_for_ticket(request, _('Invalid ticket ID or e-mail address. Please try again.'))
|
||||
|
||||
if is_helpdesk_staff(request.user):
|
||||
redirect_url = reverse('helpdesk:view', args=[ticket_id])
|
||||
if 'close' in request.GET:
|
||||
redirect_url += '?close'
|
||||
return HttpResponseRedirect(redirect_url)
|
||||
|
||||
if 'close' in request.GET and ticket.status == Ticket.RESOLVED_STATUS:
|
||||
from helpdesk.update_ticket import update_ticket
|
||||
update_ticket(
|
||||
@ -220,19 +215,25 @@ def view_ticket(request):
|
||||
)
|
||||
return HttpResponseRedirect(ticket.ticket_url)
|
||||
|
||||
|
||||
# redirect user back to this ticket if possible.
|
||||
redirect_url = ''
|
||||
if helpdesk_settings.HELPDESK_NAVIGATION_ENABLED:
|
||||
redirect_url = reverse('helpdesk:view', args=[ticket_id])
|
||||
|
||||
return render(request, 'helpdesk/public_view_ticket.html', {
|
||||
# Prepare context for rendering
|
||||
context = {
|
||||
'key': key,
|
||||
'mail': email,
|
||||
'ticket': ticket,
|
||||
'helpdesk_settings': helpdesk_settings,
|
||||
'next': redirect_url,
|
||||
})
|
||||
'next': self.get_next_url(ticket_id)
|
||||
}
|
||||
return self.render_to_response(context)
|
||||
|
||||
def get_next_url(self, ticket_id):
|
||||
redirect_url = ''
|
||||
if is_helpdesk_staff(self.request.user):
|
||||
redirect_url = reverse('helpdesk:view', args=[ticket_id])
|
||||
if 'close' in self.request.GET:
|
||||
redirect_url += '?close'
|
||||
elif helpdesk_settings.HELPDESK_NAVIGATION_ENABLED:
|
||||
redirect_url = reverse('helpdesk:view', args=[ticket_id])
|
||||
return redirect_url
|
||||
|
||||
|
||||
def change_language(request):
|
||||
|
Loading…
Reference in New Issue
Block a user