Fixed #18700 -- Added URL reversal for i18n set_language view.

This commit is contained in:
Simon Meers 2012-08-03 10:03:52 +10:00
parent b496be331c
commit 10f979fd92
3 changed files with 7 additions and 3 deletions

View File

@ -1,5 +1,5 @@
from django.conf import settings
from django.conf.urls import patterns
from django.conf.urls import patterns, url
from django.core.urlresolvers import LocaleRegexURLResolver
def i18n_patterns(prefix, *args):
@ -16,5 +16,5 @@ def i18n_patterns(prefix, *args):
urlpatterns = patterns('',
(r'^setlang/$', 'django.views.i18n.set_language'),
url(r'^setlang/$', 'django.views.i18n.set_language', name='set_language'),
)

View File

@ -1272,7 +1272,7 @@ Here's example HTML template code:
.. code-block:: html+django
<form action="/i18n/setlang/" method="post">
<form action="{% url 'set_language' %}" method="post">
{% csrf_token %}
<input name="next" type="hidden" value="{{ redirect_to }}" />
<select name="language">

View File

@ -5,6 +5,7 @@ import gettext
from os import path
from django.conf import settings
from django.core.urlresolvers import reverse
from django.test import TestCase
from django.utils.translation import override, activate, get_language
from django.utils.text import javascript_quote
@ -23,6 +24,9 @@ class I18NTests(TestCase):
self.assertRedirects(response, 'http://testserver/views/')
self.assertEqual(self.client.session['django_language'], lang_code)
def test_setlang_reversal(self):
self.assertEqual(reverse('set_language'), '/views/i18n/setlang/')
def test_jsi18n(self):
"""The javascript_catalog can be deployed with language settings"""
saved_lang = get_language()