Skip to content

Commit

Permalink
Fix Django 1.9 warnings that will break in Django 1.10
Browse files Browse the repository at this point in the history
  • Loading branch information
vdboor committed Feb 26, 2016
1 parent e454a8e commit 828b341
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 18 deletions.
2 changes: 1 addition & 1 deletion example/article/admin.py
Expand Up @@ -31,7 +31,7 @@ class ArticleAdmin(TranslatableAdmin):
form = ArticleAdminForm

# NOTE: when using Django 1.4, use declared_fieldsets= instead of fieldsets=
declared_fieldsets = (
fieldsets = (
(None, {
'fields': ('title', 'slug', 'published', 'category'),
}),
Expand Down
6 changes: 3 additions & 3 deletions example/article/urls.py
@@ -1,7 +1,7 @@
from django.conf.urls import *
from django.conf.urls import url
from .views import ArticleListView, ArticleDetailView

urlpatterns = patterns('',
urlpatterns = [
url(r'^$', ArticleListView.as_view(), name='article-list'),
url(r'^(?P<slug>[^/]+)/$', ArticleDetailView.as_view(), name='article-details'),
)
]
9 changes: 8 additions & 1 deletion parler/fields.py
Expand Up @@ -10,6 +10,8 @@
indicate that the derived model is expected to provide that translatable field.
"""
from __future__ import unicode_literals

import django
from django.forms.forms import pretty_name


Expand Down Expand Up @@ -136,7 +138,12 @@ def short_description(self):
# Fallback to what the admin label_for_field() would have done otherwise.
return pretty_name(self.field.name)

return translations_model._meta.get_field_by_name(self.field.name)[0].verbose_name
if django.VERSION >= (1, 8):
field = translations_model._meta.get_field(self.field.name)
else:
field = translations_model._meta.get_field_by_name(self.field.name)[0]

return field.verbose_name


class LanguageCodeDescriptor(object):
Expand Down
6 changes: 0 additions & 6 deletions parler/tests/test_admin.py
Expand Up @@ -13,17 +13,11 @@ class AdminTests(AppTestCase):
"""

def test_list_label(self):
# Ensure model data is correct
self.assertEqual(SimpleModel._parler_meta.root_model._meta.get_field_by_name('tr_title')[0].verbose_name, "Translated Title")

# See that adding a field to the admin list_display also receives the translated title
# This happens by TranslatedFieldDescriptor.short_description
self.assertEqual(label_for_field('tr_title', SimpleModel), "Translated Title")

def test_list_label_abc(self):
# Ensure model data is correct
self.assertEqual(ConcreteModel._parler_meta.root_model._meta.get_field_by_name('tr_title')[0].verbose_name, "Translated Title")

# See that the TranslatedFieldDescriptor of the concrete model properly routes to the proper model
self.assertEqual(label_for_field('tr_title', ConcreteModel), "Translated Title")

Expand Down
42 changes: 35 additions & 7 deletions runtests.py
Expand Up @@ -10,6 +10,40 @@

sys.path.insert(0, path.join(module_root, 'example'))

if django.VERSION >= (1, 8):
template_settings = dict(
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': (),
'OPTIONS': {
'loaders': (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
),
'context_processors': (
'django.template.context_processors.debug',
'django.template.context_processors.i18n',
'django.template.context_processors.media',
'django.template.context_processors.request',
'django.template.context_processors.static',
'django.contrib.auth.context_processors.auth',
),
},
},
]
)
else:
template_settings = dict(
TEMPLATE_LOADERS = (
'django.template.loaders.app_directories.Loader',
'django.template.loaders.filesystem.Loader',
),
TEMPLATE_CONTEXT_PROCESSORS = list(default_settings.TEMPLATE_CONTEXT_PROCESSORS) + [
'django.core.context_processors.request',
],
)

settings.configure(
DEBUG = False, # will be False anyway by DjangoTestRunner.
TEMPLATE_DEBUG = True,
Expand All @@ -26,13 +60,6 @@
'LOCATION': 'unique-snowflake',
}
},
TEMPLATE_LOADERS = (
'django.template.loaders.app_directories.Loader',
'django.template.loaders.filesystem.Loader',
),
TEMPLATE_CONTEXT_PROCESSORS = list(default_settings.TEMPLATE_CONTEXT_PROCESSORS) + [
'django.core.context_processors.request',
],
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
Expand Down Expand Up @@ -66,6 +93,7 @@
'fallbacks': ['en'],
},
},
**template_settings
)


Expand Down

0 comments on commit 828b341

Please sign in to comment.