Skip to content

Commit

Permalink
adjustment for translation
Browse files Browse the repository at this point in the history
  • Loading branch information
tomlaszczuk committed Feb 8, 2016
1 parent e9894f8 commit 1e098c7
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
-r requirements/requirements-base.txt
-r requirements/requirements-packaging.txt
-r requirements/requirements-testing.txt
-r requirements/requirements-codestyle.txt
7 changes: 6 additions & 1 deletion rest_framework_friendly_errors/mixins.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import unicode_literals

import sys

from django.core.exceptions import ValidationError as DjangoValidationError
from rest_framework.exceptions import ValidationError as RestValidationError
from rest_framework.utils.serializer_helpers import ReturnDict
Expand Down Expand Up @@ -103,7 +105,10 @@ def get_field_kwargs(self, field, field_data):

def find_key(self, field, message):
for key in field.error_messages:
unformatted = str(field.error_messages[key])
if sys.version_info.major == 3:
unformatted = str(field.error_messages[key])
else:
unformatted = unicode(field.error_messages[key])
kwargs = self.get_field_kwargs(
field, self.initial_data.get(field.field_name)
)
Expand Down
6 changes: 5 additions & 1 deletion rest_framework_friendly_errors/settings.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
from __future__ import unicode_literals

from django.conf import settings
from django.utils.translation import ugettext_lazy as _

from rest_framework_friendly_errors.utils import update_field_settings


USER_SETTINGS = getattr(settings, 'FRIENDLY_ERRORS', {})

USER_FRIENDLY_FIELD_ERRORS = USER_SETTINGS.get('FIELD_ERRORS', {})
Expand All @@ -11,7 +15,7 @@

VALIDATION_FAILED_CODE = USER_SETTINGS.get('VALIDATION_FAILED_CODE', 1000)
VALIDATION_FAILED_MESSAGE = USER_SETTINGS.get('VALIDATION_FAILED_MESSAGE',
'Validation Failed')
_('Validation Failed'))

FRIENDLY_FIELD_ERRORS = {
'BooleanField': {'required': 2001, 'invalid': 2011, 'null': 2021},
Expand Down
3 changes: 2 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ def pytest_configure():
REST_FRAMEWORK={
'EXCEPTION_HANDLER':
'rest_framework_friendly_errors.handlers.friendly_exception_handler'
}
},
LANGUAGE_CODE='pl'
)

try:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_exception_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from rest_framework_friendly_errors import settings

from tests import BaseTestCase
from views import SnippetList
from tests.views import SnippetList


class ExceptionHandlerTestCase(BaseTestCase):
Expand Down

0 comments on commit 1e098c7

Please sign in to comment.