mirror of
https://gitea.mueller.network/extern/django-helpdesk.git
synced 2024-11-22 07:53:19 +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(),
|
public.SuccessIframeView.as_view(),
|
||||||
name="success_iframe",
|
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,
|
path("change_language/", public.change_language,
|
||||||
name="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.")
|
"Public viewing of tickets without a secret key is forbidden.")
|
||||||
|
|
||||||
|
|
||||||
@protect_view
|
class ViewTicket(TemplateView):
|
||||||
def view_ticket(request):
|
template_name = 'helpdesk/public_view_ticket.html'
|
||||||
|
|
||||||
|
|
||||||
|
def get(self, request, *args, **kwargs):
|
||||||
ticket_req = request.GET.get('ticket', None)
|
ticket_req = request.GET.get('ticket', None)
|
||||||
email = request.GET.get('email', None)
|
email = request.GET.get('email', None)
|
||||||
key = request.GET.get('key', '')
|
key = request.GET.get('key', '')
|
||||||
@ -192,23 +195,15 @@ def view_ticket(request):
|
|||||||
else:
|
else:
|
||||||
return search_for_ticket(request, _('Missing ticket ID or e-mail address. Please try again.'))
|
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:
|
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:
|
if hasattr(settings, 'HELPDESK_VIEW_A_TICKET_PUBLIC') and settings.HELPDESK_VIEW_A_TICKET_PUBLIC:
|
||||||
ticket = Ticket.objects.get(
|
ticket = Ticket.objects.get(id=ticket_id, submitter_email__iexact=email)
|
||||||
id=ticket_id, submitter_email__iexact=email)
|
|
||||||
else:
|
else:
|
||||||
ticket = Ticket.objects.get(
|
ticket = Ticket.objects.get(id=ticket_id, submitter_email__iexact=email, secret_key__iexact=key)
|
||||||
id=ticket_id, submitter_email__iexact=email, secret_key__iexact=key)
|
|
||||||
except (ObjectDoesNotExist, ValueError):
|
except (ObjectDoesNotExist, ValueError):
|
||||||
return search_for_ticket(request, _('Invalid ticket ID or e-mail address. Please try again.'))
|
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:
|
if 'close' in request.GET and ticket.status == Ticket.RESOLVED_STATUS:
|
||||||
from helpdesk.update_ticket import update_ticket
|
from helpdesk.update_ticket import update_ticket
|
||||||
update_ticket(
|
update_ticket(
|
||||||
@ -220,19 +215,25 @@ def view_ticket(request):
|
|||||||
)
|
)
|
||||||
return HttpResponseRedirect(ticket.ticket_url)
|
return HttpResponseRedirect(ticket.ticket_url)
|
||||||
|
|
||||||
|
# Prepare context for rendering
|
||||||
# redirect user back to this ticket if possible.
|
context = {
|
||||||
redirect_url = ''
|
|
||||||
if helpdesk_settings.HELPDESK_NAVIGATION_ENABLED:
|
|
||||||
redirect_url = reverse('helpdesk:view', args=[ticket_id])
|
|
||||||
|
|
||||||
return render(request, 'helpdesk/public_view_ticket.html', {
|
|
||||||
'key': key,
|
'key': key,
|
||||||
'mail': email,
|
'mail': email,
|
||||||
'ticket': ticket,
|
'ticket': ticket,
|
||||||
'helpdesk_settings': helpdesk_settings,
|
'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):
|
def change_language(request):
|
||||||
|
Loading…
Reference in New Issue
Block a user