Skip to content

Commit

Permalink
got basic mapping to work
Browse files Browse the repository at this point in the history
  • Loading branch information
dangunter committed Mar 6, 2015
1 parent b5f66a6 commit 008aeec
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
13 changes: 8 additions & 5 deletions seed/common/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,22 @@ def get_pm_mapping(version, columns, include_none=False):
Args:
version (str): Version in format 'x.y[.z]'
columns (list): A list of [column_name, field, {metadata}]
include_none (bool): If True, add [column_name, None, None] for
columns that had no match.
include_none (bool): If True, add {column:None} for unmatched columns.
Return:
map of {column:MapItem}
"""
conf = MappingConfiguration()
version_parts = version.split('.')
mp = conf.pm(version_parts)
result = []
result = {}
for col in columns:
mapped = mp.get(col, None)
if mapped:
result.append([col] + mp[col].as_json())
result[col] = mapped
elif include_none:
result.append([col, None, None])
result[col] = None
else:
pass # nothing added to result
_log.debug("get_pm_mapping: result={}".format(result))
return result

Expand Down
14 changes: 7 additions & 7 deletions seed/views/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,11 @@ def create_pm_mapping(request):
return vutil.api_error(invalid)

try:
result = simple_mapper.get_pm_mapping((1, 0), body['columns'])
result = simple_mapper.get_pm_mapping('1.0', body['columns'])
except ValueError as err:
return vutil.api_error(str(err))
return vutil.api_success(mapping=result)
json_result = [[c] + v.as_json() for c, v in result.items()]
return vutil.api_success(mapping=json_result)

@api_endpoint
@ajax_request
Expand Down Expand Up @@ -1185,14 +1186,13 @@ def get_column_mapping_suggestions(request):
_log.info("map Portfolio Manager input file")
suggested_mappings = {}
ver = import_file.source_program_version
for item in simple_mapper.get_pm_mapping(
for col, item in simple_mapper.get_pm_mapping(
ver, import_file.first_row_columns,
include_none=True):
col, fld, meta = item
if fld is None:
include_none=True).items():
if item is None:
suggested_mappings[col] = (col, 0)
else:
suggested_mappings[col] = (fld, 1)
suggested_mappings[col] = (item.field, 100)
else:
# All other input types
suggested_mappings = mapper.build_column_mapping(
Expand Down

0 comments on commit 008aeec

Please sign in to comment.