diff --git a/mapit/models.py b/mapit/models.py index 358637a8..6e9e6144 100644 --- a/mapit/models.py +++ b/mapit/models.py @@ -5,7 +5,7 @@ from django.conf import settings from django.db import connection from django.db.models.query import RawQuerySet -from django.utils.encoding import python_2_unicode_compatible +from django.utils.encoding import python_2_unicode_compatible, smart_text from mapit import countries from mapit.geometryserialiser import GeometrySerialiser @@ -333,7 +333,7 @@ class Meta: verbose_name_plural = 'geometries' def __str__(self): - return '%s, polygon %d' % (self.area, self.id) + return '%s, polygon %d' % (smart_text(self.area), self.id) @python_2_unicode_compatible diff --git a/mapit/tests/test_names.py b/mapit/tests/test_names.py index aa94c6c2..146b38ef 100644 --- a/mapit/tests/test_names.py +++ b/mapit/tests/test_names.py @@ -1,4 +1,9 @@ +# coding=utf-8 + from django.test import TestCase +from django.conf import settings +from django.contrib.gis.geos import Polygon +from django.utils.encoding import smart_text from mapit.models import Type, Area, Generation, Name, NameType import mapit_gb.countries @@ -29,6 +34,10 @@ def setUp(self): generation_high=self.generation, ) + polygon = Polygon(((-5, 50), (-5, 55), (1, 55), (1, 50), (-5, 50)), srid=4326) + polygon.transform(settings.MAPIT_AREA_SRID) + self.geometry = self.area.polygons.create(polygon=polygon) + def test_new_name_changes_area_name_in_gb(self): """We can't use override_settings, as mapit.countries has been set based upon MAPIT_COUNTRY already in initial import""" @@ -40,3 +49,10 @@ def test_new_name_does_not_change_area_name_elsewhere(self): mapit.models.countries = None Name.objects.create(name='New Name', type=self.name_type, area=self.area) self.assertEqual(self.area.name, 'Big Area') + + def test_geometry_name_works(self): + name = smart_text('Big “Area”') + self.area.name = name + self.area.save() + should_be = '%s %s, polygon %d' % (self.area_type.code, name, self.geometry.id) + self.assertEqual(smart_text(self.geometry), should_be) diff --git a/mapit_gb/management/commands/mapit_UK_time_lookups.py b/mapit_gb/management/commands/mapit_UK_time_lookups.py index eefd7f3f..9debc60c 100644 --- a/mapit_gb/management/commands/mapit_UK_time_lookups.py +++ b/mapit_gb/management/commands/mapit_UK_time_lookups.py @@ -43,6 +43,7 @@ def get_random_UK_location(): location.coords = (new_lon, new_lat) return location + random_locations = None diff --git a/mapit_global/management/commands/mapit_global_import.py b/mapit_global/management/commands/mapit_global_import.py index 84bca3dd..cf23cbd5 100644 --- a/mapit_global/management/commands/mapit_global_import.py +++ b/mapit_global/management/commands/mapit_global_import.py @@ -42,6 +42,7 @@ def make_missing_none(s): else: return s + LanguageCodes = namedtuple('LanguageCodes', ['three_letter', 'two_letter', diff --git a/project/wsgi_monitor.py b/project/wsgi_monitor.py index 8510c164..04057e9a 100644 --- a/project/wsgi_monitor.py +++ b/project/wsgi_monitor.py @@ -100,6 +100,7 @@ def _exiting(): pass _thread.join() + atexit.register(_exiting)