Exemple #1
0
 def PUT(self, race_id, vehicle_id, station, **data):
     race_id = Validator.require_int(race_id)
     vehicle_id = Validator.require_int(vehicle_id)
     station = Validator.require_int(station)
     resource = self.find({
         "race_id": race_id,
         "vehicle_id": vehicle_id,
         "station": station
     })
     if resource is None:
         resource = {
             "race_id": race_id,
             "vehicle_id": vehicle_id,
             "station": station
         }
         data = Validator.validate(data,
                                   self.__class__.fields,
                                   self.__class__.defaults,
                                   require_all=True)
         self.resources.append(resource)
     else:
         data = Validator.validate(data,
                                   self.__class__.fields,
                                   self.__class__.defaults,
                                   require_all=False)
     for field in data:
         resource[field] = data[field]
     self.save()
     return self.response(resource)
    def DELETE(self, race_id, vehicle_id, **data):
        race_id = Validator.require_int(race_id)
        vehicle_id = Validator.require_int(vehicle_id)
        filter = {"race_id": race_id, "vehicle_id": vehicle_id}
        resource = self.find(filter)
        if resource is not None:
            response = deepcopy(resource)
            self.remove(filter)
            return self.response(response)

        Validator.fail_found()
    def DELETE(self, race_id, vehicle_id, **data):
        race_id = Validator.require_int(race_id)
        vehicle_id = Validator.require_int(vehicle_id)
        filter = {"race_id": race_id, "vehicle_id": vehicle_id}
        resource = self.find(filter)
        if resource is not None:
            response = deepcopy(resource)
            self.remove(filter)
            return self.response(response)

        Validator.fail_found()
    def GET(self, race_id=None, vehicle_id=None, **data):
        if vehicle_id is None:
            if race_id is None:
                return self.response(self.sort(self.findall(data)))
            race_id = Validator.require_int(race_id)
            data["race_id"] = race_id
            return self.response(self.sort(self.findall(data)))
        vehicle_id = Validator.require_int(vehicle_id)

        resource = self.find({"race_id": race_id, "vehicle_id": vehicle_id})

        return self.response(resource)
    def GET(self, race_id=None, vehicle_id=None, **data):
        if vehicle_id is None:
            if race_id is None:
                return self.response(self.sort(self.findall(data)))
            race_id = Validator.require_int(race_id)
            data["race_id"] = race_id
            return self.response(self.sort(self.findall(data)))
        vehicle_id = Validator.require_int(vehicle_id)

        resource = self.find({"race_id": race_id, "vehicle_id": vehicle_id})

        return self.response(resource)
 def PUT(self, race_id, vehicle_id, **data):
     race_id = Validator.require_int(race_id)
     vehicle_id = Validator.require_int(vehicle_id)
     resource = self.find({"race_id": race_id, "vehicle_id": vehicle_id})
     if resource is None:
         resource = {"race_id": race_id, "vehicle_id": vehicle_id}
         data = Validator.validate(data, self.__class__.fields, self.__class__.defaults, require_all=True)
         self.resources.append(resource)
     else:
         data = Validator.validate(data, self.__class__.fields, self.__class__.defaults, require_all=False)
     for field in data:
         resource[field] = data[field]
     self.save()
     return self.response(resource)
Exemple #7
0
 def is_admin(self, **data):
     if "user_id" not in data or data is None:
         return False
     user_id = Validator.require_int(data["user_id"])
     if 0 <= user_id < len(self.list):
         user = self.list[user_id]
         if user["role"] == "ADMIN":
             return True
     return False
Exemple #8
0
 def is_module_admin(self, module_id=None, **data):
     if "user_id" not in data or data is None:
         return False
     user_id = Validator.require_int(data["user_id"])
     if 0 <= user_id < len(self.list):
         user = self.list[user_id]
         if user["role"] != "ADMIN" and module_id is not None:
             for u_module_id in user["module"]:
                 if u_module_id == module_id:
                     return True
             return False
         return True
     return False