Skip to content

Commit 679a5d7

Browse files
committed
1616 - Local patch to resolve CSV export issue
1 parent c727215 commit 679a5d7

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

bcap/search/search_export.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import codecs
22
from io import StringIO
33

4+
from arches.app.models import models as arches_models
45
from arches.app.search.search_export import SearchResultsExporter
56

67

@@ -13,6 +14,24 @@ class BCAPSearchResultsExporter(SearchResultsExporter):
1314
def _prepend_bom(inner):
1415
return StringIO(codecs.BOM_UTF8.decode("utf-8") + inner.getvalue())
1516

17+
def return_ordered_header(self, graphid, export_type):
18+
headers = super().return_ordered_header(graphid, export_type)
19+
# CardXNodeXWidget only covers widget-bearing nodes, so collector nodes
20+
# (e.g. resource-instance collectors like publication_reference) that are
21+
# marked exportable are absent from the parent's result even though
22+
# flatten_tiles() will emit them into every instance dict. Appending
23+
# them here prevents DictWriter from raising ValueError on export.
24+
if export_type == "csv":
25+
in_headers = set(headers)
26+
extras = list(
27+
arches_models.Node.objects.filter(graph_id=graphid, exportable=True)
28+
.exclude(datatype="semantic")
29+
.exclude(name__in=in_headers)
30+
.values_list("name", flat=True)
31+
)
32+
headers.extend(extras)
33+
return headers
34+
1635
def to_csv(self, instances, headers, name):
1736
result = super().to_csv(instances, headers, name)
1837
result["outputfile"] = self._prepend_bom(result["outputfile"])

0 commit comments

Comments
 (0)