Skip to content

Commit

Permalink
[Fixes #6665] Improve WYSIWYG metadata editor to store formatted and …
Browse files Browse the repository at this point in the history
…plain texts (#6666) (#6668)

Co-authored-by: Alessio Fabiani <alessio.fabiani@geo-solutions.it>
  • Loading branch information
github-actions[bot] and Alessio Fabiani authored Nov 24, 2020
1 parent 5b59b92 commit 3fd48ba
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 8 deletions.
24 changes: 24 additions & 0 deletions geonode/base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,30 @@ def __init__(self, *args, **kwargs):
def __str__(self):
return "{0}".format(self.title)

def _remove_html_tags(self, attribute_str):
pattern = re.compile('<.*?>')
return re.sub(pattern, '', attribute_str)

@property
def raw_abstract(self):
return self._remove_html_tags(self.abstract)

@property
def raw_purpose(self):
return self._remove_html_tags(self.purpose)

@property
def raw_constraints_other(self):
return self._remove_html_tags(self.constraints_other)

@property
def raw_supplemental_information(self):
return self._remove_html_tags(self.supplemental_information)

@property
def raw_data_quality_statement(self):
return self._remove_html_tags(self.data_quality_statement)

def save(self, notify=False, *args, **kwargs):
"""
Send a notification when a resource is created or updated
Expand Down
28 changes: 26 additions & 2 deletions geonode/base/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
)
from django.template import Template, Context
from django.contrib.auth import get_user_model
from django.test import Client, TestCase, override_settings
from django.test import Client, TestCase, override_settings, SimpleTestCase
from django.shortcuts import reverse

from geonode.base.middleware import ReadOnlyMiddleware, MaintenanceMiddleware
Expand All @@ -50,7 +50,6 @@
from django.core.management import call_command
from django.core.management.base import CommandError


test_image = Image.new('RGBA', size=(50, 50), color=(155, 0, 0))


Expand Down Expand Up @@ -805,3 +804,28 @@ def test_category_data_shown_for_with_resourcebase_permissions(self):
assign_perm('view_resourcebase', self.user, self.rb)
categories = get_visibile_resources(self.user)
self.assertEqual(categories['iso_formats'].count(), 1)


class TestHtmlTagRemoval(SimpleTestCase):

def test_not_tags_in_attribute(self):
attribute_target_value = "This is not a templated text"
r = ResourceBase()
filtered_value = r._remove_html_tags(attribute_target_value)
self.assertEqual(attribute_target_value, filtered_value)

def test_simple_tags_in_attribute(self):
tagged_value = "<p>This is not a templated text<p>"
attribute_target_value = "This is not a templated text"
r = ResourceBase()
filtered_value = r._remove_html_tags(tagged_value)
self.assertEqual(filtered_value, attribute_target_value)

def test_complex_tags_in_attribute(self):
tagged_value = """<p style="display:none;" id="test">This is not a templated text<p>
<div class="test_css">Something in container</div>"""
attribute_target_value = """This is not a templated text
Something in container"""
r = ResourceBase()
filtered_value = r._remove_html_tags(tagged_value)
self.assertEqual(filtered_value, attribute_target_value)
12 changes: 6 additions & 6 deletions geonode/catalogue/templates/catalogue/full_metadata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,10 @@
</gmd:CI_Citation>
</gmd:citation>
<gmd:abstract>
<gco:CharacterString>{{layer.abstract}}</gco:CharacterString>
<gco:CharacterString>{{layer.raw_abstract}}</gco:CharacterString>
</gmd:abstract>
<gmd:purpose {% if not layer.purpose %}gco:nilReason="missing"{% endif %}>
{% if layer.purpose %}<gco:CharacterString>{{layer.purpose}}</gco:CharacterString>{% endif %}
<gmd:purpose {% if not layer.raw_purpose %}gco:nilReason="missing"{% endif %}>
{% if layer.raw_purpose %}<gco:CharacterString>{{layer.raw_purpose}}</gco:CharacterString>{% endif %}
</gmd:purpose>
<gmd:status>
<gmd:MD_ProgressCode codeSpace="ISOTC211/19115" codeList="http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#MD_ProgressCode" codeListValue="completed">completed</gmd:MD_ProgressCode>
Expand Down Expand Up @@ -398,7 +398,7 @@
<gmd:MD_RestrictionCode codeSpace="ISOTC211/19115" codeList="http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#MD_RestrictionCode" codeListValue="{{layer.restriction_code_type.identifier}}">{{layer.restriction_code_type.identifier}}</gmd:MD_RestrictionCode>
</gmd:useConstraints>
<gmd:otherConstraints>
<gco:CharacterString>{{layer.constraints_other}}</gco:CharacterString>
<gco:CharacterString>{{layer.raw_constraints_other}}</gco:CharacterString>
</gmd:otherConstraints>
</gmd:MD_LegalConstraints>
</gmd:resourceConstraints>
Expand Down Expand Up @@ -453,7 +453,7 @@
</gmd:extent>
{% endif %}
<gmd:supplementalInformation>
<gco:CharacterString>{{ layer.supplemental_information }}</gco:CharacterString>
<gco:CharacterString>{{ layer.raw_supplemental_information }}</gco:CharacterString>
</gmd:supplementalInformation>
</gmd:MD_DataIdentification>
</gmd:identificationInfo>
Expand Down Expand Up @@ -543,7 +543,7 @@
</gmd:scope>
<gmd:lineage>
<gmd:LI_Lineage>
<gmd:statement {% if not layer.data_quality_statement %}gco:nilReason="missing"/>{% else %}><gco:CharacterString>{{layer.data_quality_statement}}</gco:CharacterString></gmd:statement>{% endif %}
<gmd:statement {% if not layer.raw_data_quality_statement %}gco:nilReason="missing"/>{% else %}><gco:CharacterString>{{layer.raw_data_quality_statement}}</gco:CharacterString></gmd:statement>{% endif %}
</gmd:LI_Lineage>
</gmd:lineage>
</gmd:DQ_DataQuality>
Expand Down

0 comments on commit 3fd48ba

Please sign in to comment.