Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed #1459 -- Fixed get_all_doc_versions template tag. #1460

Merged
merged 1 commit into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions docs/fixtures/doc_test_fixtures.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,19 @@
"status": "f"
}
},
{
"model": "releases.release",
"pk": "1.11",
"fields": {
"major": 1,
"is_lts": true,
"date": "2017-04-04",
"iteration": 0,
"micro": 0,
"minor": 11,
"status": "f"
}
},
{
"fields": {
"lang": "en",
Expand Down Expand Up @@ -153,5 +166,23 @@
},
"model": "docs.documentrelease",
"pk": 14
},
{
"fields": {
"lang": "en",
"is_default": true,
"release": "1.11"
},
"model": "docs.documentrelease",
"pk": 15
},
{
"fields": {
"lang": "fr",
"is_default": false,
"release": "1.11"
},
"model": "docs.documentrelease",
"pk": 16
}
]
2 changes: 1 addition & 1 deletion docs/templatetags/docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def get_all_doc_versions(context, url=None):

# Save the versions into the context
versions = sorted(get_version_tuple(x) for x in versions if x != "dev")
return [str(x) for x in versions] + ["dev"]
return [".".join([str(part) for part in x]) for x in versions] + ["dev"]


class PygmentsNode(template.Node):
Expand Down
14 changes: 12 additions & 2 deletions docs/tests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import datetime
import os
import shutil
import tempfile
from http import HTTPStatus
from operator import attrgetter
from pathlib import Path
Expand Down Expand Up @@ -195,9 +197,17 @@ def test_empty_get(self):
class TemplateTagTests(TestCase):
fixtures = ["doc_test_fixtures"]

def test_get_all_doc_versions(self):
def test_get_all_doc_versions_empty(self):
with self.assertNumQueries(1):
get_all_doc_versions({})
self.assertEqual(get_all_doc_versions({}), ["dev"])

def test_get_all_doc_versions(self):
tmp_docs_build_root = Path(tempfile.mkdtemp())
self.addCleanup(shutil.rmtree, tmp_docs_build_root)
os.makedirs(tmp_docs_build_root.joinpath("en", "1.8", "_built", "json"))
os.makedirs(tmp_docs_build_root.joinpath("en", "1.11", "_built", "json"))
with self.settings(DOCS_BUILD_ROOT=tmp_docs_build_root):
self.assertEqual(get_all_doc_versions({}), ["1.8", "1.11", "dev"])

def test_pygments_template_tag(self):
template = Template(
Expand Down
Loading