Skip to content

Commit

Permalink
added Python 3.2 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
vdboor committed Feb 13, 2014
1 parent 5cd8274 commit 1a65a9e
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ language: python
python:
- "2.6"
- "2.7"
- "3.2"
- "3.3"
env:
- DJANGO=1.4.2
- DJANGO=1.5.1
- DJANGO=1.6.0
matrix:
exclude:
- python: "3.2"
env: DJANGO=1.4.2
- python: "3.3"
env: DJANGO=1.4.2

Expand Down
7 changes: 4 additions & 3 deletions parler/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
It's possible to create the translations model manually,
or let it be created dynamically when using the :class:`TranslatedFields` field.
"""
from __future__ import unicode_literals
import django
from django.core.exceptions import ImproperlyConfigured
from django.db import models, router
Expand Down Expand Up @@ -294,12 +295,12 @@ def _get_translated_model(self, language_code=None, use_fallback=False, auto_cre
try:
return self._get_translated_model(lang_dict['fallback'], use_fallback=False, auto_create=auto_create)
except self._translations_model.DoesNotExist:
fallback_msg = u" (tried fallback {0})".format(lang_dict['fallback'])
fallback_msg = " (tried fallback {0})".format(lang_dict['fallback'])

# None of the above, bail out!
raise self._translations_model.DoesNotExist(
u"{0} does not have a translation for the current language!\n"
u"{0} ID #{1}, language={2}{3}".format(self._meta.verbose_name, self.pk, language_code, fallback_msg or ''
"{0} does not have a translation for the current language!\n"
"{0} ID #{1}, language={2}{3}".format(self._meta.verbose_name, self.pk, language_code, fallback_msg or ''
))


Expand Down
9 changes: 5 additions & 4 deletions parler/tests/model_attributes.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import unicode_literals
from django.conf import settings
from django.utils import translation
from parler.models import TranslationDoesNotExist
Expand Down Expand Up @@ -87,8 +88,8 @@ def test_save_multiple(self):
x.save()

# Check if all translations are saved.
self.assertEqual(sorted(x.translations.values_list('tr_title', flat=True)), [u'TITLE_EN', u'TITLE_ES', u'TITLE_FR', u'TITLE_NL'])
self.assertEqual(sorted(x.get_available_languages()), [u'en', u'es', u'fr', u'nl'])
self.assertEqual(sorted(x.translations.values_list('tr_title', flat=True)), ['TITLE_EN', 'TITLE_ES', 'TITLE_FR', 'TITLE_NL'])
self.assertEqual(sorted(x.get_available_languages()), ['en', 'es', 'fr', 'nl'])
self.assertTrue(x.has_translation('en'))
self.assertTrue(x.has_translation('es'))
self.assertFalse(x.has_translation('fi'))
Expand All @@ -106,7 +107,7 @@ def test_save_multiple(self):
x.set_current_language('it', initialize=True)
self.assertTrue(x.has_translation('it')) # does return true for this object.
self.assertNumQueries(0, x.save_translations())
self.assertEqual(sorted(x.get_available_languages()), [u'en', u'es', u'fr', u'nl'])
self.assertEqual(sorted(x.get_available_languages()), ['en', 'es', 'fr', 'nl'])


def test_empty_model(self):
Expand All @@ -120,7 +121,7 @@ def test_empty_model(self):
x.set_current_language('nl', initialize=True)
x.save()

self.assertEqual(sorted(x.get_available_languages()), [u'en', u'fr', u'nl'])
self.assertEqual(sorted(x.get_available_languages()), ['en', 'fr', 'nl'])


def test_fallback_language(self):
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def find_version(*parts):
'Programming Language :: Python',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.2',
'Programming Language :: Python :: 3.3',
'Topic :: Internet :: WWW/HTTP',
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
Expand Down
15 changes: 15 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@
envlist=
py26-django14,
py26-django15,

py27-django14,
py27-django15,
py27-django16,

py32-django15,
py32-django16,

py33-django15,
py33-django16,

Expand Down Expand Up @@ -42,6 +47,16 @@ basepython=python2.7
deps=
django==1.6.0

[testenv:py32-django15]
basepython=python3.2
deps=
django==1.5.1

[testenv:py32-django16]
basepython=python3.2
deps=
django==1.6.0

[testenv:py33-django15]
basepython=python3.3
deps=
Expand Down

0 comments on commit 1a65a9e

Please sign in to comment.