def update_proposal(id): errors = Proposal.validate(request.json) if len(errors) > 0: return jsonify({'errors': errors}), 400 user = g.user proposal = session.query(Proposal).filter(and_( \ Proposal.id == id, \ Proposal.user_proposed_from == user.id \ )) if not proposal: abort(400) user_proposed_from = user.id request_id = request.json.get('request_id') req = session.query(Request).filter_by(id=request_id).first() if req is None: return jsonify({'errors': 'Request is not exist'}) else: user_proposed_to = req.user_id proposal = { 'request_id': request_id, 'user_proposed_from': user_proposed_from, 'user_proposed_to': user_proposed_to } proposal.update(proposal) session.commit() return jsonify({'response': True}), 201
def update_proposal(id): user = g.user if not request.json: abort(400) errors = Proposal.validate(request.json) if len(errors) == 0: return jsonify( { 'result': True } ) return jsonify({"message": "The request is invalid."},errors = [error for error in errors]) ,400
def update_proposal(id): user = g.user if not request.json: abort(400) errors = Proposal.validate(request.json) if len(errors) == 0: return jsonify({'result': True}) return jsonify({"message": "The request is invalid."}, errors=[error for error in errors]), 400
def new_proposal(): user = g.user if not request.json: abort(400) errors = Proposal.validate(request.json) if len(errors) == 0: request_id = request.json.get('request_id') r = session.query(Request).filter_by(id = request_id).first() if r is None: return jsonify({"message": "The request is invalid."},errors = [dict({"request_id":"Request does not exist"})]) ,400 if user.id == r.user_id: abort(403) proposal = Proposal(user_proposed_from = user.id, user_proposed_to = r.user_id, request_id = r.id ) session.add(proposal) session.commit() return jsonify( { 'result': True } ) return jsonify({"message": "The request is invalid."},errors = [error for error in errors]) ,400
def create_newproposal(): errors = Proposal.validate(request.json) if len(errors) == 0: user_proposed_from = g.user.id request_id = request.json.get('request_id') req = session.query(Request).filter_by(id=request_id).first() if req is None: return jsonify({'errors': 'Request is not exist'}) else: user_proposed_to = req.user_id proposal = Proposal(request_id = request_id, \ user_proposed_from = user_proposed_from, user_proposed_to=user_proposed_to ) session.add(proposal) session.commit() return jsonify({'response': True}), 201 else: return jsonify({'errors': errors})
def new_proposal(): user = g.user if not request.json: abort(400) errors = Proposal.validate(request.json) if len(errors) == 0: request_id = request.json.get('request_id') r = session.query(Request).filter_by(id=request_id).first() if r is None: return jsonify( {"message": "The request is invalid."}, errors=[dict({"request_id": "Request does not exist"})]), 400 if user.id == r.user_id: abort(403) proposal = Proposal(user_proposed_from=user.id, user_proposed_to=r.user_id, request_id=r.id) session.add(proposal) session.commit() return jsonify({'result': True}) return jsonify({"message": "The request is invalid."}, errors=[error for error in errors]), 400