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

ENH: more versatile find_func for table export

parent 58b78e36
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 #40560 failed
......@@ -27,6 +27,7 @@ them for an export as a table, e.g., for the export to metadata
repositories.
"""
from inspect import signature
import json
import logging
......@@ -163,12 +164,8 @@ class BaseTableExporter(object):
else:
self._append_missing(e, d)
elif FIND_FUNCTION in d:
if callable(d[FIND_FUNCTION]):
find_fun = d[FIND_FUNCTION]
else:
find_fun = getattr(self, d[FIND_FUNCTION])
try:
self.info[e] = find_fun()
self.info[e] = self._call_find_function(d[FIND_FUNCTION], e);
except Exception as exc:
self._append_missing(e, d)
logger.debug(exc)
......@@ -203,6 +200,22 @@ class BaseTableExporter(object):
else:
logger.error(errmssg)
def _call_find_function(self, find_function, e):
account_for_self = 0
if callable(d[FIND_FUNCTION]):
find_fun = d[FIND_FUNCTION]
else:
find_fun = getattr(self, d[FIND_FUNCTION])
account_for_self = 1
sig = signature(find_fun)
params = sig.parameters
if len(params) > (account_for_self + 1):
return find_fun(self.record, e)
elif len(params) > account_for_self:
return find_fun(self.record)
return find_fun()
def prepare_csv_export(self, delimiter=',', print_header=False,
skip_empty_optionals=False):
"""Return the values in self.info as a single-line string, separated
......
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