def saveTable(request, table): """ Serialize the table into its file :param request: HTTP request :param Table table: """ have_table_file = False table_filepath = None if TABLE_FILE_KEY in request.session: if request.session[TABLE_FILE_KEY] is not None: have_table_file = True table_filepath = request.session[TABLE_FILE_KEY] if not have_table_file: if USE_DEFAULT_FILE: table_filepath = settings.SCISHEETS_DEFAULT_TABLEFILE else: handle = tempfile.NamedTemporaryFile() table_filepath = handle.name handle.close() full_filepath = _setTableFilepath(request, table, table_filepath, verify=False) versioned_file = table.getVersionedFile() if versioned_file is None: is_changed_filepath = True elif full_filepath != versioned_file.getFilepath(): is_changed_filepath = True else: is_changed_filepath = False if is_changed_filepath: table.setFilepath(full_filepath) writeObjectToFile(table)
def createTable(name, column_name=None, is_subtable=False): """ :param str name: str table name :param str or list column_name: column(s) to create :param bool is_subtable: true if table is a subtable :return: Table object """ if column_name is None: colnms = [] elif isinstance(column_name, list): colnms = column_name else: colnms = [column_name] table = DTTable(name) factor = 1 for colnm in colnms: column = cl.Column(colnm) values = [factor*n for n in range(5)] factor += 1 column.addCells(values, replace=True) table.addColumn(column) if not is_subtable: versioned_file = VersionedFile(TABLE_FILEPATH, TEST_DIR, MAX_VERSIONS) table.setVersionedFile(versioned_file) api_util.writeObjectToFile(table, TABLE_FILEPATH) return table
def createTable(name, column_name=None, is_subtable=False): """ :param str name: str table name :param str or list column_name: column(s) to create :param bool is_subtable: true if table is a subtable :return: Table object """ if column_name is None: colnms = [] elif isinstance(column_name, list): colnms = column_name else: colnms = [column_name] table = DTTable(name) factor = 1 for colnm in colnms: column = cl.Column(colnm) values = [factor * n for n in range(5)] factor += 1 column.addCells(values, replace=True) table.addColumn(column) if not is_subtable: versioned_file = VersionedFile(TABLE_FILEPATH, TEST_DIR, MAX_VERSIONS) table.setVersionedFile(versioned_file) api_util.writeObjectToFile(table, TABLE_FILEPATH) return table
def create(self): """ Creates Table file and the table """ if os.path.exists(self._full_path): self.table = api_util.readObjectFromFile(self._full_path) self.table.setFilepath(self._full_path) # Set before write else: self.table = DTTable(self._table_name) self.table.setFilepath(self._full_path) # Set before write api_util.writeObjectToFile(self.table)
def testCommandCellUpdateWithColumnListData(self): if IGNORE_TEST: return ROW_INDEX = NROW - 1 response = self._createBaseTable() table = self._getTableFromResponse(response) column_index = 1 table.updateCell([1,2,3], ROW_INDEX, column_index) writeObjectToFile(table) self._testCommandCellUpdate(ROW_INDEX, 2, valid=False, table=table, column_index=column_index)
def testCommandCellUpdateWithColumnListData(self): if IGNORE_TEST: return row_index = NROW - 1 response = self._createBaseTable() table = self._getTableFromResponse(response) column = table.columnFromIndex(1) column_name = column.getName() table.updateCell([1, 2, 3], row_index, column_name) writeObjectToFile(table) self._testCommandCellUpdate(row_index, 2, valid=False, table=table, column_name=column_name)