def func(self, args, request): if not args: raise MudderyError(ERR.missing_args, 'Missing arguments.') if 'typeclass' not in args: raise MudderyError(ERR.missing_args, 'Missing the argument: "typeclass".') typeclass = args["typeclass"] width = args.get("width", 0) height = args.get("height", 0) forms = data_edit.query_object_form(typeclass, typeclass, None) new_area = [] for form in forms: values = { field["name"]: field["value"] for field in form["fields"] if "value" in field } values["width"] = width values["height"] = height new_area.append({"table": form["table"], "values": values}) obj_key = data_edit.save_object_form(new_area, typeclass, "") data = {"key": obj_key, "width": width, "height": height} return success_response(data)
class upload_resources(BaseRequestProcesser): """ Upload a zip package of resources. Args: args: None """ path = "upload_resources" name = "" def func(self, args, request): file_obj = request.FILES.get("file", None) if not file_obj: raise MudderyError(ERR.missing_args, 'Missing zip files.') with tempfile.TemporaryFile() as fp: try: for chunk in file_obj.chunks(): fp.write(chunk) importer.unzip_resources_all(fp) except Exception, e: logger.log_tracemsg("Upload error: %s" % e.message) raise MudderyError(ERR.upload_error, e.message) return success_response("success")
def func(self, args, request): if not args: raise MudderyError(ERR.missing_args, 'Missing arguments.') if 'tables' not in args: raise MudderyError(ERR.missing_args, 'Missing the argument: "tables".') if 'base_typeclass' not in args: raise MudderyError(ERR.missing_args, 'Missing the argument: "base_typeclass".') if 'obj_typeclass' not in args: raise MudderyError(ERR.missing_args, 'Missing the argument: "obj_typeclass".') if 'obj_key' not in args: raise MudderyError(ERR.missing_args, 'Missing the argument: "obj_key".') tables = args["tables"] base_typeclass = args["base_typeclass"] obj_typeclass = args["obj_typeclass"] obj_key = args["obj_key"] new_key = data_edit.save_object_form(tables, obj_typeclass, obj_key) if obj_key != new_key: data_edit.update_object_key(obj_typeclass, obj_key, new_key) return success_response(new_key)
def func(self, args, request): if not args: raise MudderyError(ERR.missing_args, 'Missing arguments.') if 'typeclass' not in args: raise MudderyError(ERR.missing_args, 'Missing the argument: "typeclass".') typeclass = args["typeclass"] width = args.get("width", 0) height = args.get("height", 0) forms = data_edit.query_object_form(typeclass, typeclass, None) new_area = [] for form in forms: values = {field["name"]: field["value"] for field in form["fields"] if "value" in field} values["width"] = width values["height"] = height new_area.append({ "table": form["table"], "values": values }) obj_key = data_edit.save_object_form(new_area, typeclass, "") data = {"key": obj_key, "width": width, "height": height} return success_response(data)
def func(self, args, request): if not args: raise MudderyError(ERR.missing_args, 'Missing arguments.') if 'action' not in args: raise MudderyError(ERR.missing_args, 'Missing the argument: "action".') if 'event' not in args: raise MudderyError(ERR.missing_args, 'Missing the argument: "event".') if 'values' not in args: raise MudderyError(ERR.missing_args, 'Missing the argument: "values".') action_type = args["action"] event_key = args["event"] values = args["values"] # Get action's data. action = EVENT_ACTION_SET.get(action_type) if not action: raise MudderyError(ERR.no_table, "Can not find action: %s" % action_type) table_name = action.model_name # Remove old records. data_edit.delete_records(table_name, event_key=event_key) # Add new data. for value in values: data_edit.save_form(value, table_name) return success_response("success")
def func(self, args, request): if not args: raise MudderyError(ERR.missing_args, 'Missing arguments.') if 'typeclass' not in args: raise MudderyError(ERR.missing_args, 'Missing the argument: "typeclass".') if 'location' not in args: raise MudderyError(ERR.missing_args, 'Missing the argument: "location".') if 'destination' not in args: raise MudderyError(ERR.missing_args, 'Missing the argument: "destination".') typeclass = args["typeclass"] location = args["location"] destination = args["destination"] forms = data_edit.query_object_form(typeclass, typeclass, None) new_exit = [] for form in forms: values = {field["name"]: field["value"] for field in form["fields"] if "value" in field} values["location"] = location values["destination"] = destination new_exit.append({ "table": form["table"], "values": values }) obj_key = data_edit.save_object_form(new_exit, typeclass, "") data = {"key": obj_key} return success_response(data)
def func(self, args, request): if not args: raise MudderyError(ERR.missing_args, 'Missing arguments.') if 'typeclass' not in args: raise MudderyError(ERR.missing_args, 'Missing the argument: "typeclass".') if 'location' not in args: raise MudderyError(ERR.missing_args, 'Missing the argument: "location".') if 'destination' not in args: raise MudderyError(ERR.missing_args, 'Missing the argument: "destination".') typeclass = args["typeclass"] location = args["location"] destination = args["destination"] forms = data_edit.query_object_form(typeclass, typeclass, None) new_exit = [] for form in forms: values = { field["name"]: field["value"] for field in form["fields"] if "value" in field } values["location"] = location values["destination"] = destination new_exit.append({"table": form["table"], "values": values}) obj_key = data_edit.save_object_form(new_exit, typeclass, "") data = {"key": obj_key} return success_response(data)
class ApplyChanges(BaseRequestProcesser): """ Query all tables' names. Args: None. """ path = "apply_changes" name = "" def func(self, args, request): try: # reload system data # import_syetem_data() # reload localized strings # LOCALIZED_STRINGS_HANDLER.reload() # rebuild the world build_all() # send client settings client_settings = GAME_SETTINGS.get_client_settings() text = json.dumps({"settings": client_settings}) SESSIONS.announce_all(text) # restart the server SESSIONS.announce_all("Server restarting ...") SESSIONS.portal_restart_server() except Exception, e: message = "Can not build the world: %s" % e logger.log_tracemsg(message) raise MudderyError(ERR.build_world_error, message) return success_response("success")
class QueryFormFirstRecord(BaseRequestProcesser): """ Query a form of the first record of a table. Args: table: (string) table's name """ path = "query_form_first_record" name = "" def func(self, args, request): if 'table' not in args: raise MudderyError(ERR.missing_args, 'Missing the argument: "table".') table_name = args["table"] try: record = general_query_mapper.get_the_first_record(table_name) if record: record_id = record.id else: record_id = None except Exception, e: raise MudderyError(ERR.invalid_form, "Wrong table: %s." % table_name) data = data_edit.query_form(table_name, id=record_id) return success_response(data)
def func(self, args, request): if 'table' not in args: raise MudderyError(ERR.missing_args, 'Missing argument: "table".') table_name = args["table"] data = general_query.query_table(table_name) return success_response(data)
def func(self, args, request): if 'object' not in args: raise MudderyError(ERR.missing_args, 'Missing the argument: "object".') object_key = args["object"] data = data_query.query_object_events(object_key) return success_response(data)
def func(self, args, request): if 'dialogue' not in args: raise MudderyError(ERR.missing_args, 'Missing arguments.') dialogue_key = args["dialogue"] data = data_query.query_dialogue_sentences(dialogue_key) return success_response(data)
def func(self, args, request): if ('object' not in args): raise MudderyError(ERR.missing_args, 'Missing arguments.') object_key = args["object"] data = data_query.query_object_events(object_key) return success_response(data)
def func(self, args, request): """ Get the server's status. Args: args: None """ return success_response("running")
def func(self, args, request): if 'typeclass' not in args: raise MudderyError(ERR.missing_args, 'Missing the argument: "typeclass".') typeclass = args["typeclass"] data = data_query.query_event_triggers(typeclass) return success_response(data)
def func(self, args, request): if 'table' not in args: raise MudderyError(ERR.missing_args, 'Missing the argument: "table".') table_name = args["table"] data = general_query.query_table(table_name) return success_response(data)
def func(self, args, request): """ Logout the editor. Args: args: None """ auth.logout(request) return success_response("success")
def func(self, args, request): if 'action' not in args or 'event' not in args: raise MudderyError(ERR.missing_args, 'Missing arguments.') action_type = args["action"] event_key = args["event"] data = data_edit.query_event_action_forms(action_type, event_key) return success_response(data)
def func(self, args, request): if 'typeclass' not in args: raise MudderyError(ERR.missing_args, 'Missing the argument: "typeclass".') typeclass_key = args["typeclass"] # Query data. data = data_query.query_typeclass_table(typeclass_key) return success_response(data)
def func(self, args, request): if ('type' not in args or 'key' not in args): raise MudderyError(ERR.missing_args, 'Missing arguments.') action_type = args["type"] event_key = args["key"] data = data_query.query_event_action_data(action_type, event_key) return success_response(data)
def func(self, args, request): if 'table' not in args: raise MudderyError(ERR.missing_args, 'Missing argument: "table".') table_name = args["table"] record = args.get('record', None) data = data_edit.query_form(table_name, record) return success_response(data)
def func(self, args, request): if ('table' not in args) or ('record' not in args): raise MudderyError(ERR.missing_args, 'Missing arguments.') table_name = args["table"] record_id = args["record"] data = general_query.query_record(table_name, record_id) return success_response(data)
def func(self, args, request): if 'table' not in args: raise MudderyError(ERR.missing_args, 'Missing the argument: "table".') table_name = args["table"] record = args.get('record', None) data = data_edit.query_form(table_name, id=record) return success_response(data)
def func(self, args, request): if ('table' not in args) or ('record' not in args): raise MudderyError(ERR.missing_args, 'Missing arguments.') table_name = args["table"] record_id = args["record"] data_edit.delete_record(table_name, record_id) data = {"record": record_id} return success_response(data)
def func(self, args, request): if not args: raise MudderyError(ERR.missing_args, 'Missing arguments.') if 'area' not in args: raise MudderyError(ERR.missing_args, 'Missing the argument: "area".') area_key = args["area"] data = data_query.query_map(area_key) return success_response(data)
def func(self, args, request): if not args: raise MudderyError(ERR.missing_args, 'Missing arguments.') if 'base_typeclass' not in args: raise MudderyError(ERR.missing_args, 'Missing the argument: "base_typeclass".') base_typeclass = args["base_typeclass"] obj_typeclass = args.get('obj_typeclass', None) obj_key = args.get('obj_key', None) data = data_edit.query_object_form(base_typeclass, obj_typeclass, obj_key) return success_response(data)
def func(self, args, request): if 'obj_key' not in args: raise MudderyError(ERR.missing_args, 'Missing the argument: "obj_key".') if 'base_typeclass' not in args: raise MudderyError(ERR.missing_args, 'Missing the argument: "base_typeclass".') obj_key = args["obj_key"] base_typeclass = args.get("base_typeclass", None) data_edit.delete_object(obj_key, base_typeclass) data = {"obj_key": obj_key} return success_response(data)
def func(self, args, request): if 'table' not in args: raise MudderyError(ERR.missing_args, 'Missing the argument: "table".') if 'record' not in args: raise MudderyError(ERR.missing_args, 'Missing the argument: "record".') table_name = args["table"] record_id = args["record"] data_edit.delete_record(table_name, record_id) data = {"record": record_id} return success_response(data)
def func(self, args, request): if not args: raise MudderyError(ERR.missing_args, 'Missing arguments.') if "objects" not in args: raise MudderyError(ERR.missing_args, 'Missing the argument: "objects".') objects = args["objects"] for object_key in objects: data_edit.delete_object(object_key) return success_response("success")
def func(self, args, request): if 'typeclass' not in args: raise MudderyError(ERR.missing_args, 'Missing the argument: "typeclass".') if 'obj_key' not in args: raise MudderyError(ERR.missing_args, 'Missing the argument: "obj_key".') typeclass_key = args["typeclass"] obj_key = args["obj_key"] data = data_query.query_object_properties(typeclass_key, obj_key) return success_response(data)
def func(self, args, request): if 'obj_key' not in args: raise MudderyError(ERR.missing_args, 'Missing the argument: "obj_key".') if 'level' not in args: raise MudderyError(ERR.missing_args, 'Missing the argument: "level".') obj_key = args["obj_key"] level = args["level"] data = data_query.query_object_level_properties(obj_key, level) return success_response(data)
def func(self, args, request): if not args: raise MudderyError(ERR.missing_args, 'Missing arguments.') if 'area' not in args: raise MudderyError(ERR.missing_args, 'Missing the argument: "area".') if 'rooms' not in args: raise MudderyError(ERR.missing_args, 'Missing the argument: "rooms".') area = args["area"] rooms = args["rooms"] data = data_edit.save_map_positions(area, rooms) return success_response(data)
def func(self, args, request): if not args or ('username' not in args) or ('password' not in args): raise MudderyError(ERR.missing_args, 'Missing arguments.') username = args['username'] password = args['password'] user = auth.authenticate(username=username, password=password) if not user: raise MudderyError(ERR.no_authentication, "Authentication fialed.") if not user.is_staff: raise MudderyError(ERR.no_permission, "No permission.") auth.login(request, user) return success_response("success")
def func(self, args, request): file_obj = request.FILES.get("file", None) if not file_obj: raise MudderyError(ERR.missing_args, 'Missing zip files.') with tempfile.TemporaryFile() as fp: try: for chunk in file_obj.chunks(): fp.write(chunk) importer.unzip_resources_all(fp) except Exception as e: logger.log_tracemsg("Upload error: %s" % e) raise MudderyError(ERR.upload_error, str(e)) return success_response("success")
def func(self, args, request): if not args: raise MudderyError(ERR.missing_args, 'Missing arguments.') if 'values' not in args: raise MudderyError(ERR.missing_args, 'Missing argument: "values".') if 'table' not in args: raise MudderyError(ERR.missing_args, 'Missing argument: "table".') values = args["values"] table_name = args["table"] record_id = args.get('record', None) record_id = data_edit.save_form(values, table_name, record_id) data = general_query.query_record(table_name, record_id) return success_response(data)
def func(self, args, request): if not args: raise MudderyError(ERR.missing_args, 'Missing arguments.') if 'values' not in args: raise MudderyError(ERR.missing_args, 'Missing the argument: "values".') if 'table' not in args: raise MudderyError(ERR.missing_args, 'Missing the argument: "table".') values = args["values"] table_name = args["table"] record_id = args.get('record', None) record_id = data_edit.save_form(values, table_name, record_id) data = data_edit.query_form(table_name, id=record_id) return success_response(data)
def func(self, args, request): if 'obj_key' not in args: raise MudderyError(ERR.missing_args, 'Missing the argument: "obj_key".') if 'level' not in args: raise MudderyError(ERR.missing_args, 'Missing the argument: "level".') if 'values' not in args: raise MudderyError(ERR.missing_args, 'Missing the argument: "values".') obj_key = args["obj_key"] level = args["level"] values = args["values"] data_edit.save_object_level_properties(obj_key, level, values) return success_response("success")
def func(self, args, request): if 'table' not in args: raise MudderyError(ERR.missing_args, 'Missing the argument: "table".') table_name = args["table"] try: record = general_query_mapper.get_the_first_record(table_name) if record: record_id = record.id else: record_id = None except Exception as e: raise MudderyError(ERR.invalid_form, "Wrong table: %s." % table_name) data = data_edit.query_form(table_name, id=record_id) return success_response(data)
def func(self, args, request): writer_list = writers.get_writers() data = [{"type": item.type, "name": item.name} for item in writer_list] return success_response(data)
try: fp = open(filepath, "rb") for chunk in file_obj.chunks(): data = fp.read(len(chunk)) compare = [0 for item in zip(chunk, data) if item[0] != item[1]] same = (len(compare) == 0) if not same: break except Exception, e: same = False if not same: raise MudderyError(ERR.upload_image_exist, 'File %s already exists.' % filename) exist = True icon_location = settings.IMAGE_PATH + "/" + file_type + "/" + filename if not exist: try: image = Image.open(filepath) size = image.size IMAGE_RESOURCES.add(icon_location, file_type, size[0], size[1]) except Exception, e: if fp: fp.close() logger.log_tracemsg("Upload error: %s" % e.message) raise MudderyError(ERR.upload_error, e.message) return success_response({"resource": icon_location})
def func(self, args, request): data = general_query.query_tables() return success_response(data)
def func(self, args, request): return success_response("success")
def func(self, args, request): data = data_query.query_areas() return success_response(data)