...
 
Commits (5)
...@@ -6,34 +6,14 @@ before_script: ...@@ -6,34 +6,14 @@ before_script:
- python3.6 -m venv $HOME/tox - python3.6 -m venv $HOME/tox
- $HOME/tox/bin/pip install tox - $HOME/tox/bin/pip install tox
py27-django18:
stage: test
script: $HOME/tox/bin/tox -e 'py27-django18'
py27-django110:
stage: test
script: $HOME/tox/bin/tox -e 'py27-django110'
py27-django111: py27-django111:
stage: test stage: test
script: $HOME/tox/bin/tox -e 'py27-django111' script: $HOME/tox/bin/tox -e 'py27-django111'
py36-django18:
stage: test
script: $HOME/tox/bin/tox -e 'py36-django18'
py36-django110:
stage: test
script: $HOME/tox/bin/tox -e 'py36-django110'
py36-django111: py36-django111:
stage: test stage: test
script: $HOME/tox/bin/tox -e 'py36-django111' script: $HOME/tox/bin/tox -e 'py36-django111'
py36-django20:
stage: test
script: $HOME/tox/bin/tox -e 'py36-django20'
py36-django21: py36-django21:
stage: test stage: test
script: $HOME/tox/bin/tox -e 'py36-django21' script: $HOME/tox/bin/tox -e 'py36-django21'
......
...@@ -78,8 +78,6 @@ In den Projekteinstellungen (`settings.py`) müssen folgende Anpassungen vorgeno ...@@ -78,8 +78,6 @@ In den Projekteinstellungen (`settings.py`) müssen folgende Anpassungen vorgeno
] ]
``` ```
:warning: **Achtung:** Der Sprachumschalter benötigt außerdem `crispy_forms`. Die Installation und Konfiguration ist weiter unten beschrieben.
Nutzung in Templates Nutzung in Templates
-------------------- --------------------
......
...@@ -6,3 +6,7 @@ urlpatterns = [ ...@@ -6,3 +6,7 @@ urlpatterns = [
url(r'^$', index), url(r'^$', index),
url('admin/', admin.site.urls), url('admin/', admin.site.urls),
] ]
handler403 = 'tuc2014.views.handle_403'
handler404 = 'tuc2014.views.handle_404'
...@@ -5,13 +5,12 @@ ...@@ -5,13 +5,12 @@
[tox] [tox]
skipsdist = true skipsdist = true
envlist = py{27,36}-django{18,110,111},py36-django{20,21,22} skip_missing_interpreters = true
envlist = py27-django111,py{36,37}-django{111,21,22}
[testenv] [testenv]
commands = {envpython} runtests.py commands = {envpython} runtests.py
deps = deps =
django18: Django >= 1.8, < 1.9
django110: Django >= 1.10, < 1.11
django111: Django >= 1.11, < 2 django111: Django >= 1.11, < 2
django20: Django >= 2, < 2.1 django20: Django >= 2, < 2.1
django21: Django >= 2.1, <2.2 django21: Django >= 2.1, <2.2
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django import forms
try:
# Available in Django 1.10+
from django.urls import reverse
except ImportError:
from django.core.urlresolvers import reverse
from django.conf import settings
from django.utils.translation import ugettext_lazy
class ChangeLanguageForm(forms.Form):
"""
Form for selecting the main language.
No crispy_forms required.
"""
next = forms.CharField(
required=False,
widget=forms.HiddenInput()
)
language = forms.ChoiceField(
choices=settings.LANGUAGES,
label=ugettext_lazy('Language'),
)
def __init__(self, redirect_to, *args, **kwargs):
super(ChangeLanguageForm, self).__init__(*args, **kwargs)
self.form_action = reverse('tuc2014:djangoi18n:set_language')
self.fields['next'].initial = redirect_to
...@@ -4,17 +4,13 @@ Form base classes which can be used with tuc2014, crispy_forms and bootstrap. ...@@ -4,17 +4,13 @@ Form base classes which can be used with tuc2014, crispy_forms and bootstrap.
@author: klada @author: klada
""" """
from django import forms from django import forms
try:
# Available in Django 1.10+
from django.urls import reverse
except ImportError:
from django.core.urlresolvers import reverse
from django.conf import settings
from django.utils.translation import ugettext as _, ugettext_lazy from django.utils.translation import ugettext as _, ugettext_lazy
from crispy_forms.bootstrap import FormActions, FieldWithButtons from crispy_forms.bootstrap import FormActions, FieldWithButtons
from crispy_forms.helper import FormHelper from crispy_forms.helper import FormHelper
from crispy_forms.layout import Div, Layout, Submit from crispy_forms.layout import Div, Layout, Submit
from tuc2014._forms import ChangeLanguageForm as _BaseChangeLanguageForm
class TucFormMixin(object): class TucFormMixin(object):
""" """
...@@ -82,19 +78,10 @@ class TucModelForm(forms.ModelForm, TucFormMixin): ...@@ -82,19 +78,10 @@ class TucModelForm(forms.ModelForm, TucFormMixin):
self.add_crispy_attributes() self.add_crispy_attributes()
class ChangeLanguageForm(TucForm): class ChangeLanguageForm(_BaseChangeLanguageForm, TucForm):
""" """
Form for selecting the main language. Form for selecting the main language.
""" """
next = forms.CharField(
required=False,
widget=forms.HiddenInput()
)
language = forms.ChoiceField(
choices=settings.LANGUAGES,
label=ugettext_lazy('Language'),
)
layout = Layout( layout = Layout(
'next', 'next',
FieldWithButtons('language', Submit('submit', ugettext_lazy('Submit'))) FieldWithButtons('language', Submit('submit', ugettext_lazy('Submit')))
...@@ -102,5 +89,6 @@ class ChangeLanguageForm(TucForm): ...@@ -102,5 +89,6 @@ class ChangeLanguageForm(TucForm):
def __init__(self, redirect_to, *args, **kwargs): def __init__(self, redirect_to, *args, **kwargs):
super(ChangeLanguageForm, self).__init__(*args, **kwargs) super(ChangeLanguageForm, self).__init__(*args, **kwargs)
self.helper.form_action = reverse('tuc2014:djangoi18n:set_language') self.helper.form_action = self.form_action
self.fields['next'].initial = redirect_to self.add_aria_attributes()
self.add_crispy_attributes()
{% extends "tuc2014/base.html" %}
{% load i18n %}
{% block content %}
<h1>Sprache wählen/Change Language</h1>
<form method="post" action="{{form.form_action}}">
{% csrf_token %}
{{form.as_p}}
<p>
<input type="submit" />
</p>
</form>
{% endblock %}
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals from __future__ import unicode_literals
from django.conf.urls import include, url from django.conf.urls import include, url
from django.core.exceptions import ImproperlyConfigured
try: from .views import change_language
from .views import change_language
except ImportError:
raise ImproperlyConfigured("crispy_forms is required for the tuc2014 language picker.")
urlpatterns = [ urlpatterns = [
url(r'^i18n/', include('django.conf.urls.i18n', namespace='djangoi18n')), url(r'^i18n/', include('django.conf.urls.i18n', namespace='djangoi18n')),
......
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals from __future__ import unicode_literals
from django.conf import settings
from django.shortcuts import render from django.shortcuts import render
from django.utils import translation from django.utils import translation
from .forms import ChangeLanguageForm
# Check if crispy_forms is installed and set up correctly
if 'crispy_forms' in getattr(settings, 'INSTALLED_APPS', []):
from .forms import ChangeLanguageForm
HAVE_CRISPY = True
else:
from ._forms import ChangeLanguageForm
HAVE_CRISPY = False
def change_language(request, **kwargs): def change_language(request, **kwargs):
""" """
...@@ -14,12 +23,16 @@ def change_language(request, **kwargs): ...@@ -14,12 +23,16 @@ def change_language(request, **kwargs):
referer = "" referer = ""
cur_language = translation.get_language() cur_language = translation.get_language()
form = ChangeLanguageForm(referer, initial={'language': cur_language}) form = ChangeLanguageForm(referer, initial={'language': cur_language})
return render(request, 'tuc2014/change_language.html', {'form': form, 'current': cur_language}) if HAVE_CRISPY:
template = 'tuc2014/change_language.html'
else:
template = 'tuc2014/change_language_nocrispy.html'
return render(request, template, {'form': form, 'current': cur_language})
def handle_403(request, **kwargs): def handle_403(request, *args, **kwargs):
return render(request, 'tuc2014/403.html', status=403) return render(request, 'tuc2014/403.html', status=403)
def handle_404(request, **kwargs): def handle_404(request, *args, **kwargs):
return render(request, 'tuc2014/404.html', status=404) return render(request, 'tuc2014/404.html', status=404)