Skip to content

Commit

Permalink
add handling for specific char like '%s'
Browse files Browse the repository at this point in the history
  • Loading branch information
Wei committed Mar 19, 2019
1 parent 1d1ecce commit fdaef60
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion django_excel_to_model/field_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@

from django_excel_to_model.file_readers.file_reader_exceptions import NonUnicodeFieldNameNotSupported

SPECIFIC_CHAR_MAPPING = {
"%" : 'percentage'
}

def get_target_field_name(col):
for ch in [" ", ",", "_", ")", "(", ":", "/", "\\", '"', "'", "-", ",", ".", "<", ">", "%", "&", "\r", "\n"]:
col = col.replace(ch, "_").replace("__", "_")
if ch in SPECIFIC_CHAR_MAPPING:
col = col.replace(ch, SPECIFIC_CHAR_MAPPING[ch])
else:
col = col.replace(ch, "_").replace("__", "_")
# col = filter(lambda x: x in string.printable, col)
col = get_string_with_only_char_in_list(col)
col = col.replace("__", "_")
Expand Down

0 comments on commit fdaef60

Please sign in to comment.