def _autorized_order(order, catalog_name, collection_name): """ Filter the order (list of columns) on columns that are not suppressed given the current request """ authority = Authority(catalog_name, collection_name) suppress_columns = authority.get_suppressed_columns() return [o for o in order if o not in suppress_columns]
def _dump_entities_to_table(self, entities, model): authority = Authority(self.catalog_name, self.collection_name) suppress_columns = authority.get_suppressed_columns() connection = self.datastore.connection stream = CSVStream(csv_entities(entities, model, suppress_columns), STREAM_PER) with connection.cursor() as cursor: yield "Export data" commit = COMMIT_PER while stream.has_items(): stream.reset_count() cursor.copy_expert( sql=f"COPY {self.schema}.{self.tmp_collection_name} FROM STDIN DELIMITER ';' CSV HEADER;", file=stream, size=BUFFER_PER ) if stream.total_count >= commit: connection.commit() commit += COMMIT_PER yield f"\n{self.collection_name}: {stream.total_count:,}" else: # Let client know we're still working. yield "." yield f"\nExported {stream.total_count} rows\n" connection.commit()
def test_filter_row(self): authority = Authority('cat', 'col') authority.get_suppressed_columns = lambda: ['b', 'd'] row = {'a': 1, 'b': 2, 'c': 3} authority.filter_row(row) self.assertEqual(row, {'a': 1, 'b': None, 'c': 3}) authority.allows_access = lambda: False row = {'a': 1, 'b': 2, 'c': 3} authority.filter_row(row) self.assertEqual(row, {'a': None, 'b': None, 'c': None})