def _mkflag(self, flag_type, is_file=False): """ Creates the flag in the database """ box = Box.by_uuid(self.get_argument("box_uuid", "")) if box is None: raise ValidationError("Box does not exist") if is_file: if not hasattr(self.request, "files") or not "flag" in self.request.files: raise ValidationError("No file in request") token = self.request.files["flag"][0]["body"] else: token = self.get_argument("token", "") name = self.get_argument("flag_name", "") description = self.get_argument("description", "") reward = self.get_argument("reward", "") flag = Flag.create_flag(flag_type, box, name, token, description, reward) flag.capture_message = self.get_argument("capture_message", "") flag.case_sensitive = self.get_argument("case-sensitive", 1) flag.order = len(box.flags) + 1 lock = Flag.by_uuid(self.get_argument("lock_uuid", "")) if lock: flag.lock_id = lock.id else: flag.lock_id = None self.add_attachments(flag) self.dbsession.add(flag) self.dbsession.commit() choices = self.get_arguments("addmore[]", strip=True) if choices is not None: for item in choices: FlagChoice.create_choice(flag, item) self.redirect("/admin/view/game_objects#%s" % box.uuid)
def edit_choices(self, flag, arguments): """ Edit flag multiple choice items """ choiceitems = {} currentchoices = json.loads(flag.choices()) for item in arguments: if item.startswith("choice"): if arguments[item][0] != "": uuidsplit = item.split("uuid-") if len(uuidsplit) > 1: choiceitems[uuidsplit[1]] = arguments[item][0] else: for flagoption in arguments[item]: if len(flagoption) > 0: # add choice FlagChoice.create_choice(flag, flagoption) for choice in currentchoices: if not choice["uuid"] in choiceitems: # delete choice flagchoice = FlagChoice.by_uuid(choice["uuid"]) self.dbsession.delete(flagchoice) for choice in choiceitems: flagchoice = FlagChoice.by_uuid(choice) if choiceitems[choice] != flagchoice.choice: # update choice flagchoice.choice = choiceitems[choice] self.dbsession.add(flagchoice) self.dbsession.commit()
def _mkflag(self, flag_type, is_file=False): ''' Creates the flag in the database ''' box = Box.by_uuid(self.get_argument('box_uuid', '')) if box is None: raise ValidationError('Box does not exist') if is_file: if not hasattr(self.request, 'files') or not 'flag' in self.request.files: raise ValidationError('No file in request') token = self.request.files['flag'][0]['body'] else: token = self.get_argument('token', '') name = self.get_argument('flag_name', '') description = self.get_argument('description', '') reward = self.get_argument('reward', '') flag = Flag.create_flag(flag_type, box, name, token, description, reward) flag.capture_message = self.get_argument('capture_message', '') flag.case_sensitive = self.get_argument('case-sensitive', 1) lock = Flag.by_uuid(self.get_argument('lock_uuid', '')) if lock: flag.lock_id = lock.id else: flag.lock_id = None self.add_attachments(flag) self.dbsession.add(flag) self.dbsession.commit() choices = self.get_arguments('addmore[]', strip=True) if choices is not None: for item in choices: FlagChoice.create_choice(flag, item) self.redirect("/admin/view/game_objects#%s" % box.uuid)
def edit_choices(self, flag, arguments): ''' Edit flag multiple choice items ''' choiceitems = {} currentchoices = json.loads(flag.choices()) for item in arguments: if item.startswith("choice"): if arguments[item][0] != "": uuidsplit = item.split("uuid-") if len(uuidsplit) > 1: choiceitems[uuidsplit[1]] = arguments[item][0] else: for flagoption in arguments[item]: if flagoption != "": # add choice FlagChoice.create_choice(flag, flagoption) for choice in currentchoices: if not choice['uuid'] in choiceitems: # delete choice flagchoice = FlagChoice.by_uuid(choice['uuid']) self.dbsession.delete(flagchoice) for choice in choiceitems: flagchoice = FlagChoice.by_uuid(choice) if choiceitems[choice] != flagchoice.choice: # update choice flagchoice.choice = choiceitems[choice] self.dbsession.add(flagchoice) self.dbsession.commit()
def _mkflag(self, flag_type, is_file=False): ''' Creates the flag in the database ''' box = Box.by_uuid(self.get_argument('box_uuid', '')) if box is None: raise ValidationError('Box does not exist') if is_file: if not hasattr(self.request, 'files') or not 'flag' in self.request.files: raise ValidationError('No file in request') token = self.request.files['flag'][0]['body'] else: token = self.get_argument('token', '') name = self.get_argument('flag_name', '') description = self.get_argument('description', '') reward = self.get_argument('reward', '') flag = Flag.create_flag( flag_type, box, name, token, description, reward) flag.capture_message = self.get_argument('capture_message', '') flag.case_sensitive = self.get_argument('case-sensitive', 1) lock = Flag.by_uuid(self.get_argument('lock_uuid', '')) if lock: flag.lock_id = lock.id else: flag.lock_id = None self.add_attachments(flag) self.dbsession.add(flag) self.dbsession.commit() choices = self.get_arguments('addmore[]', strip=True) if choices is not None: for item in choices: FlagChoice.create_choice(flag, item) self.redirect("/admin/view/game_objects#%s" % box.uuid)
def choicelist(self): #excludes the choice uuid choices = [] if self._type == FLAG_CHOICE: choicelist = FlagChoice.by_flag_id(self.id) if choicelist is not None and len(choicelist) > 0: for flagchoice in choicelist: choices.append(flagchoice.choice) return json.dumps(choices)
def choices(self): #inlucdes the choice uuid - needed for editing choice choices = [] if self._type == FLAG_CHOICE: choicelist = FlagChoice.by_flag_id(self.id) if choicelist is not None and len(choicelist) > 0: for flagchoice in choicelist: choices.append(flagchoice.to_dict()) return json.dumps(choices)