コード例 #1
0
ファイル: tickets.py プロジェクト: quanpower/flicket
def create_ticket():
    data = request.get_json() or {}

    if 'title' not in data or 'content' not in data or 'category_id' not in data or 'ticket_priority_id' not in data:
        return bad_request('Must include title, content, category_id and ticket_priority_id.')

    if not isinstance(data['category_id'], int) or not isinstance(data['ticket_priority_id'], int):
        return bad_request('ticket_priority_id and category_id must be integers.')

    if not FlicketCategory.query.filter_by(id=data['category_id']).first():
        return bad_request('not a valid category_id')

    if not FlicketPriority.query.filter_by(id=data['ticket_priority_id']).first():
        return bad_request('not a valid ticket_priority_id')

    ticket = FlicketTicket()
    ticket.from_dict(data)
    ticket.started_id = g.current_user.id
    ticket.date_added = datetime.datetime.now()
    ticket.status_id = 1

    db.session.add(ticket)
    db.session.commit()

    response = jsonify(ticket.to_dict())
    response.status_code = 201
    response.headers['Location'] = url_for('bp_api.get_ticket', id=ticket.id)

    return response
コード例 #2
0
def create_ticket():
    data = request.get_json() or {}

    if "title" not in data or "content" not in data or "domain_id" not in data:
        return bad_request("Must include title, content, domain_id")

    if not FlicketDomain.query.filter_by(id=data["domain_id"]).first():
        return bad_request("not a valid domain_id")

    ticket = FlicketTicket()
    ticket.from_dict(data)
    ticket.started_id = g.current_user.id
    ticket.date_added = datetime.datetime.now()
    ticket.status_id = 1

    db.session.add(ticket)
    db.session.commit()

    response = jsonify(ticket.to_dict())
    response.status_code = 201
    response.headers["Location"] = url_for("bp_api.get_ticket", id=ticket.id)

    return response