Skip to content

Commit

Permalink
[Fixes #4011] Encoding Issues with Resource having non-UTF8 characte…
Browse files Browse the repository at this point in the history
…rs on title and/or "upload-sessions" (#4012)

* [Fixes #4011] Encoding Issues with Resource having non-UTF8 characters on title and/or 'upload-sessions'

* [Fixes #4011] Encoding Issues with Resource having non-UTF8 characters on title and/or 'upload-sessions'

* [Fixes #4011] Encoding Issues with Resource having non-UTF8 characters on title and/or 'upload-sessions'

* [Fixes #4011] Encoding Issues with Resource having non-UTF8 characters on title and/or 'upload-sessions'
  • Loading branch information
Alessio Fabiani committed Oct 18, 2018
1 parent 942e286 commit 1cc9b7d
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 19 deletions.
14 changes: 7 additions & 7 deletions geonode/base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ class SpatialRepresentationType(models.Model):
is_choice = models.BooleanField(default=True)

def __unicode__(self):
return self.gn_description
return u"{0}".format(self.gn_description)

class Meta:
ordering = ("identifier",)
Expand Down Expand Up @@ -211,7 +211,7 @@ class Region(MPTTModel):
default='EPSG:4326')

def __unicode__(self):
return self.name
return u"{0}".format(self.name)

@property
def bbox(self):
Expand Down Expand Up @@ -260,7 +260,7 @@ class RestrictionCodeType(models.Model):
is_choice = models.BooleanField(default=True)

def __unicode__(self):
return self.gn_description
return u"{0}".format(self.gn_description)

class Meta:
ordering = ("identifier",)
Expand Down Expand Up @@ -289,7 +289,7 @@ class License(models.Model):
license_text = models.TextField(null=True, blank=True)

def __unicode__(self):
return self.name
return u"{0}".format(self.name)

@property
def name_long(self):
Expand Down Expand Up @@ -763,7 +763,7 @@ class ResourceBase(PolymorphicModel, PermissionLevelMixin, ItemBase):
rating = models.IntegerField(default=0, null=True, blank=True)

def __unicode__(self):
return self.title
return u"{0}".format(self.title)

def get_upload_session(self):
raise NotImplementedError()
Expand Down Expand Up @@ -1310,8 +1310,8 @@ class Link(models.Model):

objects = LinkManager()

def __str__(self):
return '%s link' % self.link_type
def __unicode__(self):
return u"{0} link".format(self.link_type)


def resourcebase_post_save(instance, *args, **kwargs):
Expand Down
10 changes: 9 additions & 1 deletion geonode/groups/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from geonode.tests.base import GeoNodeBaseTestSupport

import json
import logging
from django.contrib.auth import get_user_model
from django.contrib.auth.models import Group
from django.core.files.uploadedfile import SimpleUploadedFile
Expand All @@ -36,6 +37,12 @@
from geonode.maps.models import Map
from geonode.security.views import _perms_info_json

logger = logging.getLogger(__name__)


def _log(msg, *args):
logger.debug(msg, *args)


class SmokeTest(GeoNodeBaseTestSupport):
"""
Expand Down Expand Up @@ -480,8 +487,9 @@ def test_group_activity_pages_render(self):

response = self.client.get("/groups/group/bar/activity/")
self.assertEqual(200, response.status_code)
_log(response)
self.assertContains(response,
'<a href="/layers/geonode:CA">CA</a>',
'<a href="/layers/geonode:CA">geonode:CA</a>',
count=2,
status_code=200,
msg_prefix='',
Expand Down
19 changes: 11 additions & 8 deletions geonode/layers/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
from django.utils.translation import ugettext_lazy as _
from django.core.urlresolvers import reverse
from django.core.files.storage import FileSystemStorage

from geonode.base.models import ResourceBase, ResourceBaseManager, resourcebase_post_save
from geonode.people.utils import get_valid_user
from agon_ratings.models import OverallRating
Expand Down Expand Up @@ -81,8 +80,8 @@ class Style(models.Model, PermissionLevelMixin):
sld_url = models.CharField(_('sld url'), null=True, max_length=1000)
workspace = models.CharField(max_length=255, null=True, blank=True)

def __str__(self):
return "%s" % self.name.encode('utf-8')
def __unicode__(self):
return u"%s" % self.name

def absolute_url(self):
if self.sld_url:
Expand Down Expand Up @@ -269,8 +268,8 @@ def attribute_config(self):
}
return cfg

def __str__(self):
return self.alternate
def __unicode__(self):
return u"{0}".format(self.alternate)
# if self.alternate is not None:
# return "%s Layer" % self.service_typename.encode('utf-8')
# elif self.name is not None:
Expand Down Expand Up @@ -349,8 +348,12 @@ class UploadSession(models.Model):
def successful(self):
return self.processed and self.errors is None

def __str__(self):
return u'%s' % self.resource or self.date
def __unicode__(self):
try:
_s = '%s' % self.resource or self.date
except BaseException:
_s = '%s' % self.date
return u"{0}".format(_s)


class LayerFile(models.Model):
Expand Down Expand Up @@ -490,7 +493,7 @@ class Attribute(models.Model):

objects = AttributeManager()

def __str__(self):
def __unicode__(self):
return "%s" % self.attribute_label.encode(
"utf-8") if self.attribute_label else self.attribute.encode("utf-8")

Expand Down
5 changes: 4 additions & 1 deletion geonode/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
{% if custom_theme.logo %}
.navbar-brand {
background-image: url({{ custom_theme.logo.url }});
background-repeat: no-repeat;
background-position: center;
background-size: contain;
}
{% endif %}

Expand All @@ -65,7 +68,7 @@
.home .jumbotron .container {
position: relative;
z-index: 1;
}
}
.home .jumbotron:after {
content: "";
background-image: url({{ custom_theme.jumbotron_bg.url }});
Expand Down
4 changes: 2 additions & 2 deletions geonode/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ <h4>{{ item.title | limitTo: 20 }}{{item.title.length > 20 ? '...' : ''}}</h4>
</div>
</section>
{% endblock showcase %}
{% block partners %}
{% block partners %}
{% if custom_theme.partners.all %}
<section id="partners">
<div class="container text-center">
Expand All @@ -327,7 +327,7 @@ <h2>{{ custom_theme.partners_title|default:_("Our partners") }}</h2>
</div>
</section>
{% endif %}
{% endblock partners %}
{% endblock partners %}

{% endblock mainbody %}

Expand Down

0 comments on commit 1cc9b7d

Please sign in to comment.