Exemplo n.º 1
0
 def post(self, location_id):
     if LocationModel.find_by_id(location_id):
         return {"msg": "Location already exist"}, 400
     data = self.parser.parse_args()
     new_loc = LocationModel(location_id, **data)
     new_loc.save_to_db()
     return new_loc.json(), 201
Exemplo n.º 2
0
    def post(self, name):
        """adds a new location"""
        data = Location.parser.parse_args()
        if LocationModel.find_location_by_name(name):
            return {"message": "A location with name '{}' already exists. Please try to use another name".format(name)}, 400

        location = LocationModel(name, **data)
        try:
            location.save_to_db()
        except:
            return {"message": "An error ocurred inserting the location."}, 500
        return {"location_result": location.json()}, 201
Exemplo n.º 3
0
    def put(self, location_id):
        data = self.parser.parse_args()

        location = LocationModel.find_by_id(location_id)

        if location is None:
            location = LocationModel(location_id, **data)

        else:
            location.location_name = data["location_name"]

        location.save_to_db()
        return location.json()
Exemplo 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
Exemplo 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
Exemplo n.º 6
0
    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