summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorskidipap <mad.skidipap@gmail.com>2023-02-01 17:18:35 +0700
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2023-02-02 13:21:08 +0100
commit1250483ebf73f7a82ff820b94092c63ce4238264 (patch)
tree5c4bf71a5439a6ead50e86705219fb2223214c5f
parentc626173833784c86920b448793ac45005af4c058 (diff)
Fixed #34286 -- Fixed admindocs markups for case-sensitive template/view names.
-rw-r--r--AUTHORS1
-rw-r--r--django/contrib/admindocs/utils.py5
-rw-r--r--tests/admin_docs/test_utils.py16
3 files changed, 21 insertions, 1 deletions
diff --git a/AUTHORS b/AUTHORS
index 4e91d7b3f3..2cddbf9280 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -808,6 +808,7 @@ answer newbie questions, and generally made Django that much better:
Radek Švarz <https://www.svarz.cz/translate/>
Rafael Giebisch <rafael@giebisch-mail.de>
Raffaele Salmaso <raffaele@salmaso.org>
+ Rahmat Faisal <mad.skidipap@gmail.com>
Rajesh Dhawan <rajesh.dhawan@gmail.com>
Ramez Ashraf <ramezashraf@gmail.com>
Ramil Yanbulatov <rayman1104@gmail.com>
diff --git a/django/contrib/admindocs/utils.py b/django/contrib/admindocs/utils.py
index 6edff502ec..3708a32813 100644
--- a/django/contrib/admindocs/utils.py
+++ b/django/contrib/admindocs/utils.py
@@ -101,6 +101,9 @@ ROLES = {
def create_reference_role(rolename, urlbase):
+ # Views and template names are case-sensitive.
+ is_case_sensitive = rolename in ["template", "view"]
+
def _role(name, rawtext, text, lineno, inliner, options=None, content=None):
if options is None:
options = {}
@@ -111,7 +114,7 @@ def create_reference_role(rolename, urlbase):
urlbase
% (
inliner.document.settings.link_base,
- text.lower(),
+ text if is_case_sensitive else text.lower(),
)
),
**options,
diff --git a/tests/admin_docs/test_utils.py b/tests/admin_docs/test_utils.py
index 18c6769fad..8152857263 100644
--- a/tests/admin_docs/test_utils.py
+++ b/tests/admin_docs/test_utils.py
@@ -104,6 +104,22 @@ class TestUtils(AdminDocsSimpleTestCase):
self.assertEqual(parse_rst(body, ""), "<p>second line</p>\n")
self.assertEqual(stderr.getvalue(), "")
+ def test_parse_rst_view_case_sensitive(self):
+ source = ":view:`myapp.views.Index`"
+ rendered = (
+ '<p><a class="reference external" '
+ 'href="/admindocs/views/myapp.views.Index/">myapp.views.Index</a></p>'
+ )
+ self.assertHTMLEqual(parse_rst(source, "view"), rendered)
+
+ def test_parse_rst_template_case_sensitive(self):
+ source = ":template:`Index.html`"
+ rendered = (
+ '<p><a class="reference external" href="/admindocs/templates/Index.html/">'
+ "Index.html</a></p>"
+ )
+ self.assertHTMLEqual(parse_rst(source, "template"), rendered)
+
def test_publish_parts(self):
"""
Django shouldn't break the default role for interpreted text