From ffc0f1ba730da8fa36249d3f0adbfa18dd623be4 Mon Sep 17 00:00:00 2001 From: mattiagiupponi <51856725+mattiagiupponi@users.noreply.github.com> Date: Fri, 19 Mar 2021 18:22:31 +0100 Subject: [PATCH] [Backport to 3.2.x #7105] Remove HTML tags from metadata detail (#7117) * [Fixes: #7033] Mandatory fields in editor * [Backport #7105] Backport of #7015 * [Backport #7105] Remove HTML tags from metadata detail * [Backport #7105] Remove HTML tags from metadata detail --- geonode/base/models.py | 4 ++-- geonode/base/tests.py | 14 ++++++++++++++ .../catalogue/templates/geonode_metadata_full.html | 10 +++++----- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/geonode/base/models.py b/geonode/base/models.py index 4cbcf8413ea..6da61c20eeb 100644 --- a/geonode/base/models.py +++ b/geonode/base/models.py @@ -43,7 +43,7 @@ from django.contrib.contenttypes.models import ContentType from django.contrib.staticfiles.templatetags import staticfiles from django.core.files.storage import default_storage as storage - +from django.utils.html import strip_tags from mptt.models import MPTTModel, TreeForeignKey from PIL import Image, ImageOps @@ -927,7 +927,7 @@ def _remove_html_tags(self, attribute_str): if attribute_str: _attribute_str = html.unescape( attribute_str.replace('\n', ' ').replace('\r', '').strip()) - return _attribute_str + return strip_tags(_attribute_str) @property def raw_abstract(self): diff --git a/geonode/base/tests.py b/geonode/base/tests.py index 651bca9c951..8c7a8e713d5 100644 --- a/geonode/base/tests.py +++ b/geonode/base/tests.py @@ -825,6 +825,20 @@ def test_complex_tags_in_attribute(self): filtered_value = r._remove_html_tags(tagged_value) self.assertEqual(filtered_value, attribute_target_value) + def test_converted_html_in_tags_with_char_references(self): + tagged_value = """

<p>Abstract value & some text</p>

""" + attribute_target_value = """Abstract value & some text""" + r = ResourceBase() + filtered_value = r._remove_html_tags(tagged_value) + self.assertEqual(filtered_value, attribute_target_value) + + def test_converted_html_in_tags_with_with_multiple_tags(self): + tagged_value = """

Abstract value & some text

""" + attribute_target_value = """Abstract value & some text""" + r = ResourceBase() + filtered_value = r._remove_html_tags(tagged_value) + self.assertEqual(filtered_value, attribute_target_value) + class TestTagThesaurus(TestCase): # loading test thesausurs diff --git a/geonode/catalogue/templates/geonode_metadata_full.html b/geonode/catalogue/templates/geonode_metadata_full.html index 48c0ce05d57..2e55babd0cf 100644 --- a/geonode/catalogue/templates/geonode_metadata_full.html +++ b/geonode/catalogue/templates/geonode_metadata_full.html @@ -59,7 +59,7 @@

{{ resource.title }}

{{resource.date}}, {% trans resource.date_type|title %}
{% trans "Abstract" %}
-
{{resource.abstract}}
+
{{resource.raw_abstract}}
{% trans "Edition" %}
{% if resource.edition %} @@ -79,7 +79,7 @@

{{ resource.title }}

{% trans "Purpose" %}
{% if resource.purpose %} -
{{resource.purpose}}
+
{{resource.raw_purpose}}
{% else %}
--
{% endif %} @@ -93,7 +93,7 @@

{{ resource.title }}

{% trans "Restrictions" %}
{{resource.restriction_code_type}}
-
{{resource.constraints_other}}
+
{{resource.raw_constraints_other}}
{% trans "License" %}
{{resource.license}}
@@ -117,11 +117,11 @@

{{ resource.title }}

{% trans "Supplemental Information" %}
-
{{resource.supplemental_information}}
+
{{resource.raw_supplemental_information}}
{% trans "Data Quality" %}
{% if resource.data_quality_statement %} -
{{resource.data_quality_statement}}
+
{{resource.raw_data_quality_statement}}
{% else %}
--
{% endif %}