def tickets_escalate(): "Automatically move tickets to upper queues when no action taken" # Collect queues which have waiting time and next queue specified queues = TicketQueue.objects.filter( waiting_time__isnull=False, next_queue__isnull=False) now = datetime.datetime.now() for queue in queues: if queue.waiting_time and queue.next_queue: # Calculate the timeframe outside of which idle tickets should be # escalated delta = datetime.timedelta(seconds=int(queue.waiting_time)) timeframe = now - delta # Collect tickets ourside the timeframe tickets = queue.ticket_set.filter( date_created__lt=timeframe, status__active=True) for ticket in tickets: # Identify if any recent updates have been made on the ticket updates = ticket.updates.filter( date_created__gte=timeframe).exists() if not updates: ticket.queue = queue.next_queue ticket.auto_notify = False ticket.save() record = TicketRecord(record_type='update') record.format_message = 'Ticket automatically escalated from <a href="' + \ reverse('services_queue_view', args=[queue.id]) + \ '">' + unicode(queue) + '</a> to <a href="' + \ reverse('services_queue_view', args=[queue.next_queue.id]) + \ '">' + \ unicode(queue.next_queue) + '</a>.' record.author = ticket.creator record.save() record.about.add(ticket) ticket.set_last_updated()
def ticket_view(request, ticket_id, response_format='html'): "Ticket view" context = _get_default_context(request) agent = context['agent'] profile = request.user.profile ticket = get_object_or_404(Ticket, pk=ticket_id) if not profile.has_permission(ticket): return user_denied(request, message="You don't have access to this Ticket") if ticket.message: ticket.message.read_by.add(profile) if profile.has_permission(ticket, mode='x'): if request.POST: record = TicketRecord(sender=profile.get_contact()) record.record_type = 'manual' if ticket.message: record.message = ticket.message form = TicketRecordForm(agent, ticket, request.POST, instance=record) if form.is_valid(): record = form.save() record.save() record.set_user_from_request(request) record.about.add(ticket) ticket.set_last_updated() return HttpResponseRedirect( reverse('services_ticket_view', args=[ticket.id])) else: form = TicketRecordForm(agent, ticket) else: form = None context.update({'ticket': ticket, 'record_form': form}) return render_to_response('services/ticket_view', context, context_instance=RequestContext(request), response_format=response_format)
def ticket_view(request, ticket_id, response_format='html'): "Ticket view" context = _get_default_context(request) agent = context['agent'] profile = request.user.profile ticket = get_object_or_404(Ticket, pk=ticket_id) if not profile.has_permission(ticket): return user_denied(request, message="You don't have access to this Ticket") if ticket.message: ticket.message.read_by.add(profile) if profile.has_permission(ticket, mode='x'): if request.POST: record = TicketRecord(sender=profile.get_contact()) record.record_type = 'manual' if ticket.message: record.message = ticket.message form = TicketRecordForm( agent, ticket, request.POST, instance=record) if form.is_valid(): record = form.save() record.save() record.set_user_from_request(request) record.about.add(ticket) ticket.set_last_updated() return HttpResponseRedirect(reverse('services_ticket_view', args=[ticket.id])) else: form = TicketRecordForm(agent, ticket) else: form = None context.update({'ticket': ticket, 'record_form': form}) return render_to_response('services/ticket_view', context, context_instance=RequestContext(request), response_format=response_format)
def tickets_escalate(): "Automatically move tickets to upper queues when no action taken" # Collect queues which have waiting time and next queue specified queues = TicketQueue.objects.filter(waiting_time__isnull=False, next_queue__isnull=False) now = datetime.datetime.now() for queue in queues: if queue.waiting_time and queue.next_queue: # Calculate the timeframe outside of which idle tickets should be # escalated delta = datetime.timedelta(seconds=int(queue.waiting_time)) timeframe = now - delta # Collect tickets ourside the timeframe tickets = queue.ticket_set.filter(date_created__lt=timeframe, status__active=True) for ticket in tickets: # Identify if any recent updates have been made on the ticket updates = ticket.updates.filter( date_created__gte=timeframe).exists() if not updates: ticket.queue = queue.next_queue ticket.auto_notify = False ticket.save() record = TicketRecord(record_type='update') record.format_message = 'Ticket automatically escalated from <a href="' + \ reverse('services_queue_view', args=[queue.id]) + \ '">' + unicode(queue) + '</a> to <a href="' + \ reverse('services_queue_view', args=[queue.next_queue.id]) + \ '">' + \ unicode(queue.next_queue) + '</a>.' record.author = ticket.creator record.save() record.about.add(ticket) ticket.set_last_updated()