diff options
| author | sai-ganesh-03 <sandursaiganesh@gmail.com> | 2024-10-31 19:10:00 +0530 |
|---|---|---|
| committer | Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> | 2024-11-04 10:43:06 +0100 |
| commit | 968397228fe03968bb855856532569586c8a8a1c (patch) | |
| tree | f755f974db18f58a6ef5b61e6a873bb04d2eb7d3 | |
| parent | 4fcbdb11b114bc4d2dc50663f8053de2f18c0770 (diff) | |
Fixed #35867, Refs #2411 -- Allowed links in admindocs view details summary.
| -rw-r--r-- | django/contrib/admindocs/templates/admin_doc/view_detail.html | 2 | ||||
| -rw-r--r-- | django/contrib/admindocs/utils.py | 4 | ||||
| -rw-r--r-- | django/contrib/admindocs/views.py | 6 | ||||
| -rw-r--r-- | tests/admin_docs/test_views.py | 16 | ||||
| -rw-r--r-- | tests/admin_docs/urls.py | 1 | ||||
| -rw-r--r-- | tests/admin_docs/views.py | 9 |
6 files changed, 32 insertions, 6 deletions
diff --git a/django/contrib/admindocs/templates/admin_doc/view_detail.html b/django/contrib/admindocs/templates/admin_doc/view_detail.html index d1aa3ab98f..5a5b47247e 100644 --- a/django/contrib/admindocs/templates/admin_doc/view_detail.html +++ b/django/contrib/admindocs/templates/admin_doc/view_detail.html @@ -15,7 +15,7 @@ <h1>{{ name }}</h1> -<h2 class="subhead">{{ summary|striptags }}</h2> +<h2 class="subhead">{{ summary }}</h2> {{ body }} diff --git a/django/contrib/admindocs/utils.py b/django/contrib/admindocs/utils.py index 3708a32813..3a7ca4e781 100644 --- a/django/contrib/admindocs/utils.py +++ b/django/contrib/admindocs/utils.py @@ -242,3 +242,7 @@ def remove_non_capturing_groups(pattern): final_pattern += pattern[prev_end:start] prev_end = end return final_pattern + pattern[prev_end:] + + +def strip_p_tags(value): + return mark_safe(value.replace("<p>", "").replace("</p>", "")) diff --git a/django/contrib/admindocs/views.py b/django/contrib/admindocs/views.py index 38a2bb9286..3fdb34e0d1 100644 --- a/django/contrib/admindocs/views.py +++ b/django/contrib/admindocs/views.py @@ -30,7 +30,7 @@ from django.utils.inspect import ( from django.utils.translation import gettext as _ from django.views.generic import TemplateView -from .utils import get_view_name +from .utils import get_view_name, strip_p_tags # Exclude methods starting with these strings from documentation MODEL_METHODS_EXCLUDE = ("_", "add_", "delete", "save", "set_") @@ -195,7 +195,7 @@ class ViewDetailView(BaseAdminDocsView): **{ **kwargs, "name": view, - "summary": title, + "summary": strip_p_tags(title), "body": body, "meta": metadata, } @@ -384,7 +384,7 @@ class ModelDetailView(BaseAdminDocsView): **{ **kwargs, "name": opts.label, - "summary": title, + "summary": strip_p_tags(title), "description": body, "fields": fields, "methods": methods, diff --git a/tests/admin_docs/test_views.py b/tests/admin_docs/test_views.py index 064ce27fb0..c48a89a1b0 100644 --- a/tests/admin_docs/test_views.py +++ b/tests/admin_docs/test_views.py @@ -89,6 +89,18 @@ class AdminDocViewTests(TestDataMixin, AdminDocsTestCase): # View docstring self.assertContains(response, "Base view for admindocs views.") + def testview_docstring_links(self): + summary = ( + '<h2 class="subhead">This is a view for ' + '<a class="reference external" href="/admindocs/models/myapp.company/">' + "myapp.Company</a></h2>" + ) + url = reverse( + "django-admindocs-views-detail", args=["admin_docs.views.CompanyView"] + ) + response = self.client.get(url) + self.assertContains(response, summary, html=True) + @override_settings(ROOT_URLCONF="admin_docs.namespace_urls") def test_namespaced_view_detail(self): url = reverse( @@ -408,9 +420,9 @@ class TestModelDetailView(TestDataMixin, AdminDocsTestCase): def test_model_docstring_renders_correctly(self): summary = ( - '<h2 class="subhead"><p>Stores information about a person, related to ' + '<h2 class="subhead">Stores information about a person, related to ' '<a class="reference external" href="/admindocs/models/myapp.company/">' - "myapp.Company</a>.</p></h2>" + "myapp.Company</a>.</h2>" ) subheading = "<p><strong>Notes</strong></p>" body = ( diff --git a/tests/admin_docs/urls.py b/tests/admin_docs/urls.py index de23d9baf5..779d5f9f5f 100644 --- a/tests/admin_docs/urls.py +++ b/tests/admin_docs/urls.py @@ -14,6 +14,7 @@ urlpatterns = [ path("admin/", admin.site.urls), path("admindocs/", include("django.contrib.admindocs.urls")), path("", include(ns_patterns, namespace="test")), + path("company/", views.CompanyView.as_view()), path("xview/func/", views.xview_dec(views.xview)), path("xview/class/", views.xview_dec(views.XViewClass.as_view())), path("xview/callable_object/", views.xview_dec(views.XViewCallableObject())), diff --git a/tests/admin_docs/views.py b/tests/admin_docs/views.py index 21fe382bba..5bccaf29a0 100644 --- a/tests/admin_docs/views.py +++ b/tests/admin_docs/views.py @@ -18,3 +18,12 @@ class XViewClass(View): class XViewCallableObject(View): def __call__(self, request): return HttpResponse() + + +class CompanyView(View): + """ + This is a view for :model:`myapp.Company` + """ + + def get(self, request): + return HttpResponse() |
