Skip to content

Commit

Permalink
[Backport to 3.2.x GeoNode#7105] Remove HTML tags from metadata detail (
Browse files Browse the repository at this point in the history
GeoNode#7117)

* [Fixes: GeoNode#7033] Mandatory fields in editor

* [Backport GeoNode#7105] Backport of GeoNode#7015

* [Backport GeoNode#7105] Remove HTML tags from metadata detail

* [Backport GeoNode#7105] Remove HTML tags from metadata detail
  • Loading branch information
mattiagiupponi authored Mar 19, 2021
1 parent c3dee35 commit ffc0f1b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
4 changes: 2 additions & 2 deletions geonode/base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
14 changes: 14 additions & 0 deletions geonode/base/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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>&lt;p&gt;Abstract value &amp; some text&lt;/p&gt;</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 = """<p><p><p><p>Abstract value &amp; some text</p></p></p></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)


class TestTagThesaurus(TestCase):
# loading test thesausurs
Expand Down
10 changes: 5 additions & 5 deletions geonode/catalogue/templates/geonode_metadata_full.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ <h2 class="page-title">{{ resource.title }}</h2>
<dd>{{resource.date}}, {% trans resource.date_type|title %} </dd>

<dt>{% trans "Abstract" %}</dt>
<dd>{{resource.abstract}}</dd>
<dd>{{resource.raw_abstract}}</dd>

<dt>{% trans "Edition" %}</dt>
{% if resource.edition %}
Expand All @@ -79,7 +79,7 @@ <h2 class="page-title">{{ resource.title }}</h2>

<dt>{% trans "Purpose" %}</dt>
{% if resource.purpose %}
<dd>{{resource.purpose}}</dd>
<dd>{{resource.raw_purpose}}</dd>
{% else %}
<dd> -- </dd>
{% endif %}
Expand All @@ -93,7 +93,7 @@ <h2 class="page-title">{{ resource.title }}</h2>

<dt>{% trans "Restrictions" %}</dt>
<dd>{{resource.restriction_code_type}}</dd>
<dd>{{resource.constraints_other}}</dd>
<dd>{{resource.raw_constraints_other}}</dd>

<dt>{% trans "License" %}</dt>
<dd>{{resource.license}}</dd>
Expand All @@ -117,11 +117,11 @@ <h2 class="page-title">{{ resource.title }}</h2>


<dt>{% trans "Supplemental Information" %}</dt>
<dd>{{resource.supplemental_information}}</dd>
<dd>{{resource.raw_supplemental_information}}</dd>

<dt>{% trans "Data Quality" %} </dt>
{% if resource.data_quality_statement %}
<dd>{{resource.data_quality_statement}}</dd>
<dd>{{resource.raw_data_quality_statement}}</dd>
{% else %}
<dd> -- </dd>
{% endif %}
Expand Down

0 comments on commit ffc0f1b

Please sign in to comment.