Skip to content
Snippets Groups Projects
Verified Commit b7138cf0 authored by Timm Fitschen's avatar Timm Fitschen
Browse files

ENH: More versatile find_func for TableExporter

parent 4f79e91a
No related branches found
No related tags found
2 merge requests!89ENH: JsonSchemaExporter accepts do_not_create parameter.,!78ENH: more useful table export find func
Pipeline #40615 failed
......@@ -133,6 +133,7 @@ class BaseTableExporter(object):
self._check_sanity_of_export_dict()
self.raise_error_if_missing = raise_error_if_missing
self.info = {}
self.all_keys = [key for key in self.export_dict]
def collect_information(self):
"""Use the items of `export_dict` to collect the information for the
......@@ -140,7 +141,8 @@ class BaseTableExporter(object):
"""
for e, d in self.export_dict.items():
for e in self.all_keys:
d = self.export_dict[e]
if QUERY in d:
# TODO: How do we make this more general? There might
# be queries that don't need the record or work with
......@@ -164,11 +166,11 @@ class BaseTableExporter(object):
else:
self._append_missing(e, d)
elif FIND_FUNCTION in d:
try:
self.info[e] = self._call_find_function(d[FIND_FUNCTION], e);
except Exception as exc:
val = self._call_find_function(d[FIND_FUNCTION], e);
if val is not None:
self.info[e] = val
else:
self._append_missing(e, d)
logger.debug(exc)
# last resort: check if record has e as property:
else:
try:
......@@ -202,10 +204,10 @@ class BaseTableExporter(object):
def _call_find_function(self, find_function, e):
account_for_self = 0
if callable(d[FIND_FUNCTION]):
find_fun = d[FIND_FUNCTION]
if callable(find_function):
find_fun = find_function
else:
find_fun = getattr(self, d[FIND_FUNCTION])
find_fun = getattr(self, find_function)
account_for_self = 1
sig = signature(find_fun)
......@@ -254,7 +256,8 @@ class BaseTableExporter(object):
if print_header:
header = ""
for e, d in self.export_dict.items():
for e in self.all_keys:
d = self.export_dict[e]
if e in self.info:
body += str(self.info[e]) + delimiter
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment