Ejemplo n.º 1
0
def make_request():
    data = request.json
    package = {"menteeId": current_user.id, "mentorId": data["mentorId"], "pitch": data["pitch"], "accepted": data["accepted"]}
    newRequest = Request(**package)
    db.session.add(newRequest)
    db.session.commit()
    return newRequest.to_dict()
Ejemplo n.º 2
0
def new_request():
    """
    Create new request
    """
    form = RequestForm()
    # Get the csrf_token from the request cookie and put it into the
    # form manually to validate_on_submit can be used
    user = None
    if current_user.is_authenticated:
        user = current_user.to_dict()
    form['csrf_token'].data = request.cookies['csrf_token']
    if form.validate_on_submit():
        # Add the user to the session, we are logged in!
        new_request = Request(title=form.data['title'],
                              active=False,
                              userId=user["id"])
        db.session.add(new_request)
        db.session.commit()
        return new_request.to_dict()
    return {'errors': validation_errors_to_error_messages(form.errors)}, 401
Ejemplo n.º 3
0
def make_hit_request(id):
    player = Player.query.get(id)

    form = RequestForm()

    form['csrf_token'].data = request.cookies['csrf_token']

    if form.validate_on_submit():
        hit_request = Request(date=form.data['date'],
                              requester_id=current_user.id,
                              requestee_id=id,
                              court_id=form.data['court_id'],
                              response=None)
        db.session.add(hit_request)
        db.session.commit()

        return jsonify(hit_request.to_dict())
    else:
        return ({"errors": "errors"})

    return ({"errors": "errors"})