Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.2.X] Fixed #12650 -- Don't generate invalid XHTML in the admin, da…

…tabrowse apps when

the i18n context processor is active. Thanks to Rob Hudson for the report and
fix suggestion.

Backport of [14104] from trunk

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@14105 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 4d70df8b7830d32dd06728a12a39df14e07e42be 1 parent a92da6e
Ramiro Morales authored October 10, 2010
2  django/contrib/admin/templates/admin/base.html
... ...
@@ -1,5 +1,5 @@
1 1
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2  
-<html xmlns="http://www.w3.org/1999/xhtml" lang="{{ LANGUAGE_CODE }}" xml:lang="{{ LANGUAGE_CODE }}" {% if LANGUAGE_BIDI %}dir="rtl"{% endif %}>
  2
+<html xmlns="http://www.w3.org/1999/xhtml" lang="{{ LANGUAGE_CODE|default:"en-us" }}" xml:lang="{{ LANGUAGE_CODE|default:"en-us" }}" {% if LANGUAGE_BIDI %}dir="rtl"{% endif %}>
3 3
 <head>
4 4
 <title>{% block title %}{% endblock %}</title>
5 5
 <link rel="stylesheet" type="text/css" href="{% block stylesheet %}{% load adminmedia %}{% admin_media_prefix %}css/base.css{% endblock %}" />
2  django/contrib/databrowse/templates/databrowse/base.html
... ...
@@ -1,5 +1,5 @@
1 1
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2  
-<html xmlns="http://www.w3.org/1999/xhtml" lang="{{ LANGUAGE_CODE }}" xml:lang="{{ LANGUAGE_CODE }}" {% if LANGUAGE_BIDI %}dir="rtl"{% endif %}>
  2
+<html xmlns="http://www.w3.org/1999/xhtml" lang="{{ LANGUAGE_CODE|default:"en-us" }}" xml:lang="{{ LANGUAGE_CODE|default:"en-us" }}" {% if LANGUAGE_BIDI %}dir="rtl"{% endif %}>
3 3
 <head>
4 4
 <title>{% block title %}{% endblock %}</title>
5 5
 {% block style %}
30  tests/regressiontests/admin_views/tests.py
@@ -18,6 +18,7 @@
18 18
 from django.utils.encoding import iri_to_uri
19 19
 from django.utils.html import escape
20 20
 from django.utils.translation import get_date_formats, activate, deactivate
  21
+import django.template.context
21 22
 
22 23
 # local test models
23 24
 from models import Article, BarAccount, CustomArticle, EmptyModel, \
@@ -2232,3 +2233,32 @@ def test_filters(self):
2232 2233
 
2233 2234
 except ImportError:
2234 2235
     pass
  2236
+
  2237
+class ValidXHTMLTests(TestCase):
  2238
+    fixtures = ['admin-views-users.xml']
  2239
+    urlbit = 'admin'
  2240
+
  2241
+    def setUp(self):
  2242
+        self._context_processors = None
  2243
+        self._use_i18n, settings.USE_I18N = settings.USE_I18N, False
  2244
+        if 'django.core.context_processors.i18n' in settings.TEMPLATE_CONTEXT_PROCESSORS:
  2245
+            self._context_processors = settings.TEMPLATE_CONTEXT_PROCESSORS
  2246
+            cp = list(settings.TEMPLATE_CONTEXT_PROCESSORS)
  2247
+            cp.remove('django.core.context_processors.i18n')
  2248
+            settings.TEMPLATE_CONTEXT_PROCESSORS = tuple(cp)
  2249
+            # Force re-evaluation of the contex processor list
  2250
+            django.template.context._standard_context_processors = None
  2251
+        self.client.login(username='super', password='secret')
  2252
+
  2253
+    def tearDown(self):
  2254
+        self.client.logout()
  2255
+        if self._context_processors is not None:
  2256
+            settings.TEMPLATE_CONTEXT_PROCESSORS = self._context_processors
  2257
+            # Force re-evaluation of the contex processor list
  2258
+            django.template.context._standard_context_processors = None
  2259
+        settings.USE_I18N = self._use_i18n
  2260
+
  2261
+    def testLangNamePresent(self):
  2262
+        response = self.client.get('/test_admin/%s/admin_views/' % self.urlbit)
  2263
+        self.failIf(' lang=""' in response.content)
  2264
+        self.failIf(' xml:lang=""' in response.content)

0 notes on commit 4d70df8

Please sign in to comment.
Something went wrong with that request. Please try again.