def createticket(request): if request.POST: form = TicketForm(request.POST) if form.is_valid(): form.save() messages.success(request, 'Ticket added!') return HttpResponseRedirect('/tickets/') else: if request.user.is_superuser: form = TicketForm() else: form = UserTicketForm() return render(request, 'createticket.html', locals())
def editar_ticket(request, id): ticket = Ticket.objects.get(id=id) if request.method == "POST": form = TicketForm(request.POST, instance=ticket) if form.is_valid(): form.save() return redirect("ticket-detalle", id=id) else: form = TicketForm(instance=ticket) return render(request, "ticket_editar.html", { "ticket": ticket, "form": form, })
def ticket_edit(request, ticket_id, response_format='html'): "Ticket edit" context = _get_default_context(request) agent = context['agent'] ticket = get_object_or_404(Ticket, pk=ticket_id) if not request.user.profile.has_permission(ticket, mode='w'): return user_denied(request, message="You don't have access to this Ticket") if request.POST: if 'cancel' not in request.POST: form = TicketForm( request.user.profile, None, agent, request.POST, instance=ticket) if form.is_valid(): ticket = form.save() return HttpResponseRedirect(reverse('services_ticket_view', args=[ticket.id])) else: return HttpResponseRedirect(reverse('services_ticket_view', args=[ticket.id])) else: form = TicketForm( request.user.profile, None, agent, instance=ticket) context.update({'form': form, 'ticket': ticket}) return render_to_response('services/ticket_edit', context, context_instance=RequestContext(request), response_format=response_format)
def ticket_edit(request, ticket_id, response_format='html'): "Ticket edit" context = _get_default_context(request) agent = context['agent'] ticket = get_object_or_404(Ticket, pk=ticket_id) if not request.user.profile.has_permission(ticket, mode='w'): return user_denied(request, message="You don't have access to this Ticket") if request.POST: if 'cancel' not in request.POST: form = TicketForm(request.user.profile, None, agent, request.POST, instance=ticket) if form.is_valid(): ticket = form.save() return HttpResponseRedirect( reverse('services_ticket_view', args=[ticket.id])) else: return HttpResponseRedirect( reverse('services_ticket_view', args=[ticket.id])) else: form = TicketForm(request.user.profile, None, agent, instance=ticket) context.update({'form': form, 'ticket': ticket}) return render_to_response('services/ticket_edit', context, context_instance=RequestContext(request), response_format=response_format)
def edit_ticket(request, ticket_id=None, template="operations/edit_ticket.html", context=None): context = context or {} ticket = None if ticket_id: ticket = BaseTicket.objects.get(pk=ticket_id) ticket_form = TicketForm( request.POST or None, instance=ticket) else: ticket_form = TicketForm(request.POST or None) if ticket_form.is_valid(): ticket = ticket_form.save(commit=False) if ticket_id: ticket.created_by = request.user ticket.save() obj = BaseTicket.objects.get(pk=ticket_id) messages.success(request, 'Ticket %s is updated' %(obj.number)) else: ticket.created_by = request.user ticket.number = generate_ticket_ref() ticket.save() objj = BaseTicket.objects.latest('id') messages.success(request, 'Ticket %s is created' %(objj.number)) return redirect(reverse('view_tickets')) context['form'] = ticket_form context['ticket'] = ticket return render(request, template, context)
def support(request): if request.method == 'POST': form = TicketForm(request.POST) if form.is_valid(): form = form.save(commit=False) form.user_id = request.user.id form.save() return redirect(reverse('support')) tickets = Ticket.objects.all() comments = Comment.objects.all() form = TicketForm() form2 = CommentForm() args = { 'tickets': tickets, 'form': form, 'comments': comments, 'form2': form2 } return render(request, "support.html", args)
def contact(request): data = {} if request.method == 'POST': form = TicketForm(request.POST) if form.is_valid(): f = form.save(commit=False) f.reference = new_id() if request.user.is_authenticated(): f.user = request.user f.save() else: form.save() return redirect('shop:frontpage') else: data['form'] = form return render(request, 'helpdesk/contact.html', data) else: data['form'] = TicketForm() return render(request, 'helpdesk/contact.html', data)
def ticketdetails(request, ticket_id): ticket = get_object_or_404(Ticket, pk=ticket_id) tickets = Ticket.history.filter(id=ticket_id) t = "Edit" if request.POST: form = TicketForm(request.POST, instance=ticket) if form.is_valid(): form.save() return HttpResponseRedirect('/tickets/') else: form = TicketForm(instance=ticket) return render_to_response("ticketdetails.html", { 'form': form, 't': t, 'tickets': tickets, }, context_instance=RequestContext(request))
def place_reservation(request, event_id): tickets = Tickets.objects.filter(event_id = event_id) if request.method == 'POST': form = TicketForm(event_id, request.POST) if form.is_valid(): ticket = form.save(commit=False) ticket.user = request.user ticket.save() ticket.generate_qrcode() mail = EmailMessage('Event entry ticket', ticket.get_reservation_info(), '*****@*****.**', [ticket.guest_email]) mail.attach_file(ticket.qrcode.url) mail.send() return render(request, 'success_res.html') else: form = TicketForm(event_id) return render(request, 'place_reservation.html', {'form': form, 'tickets': tickets})
def ticket_add(request, queue_id=None, response_format='html'): "Ticket add" context = _get_default_context(request) agent = context['agent'] profile = request.user.profile queue = None if queue_id: queue = get_object_or_404(TicketQueue, pk=queue_id) if not profile.has_permission(queue, mode='x'): queue = None if request.POST: if 'cancel' not in request.POST: ticket = Ticket(creator=profile) if not agent: if queue: ticket.queue = queue if queue.default_ticket_status: ticket.status = queue.default_ticket_status else: try: conf = ModuleSetting.get_for_module( 'anaf.services', 'default_ticket_status')[0] ticket.status = TicketStatus.objects.get( pk=long(conf.value)) except: if 'statuses' in context: try: ticket.status = context['statuses'][0] except: pass ticket.priority = queue.default_ticket_priority ticket.service = queue.default_service else: try: conf = ModuleSetting.get_for_module( 'anaf.services', 'default_ticket_status')[0] ticket.status = TicketStatus.objects.get( pk=long(conf.value)) except: if 'statuses' in context: try: ticket.status = context['statuses'][0] except: pass try: conf = ModuleSetting.get_for_module( 'anaf.services', 'default_ticket_queue')[0] ticket.queue = TicketQueue.objects.get( pk=long(conf.value)) except: if 'queues' in context: try: ticket.queue = context['queues'][0] except: pass try: ticket.caller = profile.get_contact() except: pass form = TicketForm( profile, queue, agent, request.POST, instance=ticket) if form.is_valid(): ticket = form.save() ticket.set_user_from_request(request) return HttpResponseRedirect(reverse('services_ticket_view', args=[ticket.id])) else: return HttpResponseRedirect(reverse('services')) else: form = TicketForm(request.user.profile, queue, agent) context.update({'form': form, 'queue': queue}) return render_to_response('services/ticket_add', context, context_instance=RequestContext(request), response_format=response_format)
def ticket_add(request, queue_id=None, response_format='html'): "Ticket add" context = _get_default_context(request) agent = context['agent'] profile = request.user.profile queue = None if queue_id: queue = get_object_or_404(TicketQueue, pk=queue_id) if not profile.has_permission(queue, mode='x'): queue = None if request.POST: if 'cancel' not in request.POST: ticket = Ticket(creator=profile) if not agent: if queue: ticket.queue = queue if queue.default_ticket_status: ticket.status = queue.default_ticket_status else: try: conf = ModuleSetting.get_for_module( 'anaf.services', 'default_ticket_status')[0] ticket.status = TicketStatus.objects.get( pk=long(conf.value)) except: if 'statuses' in context: try: ticket.status = context['statuses'][0] except: pass ticket.priority = queue.default_ticket_priority ticket.service = queue.default_service else: try: conf = ModuleSetting.get_for_module( 'anaf.services', 'default_ticket_status')[0] ticket.status = TicketStatus.objects.get( pk=long(conf.value)) except: if 'statuses' in context: try: ticket.status = context['statuses'][0] except: pass try: conf = ModuleSetting.get_for_module( 'anaf.services', 'default_ticket_queue')[0] ticket.queue = TicketQueue.objects.get( pk=long(conf.value)) except: if 'queues' in context: try: ticket.queue = context['queues'][0] except: pass try: ticket.caller = profile.get_contact() except: pass form = TicketForm(profile, queue, agent, request.POST, instance=ticket) if form.is_valid(): ticket = form.save() ticket.set_user_from_request(request) return HttpResponseRedirect( reverse('services_ticket_view', args=[ticket.id])) else: return HttpResponseRedirect(reverse('services')) else: form = TicketForm(request.user.profile, queue, agent) context.update({'form': form, 'queue': queue}) return render_to_response('services/ticket_add', context, context_instance=RequestContext(request), response_format=response_format)