Skip to content

Commit

Permalink
Remove sigle quotes in error mesages"
Browse files Browse the repository at this point in the history
  • Loading branch information
valdergallo committed Jan 15, 2015
1 parent 9388894 commit 98296f8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
15 changes: 9 additions & 6 deletions data_importer/importers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-

import os
import re
from django.db import transaction
from django.db.models.fields import FieldDoesNotExist
from django.core.exceptions import ValidationError
Expand Down Expand Up @@ -169,7 +170,7 @@ def clean_field(self, field_name, value):
pass # do nothing if not find this field in model
except ValidationError as msg:
default_msg = msg.messages[0].replace('This field', '')
new_msg = u"Field (%s) %s" % (field.name, default_msg)
new_msg = u'Field (%s) %s' % (field.name, default_msg)
raise ValidationError(new_msg)

clean_function = getattr(self, 'clean_%s' % field_name, False)
Expand All @@ -186,7 +187,7 @@ def process_row(self, row, values):
try:
values = dict(zip(self.fields, values_encoded))
except TypeError:
raise TypeError("Invalid Line: %s" % row)
raise TypeError('Invalid Line: %s' % row)

has_error = False

Expand Down Expand Up @@ -223,15 +224,17 @@ def get_error_message(self, error, row=None, error_type=None):
messages = error

if not error_type:
error_type = type(error).__name__
error_type = u"%s" % type(error).__name__

if hasattr(error, 'message'):
if hasattr(error, 'message'):
if error.message:
messages = u"%s" % error.message
messages = u'%s' % error.message
elif hasattr(error, 'messages'):
if error.messages:
messages = u','.join(error.messages)

messages = re.sub('\'', '', messages)

if row:
return row, error_type, messages
else:
Expand Down Expand Up @@ -330,7 +333,7 @@ def save(self, instance=None):
instance = self.Meta.model

if not instance:
raise AttributeError("Invalid instance model")
raise AttributeError('Invalid instance model')

if self.Meta.transaction:
with transaction.atomic():
Expand Down
3 changes: 2 additions & 1 deletion data_importer/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ def clean_test(self, value):
importer_error = TestMetaClean(source=['test1', ])

self.assertFalse(importer_error.is_valid())
self.assertEqual(importer_error.errors, [(1, 'AttributeError', u"'unicode' object has no attribute 'coisa'")])
self.assertEqual(importer_error.errors, [(1, 'AttributeError',
u"unicode object has no attribute coisa")])

def test_read_content_skip_first_line(self):
class TestMeta(CSVImporter):
Expand Down
4 changes: 2 additions & 2 deletions data_importer/tests/test_base_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def test_values_is_valid(self):
def test_errors_values(self):
self.importer.is_valid()
if django.VERSION < (1, 4):
error = [(1, 'ValidationError', u"Field (price) This value must be a float.")]
error = [(1, 'ValidationError', u'Field (price) This value must be a float.')]
else:
error = [(1, 'ValidationError', u'Field (price) \'23,98\' value must be a float.')]
error = [(1, 'ValidationError', u'Field (price) 23,98 value must be a float.')]
self.assertEquals(self.importer.errors, error)
3 changes: 2 additions & 1 deletion data_importer/tests/test_csv_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ def clean_test(self, value):
importer_error = TestMetaClean(source=['test1',])

self.assertFalse(importer_error.is_valid())
self.assertEqual(importer_error.errors, [(1, 'AttributeError', u"'unicode' object has no attribute 'coisa'")])
self.assertEqual(importer_error.errors, [(1, 'AttributeError',
u"unicode object has no attribute coisa")])

def test_read_content_skip_first_line(self):
class TestMeta(CSVImporter):
Expand Down

0 comments on commit 98296f8

Please sign in to comment.