Пример #1
0
def update_date(id):
    user = g.user
    if not request.json:
        abort(400)
    date = session.query(MealDate).filter_by(id = id).first()
    if data is None:
        abort(404)
    errors = MealDate.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
Пример #2
0
def update_date(id):
    user = g.user
    if not request.json:
        abort(400)
    date = session.query(MealDate).filter_by(id=id).first()
    if data is None:
        abort(404)
    errors = MealDate.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
Пример #3
0
def create_newdate():
    errors = MealDate.validate(request.json)
    if len(errors) == 0:
        proposal_id = request.json.get('proposal_id')
        accept_proposal = request.json.get('accept_proposal')

        proposal = session.query(Proposal).filter_by(id=proposal_id).first()
        if proposal is None:
            return jsonify({'response': False})

        req = proposal.request
        if req.filled:
            return jsonify({'response': False})
        if accept_proposal:
            proposal.update({'filled': True})
            req.update({'filled': True})

            restaurant_name = ''
            restaurant_address = ''
            restaurant_picture = ''

            try:
                restaurant = findARestaurant(req.meal_type,
                                             req.location_string)
                if type(restaurant) == dict:
                    restaurant_name = restaurant['name']
                    restaurant_address = restaurant['address']
                    restaurant_picture = restaurant['image_url']
            except Exception as e:
                print e

            date = MealDate(
                user_1 = req.user_id,   \
                user_2 = proposal.user_proposed_from,   \
                restaurant_name =  restaurant_name,     \
                restaurant_address = restaurant_address,    \
                restaurant_picture = restaurant_picture,    \
                meal_time = req.meal_time   \
            )
            session.add(date)
            session.commit()
            return jsonify({'response': True}), 201
        else:
            session.delete(proposal)
            session.commit()
            return jsonify({'response': 'Deleted proposal'})
    else:
        return jsonify({'errors': errors}), 400
Пример #4
0
def new_date():
    user = g.user
    if not request.json:
        abort(400)
    errors = MealDate.validate(request.json)
    if len(errors) == 0:
        proposalsa_id = request.json.get('proposal_id')
        accept_proposal = request.json.get('accept_proposal')
        proposal = session.query(Proposal).filter_by(id=proposal_id).first()
        if proposal is None:
            abort(404)
        r = proposal.request
        if r.filled:
            return jsonify({'result': False})
        if accept_proposal:
            proposal.filled = True
            r.filled = True
            restaurant_picture = "No Restaurants Found"
            restaurant_address = "No Restaurants Found"
            restaurant_name = "No Restaurants Found"
            try:
                result = findARestaurant(r.meal_type, r.location_string)
                if type(result) == dict:
                    restaurant_picture = result.get('name')
                    restaurant_address = result.get('address')
                    restaurant_name = result.get('image')
            except Exception as e:
                print e
            date = MealDate(meal_time=r.meal_time,
                            user_1=r.user_id,
                            user_2=proposal.user_proposed_from,
                            restaurant_picture=restaurant_picture,
                            restaurant_address=restaurant_address,
                            restaurant_name=restaurant_name)
            session.add(date)
            session.add(proposal)
            session.add(r)
            session.commit()
            return jsonify({'result': True})
        else:
            session.delete(proposal)
            session.commit()
            return jsonify({'result': True})

    return jsonify({"message": "The request is invalid."},
                   errors=[error for error in errors]), 400
Пример #5
0
def new_date():
    user = g.user
    if not request.json:
        abort(400)
    errors = MealDate.validate(request.json)
    if len(errors) == 0:
        proposalsa_id = request.json.get('proposal_id')
        accept_proposal = request.json.get('accept_proposal')
        proposal = session.query(Proposal).filter_by(id = proposal_id).first()
        if proposal is None:
            abort(404)
        r = proposal.request
        if r.filled:
            return  jsonify( { 'result': False } )
        if accept_proposal:
            proposal.filled = True
            r.filled = True
            restaurant_picture = "No Restaurants Found"
            restaurant_address = "No Restaurants Found"
            restaurant_name =  "No Restaurants Found"
            try:
                result = findARestaurant(r.meal_type, r.location_string)
                if type(result) == dict:
                    restaurant_picture = result.get('name')
                    restaurant_address = result.get('address')
                    restaurant_name =  result.get('image')
            except Exception as e:
                 print e
            date = MealDate(meal_time = r.meal_time, user_1 = r.user_id , user_2 = proposal.user_proposed_from, restaurant_picture = restaurant_picture,restaurant_address = restaurant_address, restaurant_name= restaurant_name )
            session.add(date)
            session.add(proposal)
            session.add(r)
            session.commit()
            return  jsonify( { 'result': True } )
        else:
            session.delete(proposal)
            session.commit()
            return  jsonify( { 'result': True } )


    return jsonify({"message": "The request is invalid."},errors = [error for error in errors])  ,400