diff options
Diffstat (limited to 'src/ee/ds')
-rw-r--r-- | src/ee/ds/__init__.py | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/ee/ds/__init__.py b/src/ee/ds/__init__.py index 030113b..f71a7c6 100644 --- a/src/ee/ds/__init__.py +++ b/src/ee/ds/__init__.py @@ -347,7 +347,8 @@ class DataSetManager(object): # noinspection PyMethodMayBeStatic def store_csv(self, path: Union[str, Path], ds: DataSet, object_type: str, - order_by: Union[str, Iterable[str]] = None): + order_by: Union[str, Iterable[str]] = None, fields: List[str] = None, + include_extra_fields: bool = True): items = [o for o in ds.items() if o.object_type.name == object_type] if order_by: @@ -359,10 +360,17 @@ class DataSetManager(object): raise Exception("Unsupported order_by") with open(path, "w") as f: - w = csv.writer(f) + w = csv.writer(f, lineterminator=os.linesep) if len(items): - header = ds.get_object_type(object_type).fields + + if fields is not None: + header = list(fields) + + if include_extra_fields: + header.append(set(ds.get_object_type(object_type).fields) - set(header)) + else: + header = ds.get_object_type(object_type).fields w.writerow(header) for o in items: |