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_fields(table_name) return success_response(data)
def query_typeclass_table(typeclass_key): """ Query a table of objects of the same typeclass. Args: typeclass_key: (string) typeclass's key. """ typeclass_cls = TYPECLASS(typeclass_key) if not typeclass_cls: raise MudderyError(ERR.no_table, "Can not find typeclass %s" % typeclass_key) # get all tables' name tables = typeclass_cls.get_models() if not tables: raise MudderyError(ERR.no_table, "Can not get tables of %s" % typeclass_key) # get all tables' fields # add the first table table_fields = query_fields(tables[0]) fields = [field for field in table_fields if field["name"] != "id"] # add other tables for table in tables[1:]: table_fields = query_fields(table) fields.extend([ field for field in table_fields if field["name"] != "id" and field["name"] != "key" ]) # get all tables' data records = general_query_mapper.get_all_from_tables(tables) rows = [] for record in records: line = [str(record[field["name"]]) for field in fields] rows.append(line) table = { "fields": fields, "records": rows, } return table
def query_typeclass_properties(typeclass_key): """ Query a typeclass's properties. Args: typeclass_key: (string) typeclass' key. """ fields = query_fields("properties_dict") records = CM.PROPERTIES_DICT.filter(typeclass=typeclass_key) rows = [] for record in records: line = [ str(record.serializable_value(field["name"])) for field in fields ] rows.append(line) table = { "fields": fields, "records": rows, } return table
def query_object_events(object_key): """ Query all events of the given object. Args: object_key: (string) object' key. """ fields = query_fields("event_data") records = get_object_event(object_key) rows = [] for record in records: line = [ str(record.serializable_value(field["name"])) for field in fields ] rows.append(line) table = { "fields": fields, "records": rows, } return table
def get_event_data_table(self, event_key): """ Query all actions of an event. Args: event_key: (string)event's key. """ if not self.model_name: return fields = query_fields(self.model_name) rows = [] record = general_query_mapper.get_record(self.model_name, event_key=event_key) line = [str(record.serializable_value(field["name"])) for field in fields] rows.append(line) table = { "table": self.model_name, "fields": fields, "records": rows, } return table
def query_dialogues_table(): """ Query dialogues. """ cursor = connections[settings.WORLD_DATA_APP].cursor() query = "SELECT T1.*, T2.event event, T5.name npc_name, T5.npc npc_key " \ "FROM (worlddata_dialogues T1 LEFT JOIN " \ "(SELECT MIN(T6.key) event, T6.trigger_obj FROM worlddata_event_data T6 " \ "WHERE T6.trigger_type='EVENT_TRIGGER_DIALOGUE' GROUP BY trigger_obj) T2 " \ "ON T1.key=T2.trigger_obj) " \ "LEFT JOIN (SELECT T3.npc, T3.dialogue, T4.name FROM worlddata_npc_dialogues T3 " \ "JOIN worlddata_objects T4 ON T3.npc=T4.key) T5 " \ "ON T1.key=T5.dialogue" cursor.execute(query) fields = query_fields("dialogues") # add event and npc fields fields.append({ "default": "", "editable": False, "help_text": _("Has event.", "help_text"), "label": _("event", "field"), "name": "event", "type": "BooleanField", }) fields.append({ "default": "", "editable": False, "help_text": _("Dialogue's NPC.", "help_text"), "label": _("NPC", "field"), "name": "npc", "type": "CharField", }) columns = [col[0] for col in cursor.description] key_column = columns.index("key") # get records rows = [] record = cursor.fetchone() while record is not None: if len(rows) > 0 and record[key_column] == rows[-1][key_column]: rows[-1][-2] += "," + record[-2] + "(" + record[-1] + ")" else: row = list(record) if not row[-3]: row[-3] = "" else: row[-3] = True if not row[-2]: row[-2] = "" if row[-1]: row[-2] += "(" + row[-1] + ")" rows.append(row) record = cursor.fetchone() table = { "fields": fields, "records": rows, } return table