Example #1
0
    def create(self, request, *args, **kwargs):
        ticket = self.get_ticket(request, kwargs)
        if isinstance(ticket, Ticket):
            profile = request.user.get_profile()
            if profile.has_permission(ticket, mode='x'):
                context = _get_default_context(request)
                agent = context['agent']

                record = TicketRecord(sender = profile.get_contact())
                record.record_type = 'manual'
                if ticket.message:
                    record.message = ticket.message
                form = TicketRecordForm(agent, ticket, request.data, 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 record
                else:
                    self.status = 400
                    return form.errors
            else:
                return rc.FORBIDDEN
        else:
            return ticket
Example #2
0
def ticket_view(request, ticket_id, response_format='html'):
    "Ticket view"
    
    context = _get_default_context(request)
    agent = context['agent']
    profile = request.user.get_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)