Esempio n. 1
0
 def delete(self, name):
     location = LocationModel.find_by_name(name)
     if location:
         location.delete_from_db()
     else:
         return {'error': 'Location not found'}, 404
     return {'success': 'location deleted'}, 202
Esempio n. 2
0
 def put(self, name):
     data = json.loads(request.data)
     location = LocationModel.find_by_name(name)
     if location:
         location.update(**data)
     else:
         return {'error': 'Location not found'}, 404
     location.save_to_db(commit=True)
     return location.json(), 201
Esempio n. 3
0
 def get(self, name=None):
     queryData = request.args.to_dict()
     if name:
         location = LocationModel.find_by_name(name)
         if location:
             return location.json(), 200
         else:
             return {'error': 'location not found'}, 404
     locations = LocationModel.find(**queryData)
     return {'locations': list(map(lambda x: x.json(), locations))}, 200
Esempio n. 4
0
    def post(self, name):
        if LocationModel.find_by_name(name):
            return {
                'message': "A location named '{}' already exists.".format(name)
            }, 400

        location = LocationModel(name)
        try:
            location.save_to_db()
        except:
            return {"message": "An error occurred creating the location."}, 500

        return location.json(), 201
Esempio n. 5
0
 def post(self, name=None):
     data = json.loads(request.data)
     name = data.get("name", name)
     if LocationModel.find_by_name(name):
         return {
             'error':
             "A location with name '{}' already exists.".format(name)
         }, 400
     location = LocationModel(**data)
     try:
         location.save_to_db()
     except:
         return {"error": "An error occurred creating the location."}, 500
     return location.json(), 201
    def post(self, name):
        if LocationModel.find_by_name(name):
            return {
                'message':
                "A location with name '{}' already exists.".format(name)
            }, 400

        data = Location.parser.parse_args()

        location = LocationModel(
            name, **data)  # (name, data['name'], data['school_id'])

        try:
            location.save_to_db()
        except:
            return {'message': 'An error ocurred inserting the location'}, 500

        return location.json(), 201
Esempio n. 7
0
 def get(self, name):
     location = LocationModel.find_by_name(name)
     if location:
         return location.json()
     return {'message': 'Location not found'}, 404
Esempio n. 8
0
    def delete(self, name):
        location = LocationModel.find_by_name(name)
        if location:
            location.delete_from_db()

        return {'message': 'Location deleted'}
Esempio n. 9
0
 def get(self, name):
     location = LocationModel.find_by_name(name)
     if location:
         return location.childinlocation()