def _doCreateObject(self, data): """Builds the kill object using the raw data provided from the database""" from Model.kill import Kill kill_ = Kill(data["id"]) pmapper = PlayerMapper() killer = pmapper.find(data["killer_player_id"]) victim = pmapper.find(data["victim_player_id"]) kill_.setKiller(killer) kill_.setVictim(victim) kill_.setVerified(data["verified"]) kill_.setTime(data["time"]) return kill_
def _doPost(self, dataObject): if "killer" and "victim" and "time" in dataObject: try: KM = KillMapper() GM = GameMapper() PM = PlayerMapper() if dataObject["killer"] is not None and dataObject["victim"] is not None: if "id" in dataObject["killer"] and "id" in dataObject["victim"]: # Get the user by ID killer = PM.find(dataObject["killer"]["id"]) victim = PM.find(dataObject["victim"]["id"]) try: proptime = parseDateTime(dataObject["time"]) except: raise BadRequest("""Invalid Time object sent, acceptable formats: Acceptable formats are: "YYYY-MM-DD HH:MM:SS.ssssss+HH:MM", "YYYY-MM-DD HH:MM:SS.ssssss", "YYYY-MM-DD HH:MM:SS+HH:MM", "YYYY-MM-DD HH:MM:SS" """) if killer is None or victim is None: raise NotFound("Either the victim or the killer were invalid player objects") else: raise BadRequest("Arguments provided for this kill are invalid.") else: raise BadRequest("Arguments provided for this kill are invalid.") kill = Kill() kill.setKiller(killer) kill.setVictim(victim) kill.setVerified(False) kill.setTime(proptime) KM.insert(kill) return self._response(kill.dict(3), CODE.CREATED) except mdb.DatabaseError, e: raise ServerError("Unable to search the user database (%s)" % e.args[1])
def _doCreateObject(self, data): """Builds the kill object using the raw data provided from the database""" from Model.kill import Kill from Model.qrzarplayer import QRzarPlayer from Model.deferredobject import DeferredObject kill_ = Kill(data["id"]) killer = DeferredObject(QRzarPlayer(data["killer_player_id"])) victim = DeferredObject(QRzarPlayer(data["victim_player_id"])) kill_.setKiller(killer) kill_.setVictim(victim) kill_.setVerified(data["verified"]) kill_.setTime(data["time"]) return kill_
else: raise BadRequest("Arguments provided for this kill are invalid.") if killer.getId() == victim.getId(): raise Conflict("You cannot kill yourself, that's a sin!!!!!11111OMGZ") if killer.getAlive() is False: raise Conflict("You are not alive, therefore you can't tag someone else!") if victim.getAlive() is False: raise Conflict("Victim is already dead, let him rest!") kill = Kill() kill.setKiller(killer) kill.setVictim(victim) kill.setVerified(False) # Even though unverified, let's set that user as dead for now victim.setAlive(False) try: PM.update(victim) except mdb.DatabaseError, e: raise ServerError("Unable to update the victim record in the database (%s)" % e.args[1]) kill.setTime(datetime.now()) try: KM.insert(kill) except mdb.DatabaseError, e: raise ServerError("Unable to create the kill record in the db (%s)" % e.args[1])