def insert_tables_config(name, path=json_path): with open(os.path.join(path, '{}-columns.json'.format(kebab_case(name))), encoding='utf-8') as data_file: data = ujson.load(data_file) table = Table(columns=list(), classes=list()) columns = data.get('columns', []) classes = data.get('classes', []) view = data.get('view', []) for item in columns: config = TableColumns(**item) table.columns.append(config) for item in classes: config = TableClasses(**item) table.classes.append(config) table.filtered_by_owner = data.get('filtered_by_owner', False) table_config = TableConfig.get_by_key("{}{}".format(name, '.default')) if table_config is None: table.view = TableView(**view) table_config = TableConfig(key="{}{}".format(name, '.default'), value=table) else: table.pagination = table_config.value.pagination table_config.value = table table_config.save()
def create(self, request, *args, **kwargs): config_key = request.data.pop('configKey', "") config = request.data.pop('config', "") columns = list() # **{'name': 'default', 'page_size': 5, 'page_options': [5, 10, 20, 30]})) for item in config['columns']: column = TableColumns(**item) columns.append(column) table_config = TableConfig.get_by_key(config_key) table = Table(columns=columns) if table_config is None: # table.pagination.append( # PaginationNamespace(**{'name': 'default', 'page_size': 5, 'page_options': [5, 10, 20, 30]})) table_config = TableConfig(key=config_key, value=table) else: table.pagination = table_config.value.pagination table_config.value = table table_config.save(validate=False) return Response(TableConfigSerializer(table_config).data)
def save_config(self, config_data): config = TableConfig(**config_data) config.save() return TableConfigSerializer(config).data