Skip to content

Commit

Permalink
use six which handles the invalid unicode characters from excel the r…
Browse files Browse the repository at this point in the history
…ight way
  • Loading branch information
norkans7 committed Feb 20, 2017
1 parent a5508a1 commit a11c0ff
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
Binary file modified media/test_imports/sample_contacts_bad_unicode.xls
Binary file not shown.
6 changes: 1 addition & 5 deletions temba/contacts/models.py
Expand Up @@ -1003,11 +1003,7 @@ def create_instance(cls, field_dict):
if not value:
continue

try:
value = str(value)
except UnicodeEncodeError:
error_msg = "Invalid text in column '%s'" % urn_header
raise SmartImportRowError(error_msg)
value = six.text_type(value)

urn_scheme = ContactURN.IMPORT_HEADER_TO_SCHEME[urn_header]

Expand Down
12 changes: 10 additions & 2 deletions temba/contacts/tests.py
Expand Up @@ -2522,8 +2522,16 @@ def test_contact_import(self):
ContactGroup.user_groups.all().delete()

self.assertContactImport('%s/test_imports/sample_contacts_bad_unicode.xls' % settings.MEDIA_ROOT,
dict(records=1, errors=1, creates=1, updates=0,
error_messages=[dict(line=3, error="Invalid text in column 'phone'")]))
dict(records=2, errors=0, creates=2, updates=0, error_messages=[]))

self.assertEquals(1, Contact.objects.filter(name='John Doe').count())
self.assertEquals(1, Contact.objects.filter(name='Mary Smith').count())

contact = Contact.objects.filter(name='John Doe').first()
contact2 = Contact.objects.filter(name='Mary Smith').first()

self.assertEqual(list(contact.get_urns().values_list('path', flat=True)), ['+250788123123'])
self.assertEqual(list(contact2.get_urns().values_list('path', flat=True)), ['+250788345345'])

Contact.objects.all().delete()
ContactGroup.user_groups.all().delete()
Expand Down
13 changes: 5 additions & 8 deletions templates/contacts/contact_import.haml
Expand Up @@ -76,10 +76,8 @@
Some rows were not imported
%br
%strong
-blocktrans count results.error_messages as error_count
Error description
-plural
Errors description
-blocktrans
Errors description
%br
- for error_message in results.error_messages
Row {{ error_message.line }}: {{ error_message.error }}
Expand All @@ -96,10 +94,9 @@
.import-result
.well.well-small
%strong
-blocktrans count results.error_messages as error_count
Error description
-plural
Errors description
-blocktrans
Errors description

%br
- for error_message in results.error_messages
Row {{ error_message.line }}: {{ error_message.error }}
Expand Down

0 comments on commit a11c0ff

Please sign in to comment.