Skip to content

Commit

Permalink
Merge pull request #5198 from GeoNode/ISSUE-5197
Browse files Browse the repository at this point in the history
[Fixes #5197] Admin Panel add Menu Item does not work for UTF-8 Characters
  • Loading branch information
Alessio Fabiani authored Nov 11, 2019
2 parents 1e0c835 + f2a3d70 commit 862bb8a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 19 deletions.
9 changes: 9 additions & 0 deletions geonode/base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1359,6 +1359,9 @@ class MenuPlaceholder(models.Model):
unique=True
)

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

def __str__(self):
return self.name

Expand All @@ -1379,6 +1382,9 @@ class Menu(models.Model):
null=False,
)

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

def __str__(self):
return self.title

Expand Down Expand Up @@ -1412,6 +1418,9 @@ class MenuItem(models.Model):
blank=False
)

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

def __str__(self):
return self.title

Expand Down
42 changes: 23 additions & 19 deletions geonode/base/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def setUp(self):
name='test_menu_placeholder_0'
)
self.placeholder_1 = MenuPlaceholder.objects.create(
name='test_menu_placeholder_1'
name=u'test_unicode_äöü_menu_placeholder_1'
)
self.menu_0_0 = Menu.objects.create(
title='test_menu_0_0',
Expand All @@ -63,7 +63,7 @@ def setUp(self):

)
self.menu_1_0 = Menu.objects.create(
title='test_menu_1_0',
title=u'test_unicode_äöü_menu_1_0',
order=0,
placeholder=self.placeholder_1

Expand Down Expand Up @@ -104,14 +104,14 @@ def setUp(self):
menu=self.menu_0_1
)
self.menu_item_1_0_0 = MenuItem.objects.create(
title='test_menu_item_1_0_0',
title=u'test_unicode_äöü_menu_item_1_0_0',
order=0,
blank_target=False,
url='/about',
menu=self.menu_1_0
)
self.menu_item_1_0_1 = MenuItem.objects.create(
title='test_menu_item_1_0_1',
title=u'test_unicode_äöü_menu_item_1_0_1',
order=1,
blank_target=False,
url='/about',
Expand All @@ -124,7 +124,7 @@ def test_get_menu_placeholder_0(self):
)
rendered = template.render(Context({}))
# menu_placeholder_0
# first menu
# first menu with ascii chars
self.assertIn(
self.menu_0_0.title,
rendered,
Expand Down Expand Up @@ -177,31 +177,32 @@ def test_get_menu_placeholder_0(self):
)
# menu_placeholder_1
# first menu
# unicode
self.assertNotIn(
self.menu_1_0.title,
rendered,
'No "{}" string expected in the rendered template'.format(
u'No "{}" string expected in the rendered template'.format(
self.menu_1_0.title
)
)
self.assertNotIn(
self.menu_item_1_0_0.title,
rendered,
'No "{}" string expected in the rendered template'.format(
u'No "{}" string expected in the rendered template'.format(
self.menu_item_1_0_0.title
)
)
self.assertNotIn(
self.menu_item_1_0_1.title,
rendered,
'No "{}" string expected in the rendered template'.format(
u'No "{}" string expected in the rendered template'.format(
self.menu_item_1_0_1.title
)
)

def test_get_menu_placeholder_1(self):
template = Template(
"{% load base_tags %} {% get_menu 'test_menu_placeholder_1' %}"
"{% load base_tags %} {% get_menu 'test_unicode_äöü_menu_placeholder_1' %}"
)
rendered = template.render(Context({}))
# menu_placeholder_0
Expand Down Expand Up @@ -258,24 +259,25 @@ def test_get_menu_placeholder_1(self):
)
# menu_placeholder_1
# first menu
# unicode
self.assertIn(
self.menu_1_0.title,
rendered,
'Expected "{}" string in the rendered template'.format(
u'Expected "{}" string in the rendered template'.format(
self.menu_1_0.title
)
)
self.assertIn(
self.menu_item_1_0_0.title,
rendered,
'Expected "{}" string in the rendered template'.format(
u'Expected "{}" string in the rendered template'.format(
self.menu_item_1_0_0.title
)
)
self.assertIn(
self.menu_item_1_0_1.title,
rendered,
'Expected "{}" string in the rendered template'.format(
u'Expected "{}" string in the rendered template'.format(
self.menu_item_1_0_1.title
)
)
Expand Down Expand Up @@ -339,31 +341,32 @@ def test_render_nav_menu_placeholder_0(self):
)
# menu_placeholder_1
# first menu
# unicode
self.assertNotIn(
self.menu_1_0.title,
rendered,
'No "{}" string expected in the rendered template'.format(
u'No "{}" string expected in the rendered template'.format(
self.menu_1_0.title
)
)
self.assertNotIn(
self.menu_item_1_0_0.title,
rendered,
'No "{}" string expected in the rendered template'.format(
u'No "{}" string expected in the rendered template'.format(
self.menu_item_1_0_0.title
)
)
self.assertNotIn(
self.menu_item_1_0_1.title,
rendered,
'No "{}" string expected in the rendered template'.format(
u'No "{}" string expected in the rendered template'.format(
self.menu_item_1_0_1.title
)
)

def test_render_nav_menu_placeholder_1(self):
template = Template(
"{% load base_tags %} {% render_nav_menu 'test_menu_placeholder_1' %}"
"{% load base_tags %} {% render_nav_menu 'test_unicode_äöü_menu_placeholder_1' %}"
)
rendered = template.render(Context({}))
# menu_placeholder_0
Expand Down Expand Up @@ -420,24 +423,25 @@ def test_render_nav_menu_placeholder_1(self):
)
# menu_placeholder_1
# first menu
# unicode
self.assertIn(
self.menu_1_0.title,
rendered,
'Expected "{}" string in the rendered template'.format(
u'Expected "{}" string in the rendered template'.format(
self.menu_1_0.title
)
)
self.assertIn(
self.menu_item_1_0_0.title,
rendered,
'Expected "{}" string in the rendered template'.format(
u'Expected "{}" string in the rendered template'.format(
self.menu_item_1_0_0.title
)
)
self.assertIn(
self.menu_item_1_0_1.title,
rendered,
'Expected "{}" string in the rendered template'.format(
u'Expected "{}" string in the rendered template'.format(
self.menu_item_1_0_1.title
)
)

0 comments on commit 862bb8a

Please sign in to comment.