def simple_transformer(sphere, index, row, lst, field, fields): idx = _name_ixd(field["name"], fields) input = strutils.build_input(row[idx]) a = utils.to_action(index, "dict", input, input, row[idx].strip(), {"name": strutils.to_name(row[idx])}) lst[strutils.to_name(row[idx])] = a
def name_transformer(sphere, index, row, lst, field, fields): idx = field["name"] if not row.get(idx): return inval = strutils.build_input(row[idx]) a = utils.to_action(index, "dict", inval, inval, row[idx].strip(), { "id": row["_id"], "name": strutils.to_name(row[idx]) }) lst[strutils.to_name(row[idx])] = a
def location_transformer(sphere, index, row, lst, field, fields): val = by_path(row, "location", field.get("json")) if not val: return input = strutils.build_input(val) a = utils.to_action( index, "dict", input, input, val.strip(), { "name": strutils.to_name(val), "country": by_path(row, "country", ["data", "location_tree"]) }) lst[strutils.to_name(val)] = a
def list_transformer(sphere, index, row, lst, field, fields): fname = field["name"] val = by_path(row, fname, field.get("json")) if not val: return for item in val: a = utils.to_action(index, "dict", strutils.to_name(item), strutils.build_input(item), item, { "label": item, "name": strutils.to_name(item) }) uid = uniq_id([strutils.to_name(item)]) if uid not in lst: lst[uid] = a
def admin1_transformer(sphere, index, row, lst, field, fields): val = by_path(row, "admin1", field.get("json")) if not val: return admin1 = strutils.to_name(val) country = strutils.to_name(by_path(row, "country", field.get("json"))) input = strutils.build_input(val) a = utils.to_action(index, "dict", admin1, input, val.strip(), { "name": admin1, "path": [country, admin1, ""] }) uid = uniq_id([country if country else "", admin1 if admin1 else ""]) if uid not in lst: lst[uid] = a
def country_transformer(sphere, index, row, lst, field, fields): val = by_path(row, "country", field.get("json")) nval = strutils.to_name(val) if not nval: return input = strutils.build_input(val) a = utils.to_action(index, "dict", nval, input, val.strip(), { "name": nval, "path": [nval, "", ""] }) # only unique values must be appended uid = uniq_id([val]) if uid not in lst: lst[uid] = a
def mcountry_transformer(sphere, index, row, acc, field, fields): fname = field["name"] val = by_path(row, fname, field.get("json")) if not val: return for item in val: name = item["country"] uid = uniq_id([strutils.to_name(name)]) if uid not in acc: inval = strutils.to_name(name) a = utils.to_action(index, "dict", strutils.to_name(name), inval, name, { "label": name, "name": strutils.to_name(name) }) acc[uid] = a