Example #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
Example #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
Example #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()
Example #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
Example #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
Example #7
0
    def post(self):
        claims = get_jwt_claims()
        if not claims['active']:
            return {
                'message':
                'Error # 25 in Location Resource, You have not been activated by the admin'
            }, 400

        username = UserModel.find_by_user(get_jwt_identity())
        approved_zid_list = VbusinessModel.find_all_business_list()

        if username.businessId not in approved_zid_list:
            return {
                'message':
                'Error # 182 in Customer Resource, You have not been authorized to use this business'
            }, 400

        json_data = request.get_json()

        if not json_data:
            return {'message': 'No input data provided'}, 400

        try:
            data = opmobSchemas.load(json_data).data
        except ValidationError as err:
            return err.messages, 400

        locationDetail = LocationModel(ztime=data['ztime'],
                                       zid=username.businessId,
                                       xemp=username.employeeCode,
                                       xlat=data['xlat'],
                                       xlong=data['xlong'])

        try:
            locationDetail.save_to_db()
            return {'message': 'Location Saved'}, 200
        except:
            return {'message': 'Something went wrong'}, 400