Skip to content

Commit 7700f0e

Browse files
committed
Added DEFAULT_LANGUAGE_CODE setting.
1 parent 52a144e commit 7700f0e

File tree

11 files changed

+62
-28
lines changed

11 files changed

+62
-28
lines changed

aggregator/tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def setUp(self, mocker):
2626
)
2727
DocumentRelease.objects.update_or_create(
2828
release=release,
29-
lang="en",
29+
lang=settings.DEFAULT_LANGUAGE_CODE,
3030
defaults={"is_default": True},
3131
)
3232

blog/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ def invalidate_cached_entry(self):
211211
)
212212
is_secure = url.scheme == "https"
213213
request = rf.get(url.path, secure=is_secure)
214-
request.LANGUAGE_CODE = "en"
214+
request.LANGUAGE_CODE = settings.DEFAULT_LANGUAGE_CODE
215215
cache = caches[settings.CACHE_MIDDLEWARE_ALIAS]
216216
cache_key = _generate_cache_header_key(
217217
settings.CACHE_MIDDLEWARE_KEY_PREFIX, request

djangoproject/tests.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from http import HTTPStatus
22
from io import StringIO
33

4+
from django.conf import settings
45
from django.core.management import call_command
56
from django.test import TestCase
67
from django.urls import NoReverseMatch, get_resolver
@@ -98,7 +99,9 @@ class ExcludeHostsLocaleMiddlewareTests(TestCase):
9899
@classmethod
99100
def setUpTestData(cls):
100101
r2 = Release.objects.create(version="2.0")
101-
DocumentRelease.objects.create(lang="en", release=r2, is_default=True)
102+
DocumentRelease.objects.create(
103+
lang=settings.DEFAULT_LANGUAGE_CODE, release=r2, is_default=True
104+
)
102105

103106
def test_docs_host_excluded(self):
104107
"""We get no Content-Language or Vary headers when docs host is excluded"""

docs/management/commands/update_docs.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ def _get_doc_releases(self, versions, options):
7979

8080
# Skip translated non-stable versions to avoid a crash:
8181
# https://github.com/django/djangoproject.com/issues/627
82-
queryset = queryset.filter(Q(lang="en") | Q(release=default_docs_version))
82+
queryset = queryset.filter(
83+
Q(lang=settings.DEFAULT_LANGUAGE_CODE) | Q(release=default_docs_version)
84+
)
8385

8486
if options["language"]:
8587
queryset = queryset.filter(lang=options["language"])
@@ -161,7 +163,7 @@ def build_doc_release(self, release, force=False, interactive=False):
161163

162164
source_dir = checkout_dir.joinpath("docs")
163165

164-
if release.lang != "en":
166+
if release.lang != settings.DEFAULT_LANGUAGE_CODE:
165167
scm_url = release.scm_url.replace(
166168
"django.git", "django-docs-translations.git"
167169
)

docs/models.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ def get_search_config(lang):
4747

4848

4949
class DocumentReleaseQuerySet(models.QuerySet):
50-
def current(self, lang="en"):
50+
def current(self, lang=settings.DEFAULT_LANGUAGE_CODE):
5151
current = self.get(is_default=True)
52-
if lang != "en":
52+
if lang != settings.DEFAULT_LANGUAGE_CODE:
5353
try:
5454
return self.get(lang=lang, release=current.release)
5555
except DocumentRelease.DoesNotExist:
@@ -99,7 +99,9 @@ class DocumentRelease(models.Model):
9999

100100
DEFAULT_CACHE_KEY = "%s_docs_version" % settings.CACHE_MIDDLEWARE_KEY_PREFIX
101101

102-
lang = models.CharField(max_length=7, choices=settings.LANGUAGES, default="en")
102+
lang = models.CharField(
103+
max_length=7, choices=settings.LANGUAGES, default=settings.DEFAULT_LANGUAGE_CODE
104+
)
103105
release = models.ForeignKey(
104106
Release,
105107
null=True,

docs/templatetags/docs.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from urllib.parse import quote
33

44
from django import template
5+
from django.conf import settings
56
from django.template.defaultfilters import stringfilter
67
from django.utils.safestring import mark_safe
78
from django.utils.version import get_version_tuple
@@ -38,7 +39,7 @@ def get_all_doc_versions(context, url=None):
3839
3940
Usage: {% get_all_doc_versions <url> as "varname" %}
4041
"""
41-
lang = context.get("lang", "en")
42+
lang = context.get("lang", settings.DEFAULT_LANGUAGE_CODE)
4243
versions = []
4344

4445
# Look for each version of the docs.

docs/tests/test_models.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@ def setUpTestData(cls):
122122
DocumentRelease.objects.bulk_create(
123123
DocumentRelease(lang=lang, release=release)
124124
for lang, release in [
125-
("en", None),
126-
("en", r1),
127-
("en", r2),
125+
(settings.DEFAULT_LANGUAGE_CODE, None),
126+
(settings.DEFAULT_LANGUAGE_CODE, r1),
127+
(settings.DEFAULT_LANGUAGE_CODE, r2),
128128
("sv", r1),
129129
("ar", r1),
130130
]
@@ -133,23 +133,28 @@ def setUpTestData(cls):
133133
def test_by_version(self):
134134
self.assertQuerySetEqual(
135135
DocumentRelease.objects.by_version("1.0"),
136-
[("en", "1.0"), ("sv", "1.0"), ("ar", "1.0")],
136+
[(settings.DEFAULT_LANGUAGE_CODE, "1.0"), ("sv", "1.0"), ("ar", "1.0")],
137137
transform=attrgetter("lang", "version"),
138138
ordered=False,
139139
)
140140

141141
def test_by_version_dev(self):
142142
self.assertQuerySetEqual(
143143
DocumentRelease.objects.by_version("dev"),
144-
[("en", "dev")],
144+
[(settings.DEFAULT_LANGUAGE_CODE, "dev")],
145145
transform=attrgetter("lang", "version"),
146146
ordered=False,
147147
)
148148

149149
def test_by_versions(self):
150150
self.assertQuerySetEqual(
151151
DocumentRelease.objects.by_versions("1.0", "dev"),
152-
[("en", "dev"), ("en", "1.0"), ("sv", "1.0"), ("ar", "1.0")],
152+
[
153+
(settings.DEFAULT_LANGUAGE_CODE, "dev"),
154+
(settings.DEFAULT_LANGUAGE_CODE, "1.0"),
155+
("sv", "1.0"),
156+
("ar", "1.0"),
157+
],
153158
transform=attrgetter("lang", "version"),
154159
ordered=False,
155160
)
@@ -159,18 +164,20 @@ def test_by_versions_empty(self):
159164
DocumentRelease.objects.by_versions()
160165

161166
def test_get_by_version_and_lang_exists(self):
162-
doc = DocumentRelease.objects.get_by_version_and_lang("1.0", "en")
167+
doc = DocumentRelease.objects.get_by_version_and_lang(
168+
"1.0", settings.DEFAULT_LANGUAGE_CODE
169+
)
163170
self.assertEqual(doc.release.version, "1.0")
164-
self.assertEqual(doc.lang, "en")
171+
self.assertEqual(doc.lang, settings.DEFAULT_LANGUAGE_CODE)
165172

166173
def test_get_by_version_and_lang_missing(self):
167174
with self.assertRaises(DocumentRelease.DoesNotExist):
168175
DocumentRelease.objects.get_by_version_and_lang("2.0", "sv")
169176

170177
def test_get_available_languages_by_version(self):
171178
get = DocumentRelease.objects.get_available_languages_by_version
172-
self.assertEqual(list(get("1.0")), ["ar", "en", "sv"])
173-
self.assertEqual(list(get("2.0")), ["en"])
179+
self.assertEqual(list(get("1.0")), ["ar", settings.DEFAULT_LANGUAGE_CODE, "sv"])
180+
self.assertEqual(list(get("2.0")), [settings.DEFAULT_LANGUAGE_CODE])
174181
self.assertEqual(list(get("3.0")), [])
175182

176183

@@ -444,7 +451,7 @@ def test_search_title(self):
444451
with self.assertNumQueries(1):
445452
self.assertQuerySetEqual(
446453
misspelled_query,
447-
[("Generic views", "en", "1.2.3")],
454+
[("Generic views", settings.DEFAULT_LANGUAGE_CODE, "1.2.3")],
448455
transform=attrgetter(
449456
"headline", "release.lang", "release.release.version"
450457
),

docs/tests/test_templates.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import tempfile
44
from pathlib import Path
55

6+
from django.conf import settings
67
from django.template import Context, Template
78
from django.template.loader import render_to_string
89
from django.test import RequestFactory, TestCase
@@ -27,8 +28,16 @@ def test_get_all_doc_versions_empty(self):
2728
def test_get_all_doc_versions(self):
2829
tmp_docs_build_root = Path(tempfile.mkdtemp())
2930
self.addCleanup(shutil.rmtree, tmp_docs_build_root)
30-
os.makedirs(tmp_docs_build_root.joinpath("en", "1.8", "_built", "json"))
31-
os.makedirs(tmp_docs_build_root.joinpath("en", "1.11", "_built", "json"))
31+
os.makedirs(
32+
tmp_docs_build_root.joinpath(
33+
settings.DEFAULT_LANGUAGE_CODE, "1.8", "_built", "json"
34+
)
35+
)
36+
os.makedirs(
37+
tmp_docs_build_root.joinpath(
38+
settings.DEFAULT_LANGUAGE_CODE, "1.11", "_built", "json"
39+
)
40+
)
3241
with self.settings(DOCS_BUILD_ROOT=tmp_docs_build_root):
3342
self.assertEqual(get_all_doc_versions({}), ["1.8", "1.11", "dev"])
3443

@@ -193,15 +202,15 @@ class TemplateTestCase(TestCase):
193202
def _assertOGTitleEqual(self, doc, expected):
194203
output = render_to_string(
195204
"docs/doc.html",
196-
{"doc": doc, "lang": "en", "version": "5.0"},
205+
{"doc": doc, "lang": settings.DEFAULT_LANGUAGE_CODE, "version": "5.0"},
197206
request=RequestFactory().get("/"),
198207
)
199208
self.assertInHTML(f'<meta property="og:title" content="{expected}" />', output)
200209

201210
def test_opengraph_title(self):
202211
doc = Document.objects.create(
203212
release=DocumentRelease.objects.create(
204-
lang="en",
213+
lang=settings.DEFAULT_LANGUAGE_CODE,
205214
release=Release.objects.create(version="5.0"),
206215
),
207216
)

docs/tests/test_views.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,11 @@ def test_code_links(self):
199199
base_url = reverse_with_host(
200200
"document-detail",
201201
host="docs",
202-
kwargs={"lang": "en", "version": "5.1", "url": "refs/query"},
202+
kwargs={
203+
"lang": settings.DEFAULT_LANGUAGE_CODE,
204+
"version": "5.1",
205+
"url": "refs/query",
206+
},
203207
)
204208
for query, expected_code_links in [
205209
(
@@ -247,7 +251,9 @@ def test_sitemap_index(self):
247251
)
248252
self.assertContains(response, "<sitemap>", count=2)
249253
en_sitemap_url = reverse_with_host(
250-
"document-sitemap", host="docs", kwargs={"section": "en"}
254+
"document-sitemap",
255+
host="docs",
256+
kwargs={"section": settings.DEFAULT_LANGUAGE_CODE},
251257
)
252258
self.assertContains(response, f"<loc>{en_sitemap_url}</loc>")
253259

docs/views_debug.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from django.conf import settings
12
from django.views import static
23

34
from .models import DocumentRelease
@@ -24,5 +25,7 @@ def objects_inventory(request, lang, version):
2425

2526
def pot_file(request, pot_name):
2627
version = DocumentRelease.objects.current().version
27-
doc_root = get_doc_root_or_404("en", version, builder="gettext")
28+
doc_root = get_doc_root_or_404(
29+
settings.DEFAULT_LANGUAGE_CODE, version, builder="gettext"
30+
)
2831
return static.serve(request, document_root=doc_root, path=pot_name)

0 commit comments

Comments
 (0)