예제 #1
0
def _update_status(body, report, user):
    """
        Update report status
    """
    if body['status'].lower() not in STATUS:
        return 400, {'status': 'Bad Request', 'code': 400, 'message': 'Invalid status'}

    # Detach report if requested status is "New"
    # If status in ['attached', 'validated'], try to attach to existing ticket
    #
    if body['status'].lower() == 'new':
        if report.ticket and report.ticket.reportTicket.count() == 1:  # Close corresponding ticket
            ticket = Ticket.objects.get(id=report.ticket.id)
            ticket.status = 'Closed'
            ticket.save()
        body['ticket'] = None
        report.status = 'New'
        report.save()
    elif report.status.lower() == 'tovalidate' and body['status'].lower() == 'attached':
        report.status = 'Attached'
        report.save()
        utils.email_queue.enqueue(
            'report.reparse_validated',
            report_id=report.id,
            user_id=user.id,
        )
        return 201, {'status': 'OK', 'code': 201, 'message': 'Report successfully updated'}
    elif body['status'].lower() == 'attached' and not report.ticket and all((report.category, report.defendant, report.service)):
        return TicketsController.create(body, user)

    return 200, body
예제 #2
0
def create_ticket():
    """ Post a new ticket
    """
    body = request.get_json()
    code, resp = TicketsController.create(body, g.user)
    return code, resp