place.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:airbnb_clone 作者: bennettbuchanan 项目源码 文件源码
def handle_places():
    '''Returns all the places with a GET request, or adds a new city to the
    database with a POST request. The parameters passed to the POST request
    iterate through the data and set the corresponding attributes of the
    instance to  be inserted into the database. Will not set attribute passed
    as `updated_at` or `created_at`.
    '''
    if request.method == 'GET':
        list = ListStyle().list(Place.select(), request)
        return jsonify(list), 200

    elif request.method == 'POST':
        params = request.values
        place = Place()

        '''Check that all the required parameters are made in request.'''
        required = set(["owner", "city", "name"]) <= set(request.values.keys())
        if required is False:
            return jsonify(msg="Missing parameter."), 400

        for key in params:
            if key == 'updated_at' or key == 'created_at':
                continue
            setattr(place, key, params.get(key))
        place.save()
        return jsonify(place.to_dict()), 200
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号