Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix display of Geometry object in admin. #273

Merged
merged 2 commits into from
Nov 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions mapit/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: Why didn’t you use u'' as an easier way to fix this?
A: Django 1.8, still supported, still supports Python 3.2, therefore so do we. u'' was only re-added in 3.3.



@python_2_unicode_compatible
Expand Down
16 changes: 16 additions & 0 deletions mapit/tests/test_names.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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"""
Expand All @@ -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)
1 change: 1 addition & 0 deletions mapit_gb/management/commands/mapit_UK_time_lookups.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def get_random_UK_location():
location.coords = (new_lon, new_lat)
return location


random_locations = None


Expand Down
1 change: 1 addition & 0 deletions mapit_global/management/commands/mapit_global_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def make_missing_none(s):
else:
return s


LanguageCodes = namedtuple('LanguageCodes',
['three_letter',
'two_letter',
Expand Down
1 change: 1 addition & 0 deletions project/wsgi_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ def _exiting():
pass
_thread.join()


atexit.register(_exiting)


Expand Down