From 8731b3b9c9acf90e558e132032cefbef3dba4d92 Mon Sep 17 00:00:00 2001 From: KK Date: Thu, 7 Dec 2023 15:41:32 +0100 Subject: [PATCH] fix: tooltips for class docstrings, whitespace issues - fixes linebreaks between text and HTML tags caused by templatetag - checks for existence of docstrings following Python formatting conventions (see PEP 257) instead of falling back on class definition PEP 257: https://peps.python.org/pep-0257/ --- apis_core/apis_entities/views.py | 6 ++++-- .../templates/apis_metainfo/tags/class_definition.html | 6 +++++- apis_core/apis_metainfo/templates/generic_list.html | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/apis_core/apis_entities/views.py b/apis_core/apis_entities/views.py index 0d0b5264b..ac25bc410 100644 --- a/apis_core/apis_entities/views.py +++ b/apis_core/apis_entities/views.py @@ -156,10 +156,12 @@ def get_context_data(self, **kwargs): context[self.context_filter_name] = self.filter context["entity"] = self.entity # model slug context["app_name"] = "apis_entities" - context["docstring"] = f"{model.__doc__}" - context["entity_create_stanbol"] = GenericEntitiesStanbolForm(self.entity) + # only consider properly formatted docstrings (PEP 257) + if '"""' in model.__doc__: + context["docstring"] = f"{model.__doc__}" + if "browsing" in settings.INSTALLED_APPS: from browsing.models import BrowsConf diff --git a/apis_core/apis_metainfo/templates/apis_metainfo/tags/class_definition.html b/apis_core/apis_metainfo/templates/apis_metainfo/tags/class_definition.html index 1307b7a29..78ecc9ee5 100644 --- a/apis_core/apis_metainfo/templates/apis_metainfo/tags/class_definition.html +++ b/apis_core/apis_metainfo/templates/apis_metainfo/tags/class_definition.html @@ -1 +1,5 @@ -{{ class_name }} +{% if docstring %} + {{ class_name }} +{% else %} + {{ class_name }} +{% endif %} diff --git a/apis_core/apis_metainfo/templates/generic_list.html b/apis_core/apis_metainfo/templates/generic_list.html index fd467055c..eab859700 100644 --- a/apis_core/apis_metainfo/templates/generic_list.html +++ b/apis_core/apis_metainfo/templates/generic_list.html @@ -29,7 +29,7 @@
-

+

Browse {% class_definition %} {% block list_title %}{% endblock %}