예제 #1
0
    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")
예제 #2
0
    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)
예제 #3
0
    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)
예제 #4
0
    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)
예제 #5
0
    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)
예제 #6
0
    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)
예제 #7
0
    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_object_event_triggers(typeclass)
        return success_response(data)
예제 #8
0
    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)
예제 #9
0
    def func(self, args, request):
        """
        Get the server's status.

        Args:
            args: None
        """
        return success_response("running")
예제 #10
0
    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)
예제 #11
0
    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)
예제 #12
0
    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)
예제 #13
0
    def func(self, args, request):
        """
        Logout the editor.

        Args:
            args: None
        """
        auth.logout(request)
        return success_response("success")
예제 #14
0
    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)
예제 #15
0
    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)
예제 #16
0
    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)
예제 #17
0
    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)
예제 #18
0
    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)
예제 #19
0
    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)
예제 #20
0
    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")
예제 #21
0
    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)
예제 #22
0
    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)
예제 #23
0
파일: files.py 프로젝트: xujiameng/muddery
    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")
예제 #24
0
    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")
예제 #25
0
    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")
예제 #26
0
    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)
예제 #27
0
    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)
예제 #28
0
파일: files.py 프로젝트: xujiameng/muddery
    def func(self, args, request):
        file_obj = request.FILES.get("file", None)

        if not file_obj:
            raise MudderyError(ERR.missing_args, 'Missing data files.')

        fullname = file_obj.name
        filename, ext_name = os.path.splitext(fullname)
        table_name = args.get("table", None)

        if not table_name:
            table_name = filename

        file_type = ""
        if ext_name:
            file_type = ext_name[1:].lower()

        temp_filename = tempfile.mktemp()
        try:
            # Write data to a template file.
            with open(temp_filename, 'wb') as fp:
                for chunk in file_obj.chunks():
                    fp.write(chunk)

            # Import the template file.
            importer.import_file(temp_filename,
                                 table_name=table_name,
                                 file_type=file_type,
                                 clear=True)
        except Exception as e:
            logger.log_tracemsg("Upload error: %s" % e)
            raise MudderyError(ERR.upload_error, str(e))
        finally:
            try:
                os.remove(temp_filename)
            except IOError:
                pass

        return success_response("success")
예제 #29
0
    def func(self, args, request):
        try:
            # reload system data
            # import_syetem_data()

            # reload localized strings
            # LOCALIZED_STRINGS_HANDLER.reload()

            # reload data
            WorldData.reload()

            # rebuild the world
            build_all()

            # restart the server
            SESSIONS.announce_all("Server restarting ...")
            SESSIONS.portal_restart_server()
        except Exception as e:
            message = "Can not build the world: %s" % e
            logger.log_tracemsg(message)
            raise MudderyError(ERR.build_world_error, message)

        return success_response("success")
예제 #30
0
 def func(self, args, request):
     data = data_query.query_dialogues_table()
     return success_response(data)