Skip to content

Commit

Permalink
fix issue with WAGTAILTRANS_LANGUAGES_PER_SITE SETTING (#102)
Browse files Browse the repository at this point in the history
* fix issue with WAGTAILTRANS_LANGUAGES_PER_SITE
* add test to test Admin language add/edit panels
* Make testsuite Django 1.8 compatible on a middleware level
  • Loading branch information
OktayAltay authored and jjanssen committed Aug 27, 2017
1 parent 1948421 commit 7655700
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 13 deletions.
5 changes: 1 addition & 4 deletions src/wagtailtrans/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ def __init__(self, *args, **kwargs):
sorted_choices = sorted(self.fields['code'].choices, key=itemgetter(1))
self.fields['code'].choices = sorted_choices

if get_wagtailtrans_setting('LANGUAGES_PER_SITE'):
del self.fields['is_default']

def clean_is_default(self):
is_default = self.cleaned_data['is_default']
default_lang = Language.objects.default()
Expand Down Expand Up @@ -145,7 +142,7 @@ def _language_default():

class TranslatablePage(Page):

#: Defined with a uniqe name, to prevent field clashes..
#: Defined with a unique name, to prevent field clashes..
translatable_page_ptr = models.OneToOneField(
Page, parent_link=True, related_name='+', on_delete=models.CASCADE)
canonical_page = models.ForeignKey(
Expand Down
12 changes: 6 additions & 6 deletions tests/_sandbox/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,8 @@
"""
import os

try:
from wagtail import VERSION as wagtail_version
except ImportError:
#: As of wagtail 1.7 VERSION is located in Wagtail's __init__
wagtail_version = (1, 6)

from django import VERSION as django_version
from wagtail import VERSION as wagtail_version
from wagtailtrans import WAGTAILTRANS_TEMPLATE_DIR

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
Expand Down Expand Up @@ -67,6 +63,7 @@
'tests._sandbox.search',
]


MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
Expand All @@ -82,6 +79,9 @@
'wagtailtrans.middleware.TranslationMiddleware'
]

if django_version < (1, 10):
MIDDLEWARE_CLASSES = MIDDLEWARE

ROOT_URLCONF = 'tests._sandbox.urls'

TEMPLATES = [
Expand Down
3 changes: 0 additions & 3 deletions tests/unit/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ def test_init(self):

assert 'is_default' in self.form_class().fields.keys()

with override_settings(WAGTAILTRANS_LANGUAGES_PER_SITE=True):
assert 'is_default' not in self.form_class().fields.keys()

def test_clean_is_default(self):
language = LanguageFactory(is_default=True)
form = self.form_class(instance=language, data={
Expand Down
16 changes: 16 additions & 0 deletions tests/unit/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,19 @@ def test_post_404(self, rf):
view = TranslationView.as_view()
with pytest.raises(Http404):
view(rf.post('/'), instance_id=0, language_code='en')


@pytest.mark.django_db
class TestLanguageAdminView(object):

def setup(self):
self.language = language.LanguageFactory()

def test_response_language_add_view(self, admin_client):
response = admin_client.get('/admin/wagtailtrans/language/create/')
assert response.status_code == 200

def test_response_language_edit_view(self, admin_client):
response = admin_client.get(
'/admin/wagtailtrans/language/edit/%d/' % self.language.pk)
assert response.status_code == 200

0 comments on commit 7655700

Please sign in to comment.