/django/contrib/gis/tests/geoapp/feeds.py
Python | 63 lines | 41 code | 14 blank | 8 comment | 0 complexity | 65964f73beae99434f1c0515d36f84b0 MD5 | raw file
Possible License(s): BSD-3-Clause
1from django.contrib.gis import feeds 2from django.contrib.gis.tests.utils import mysql 3from models import City, Country 4 5class TestGeoRSS1(feeds.Feed): 6 link = '/city/' 7 title = 'Test GeoDjango Cities' 8 9 def items(self): 10 return City.objects.all() 11 12 def item_link(self, item): 13 return '/city/%s/' % item.pk 14 15 def item_geometry(self, item): 16 return item.point 17 18class TestGeoRSS2(TestGeoRSS1): 19 def geometry(self, obj): 20 # This should attach a <georss:box> element for the extent of 21 # of the cities in the database. This tuple came from 22 # calling `City.objects.extent()` -- we can't do that call here 23 # because `extent` is not implemented for MySQL/Oracle. 24 return (-123.30, -41.32, 174.78, 48.46) 25 26 def item_geometry(self, item): 27 # Returning a simple tuple for the geometry. 28 return item.point.x, item.point.y 29 30class TestGeoAtom1(TestGeoRSS1): 31 feed_type = feeds.GeoAtom1Feed 32 33class TestGeoAtom2(TestGeoRSS2): 34 feed_type = feeds.GeoAtom1Feed 35 36 def geometry(self, obj): 37 # This time we'll use a 2-tuple of coordinates for the box. 38 return ((-123.30, -41.32), (174.78, 48.46)) 39 40class TestW3CGeo1(TestGeoRSS1): 41 feed_type = feeds.W3CGeoFeed 42 43# The following feeds are invalid, and will raise exceptions. 44class TestW3CGeo2(TestGeoRSS2): 45 feed_type = feeds.W3CGeoFeed 46 47class TestW3CGeo3(TestGeoRSS1): 48 feed_type = feeds.W3CGeoFeed 49 50 def item_geometry(self, item): 51 from django.contrib.gis.geos import Polygon 52 return Polygon(((0, 0), (0, 1), (1, 1), (1, 0), (0, 0))) 53 54# The feed dictionary to use for URLs. 55feed_dict = { 56 'rss1' : TestGeoRSS1, 57 'rss2' : TestGeoRSS2, 58 'atom1' : TestGeoAtom1, 59 'atom2' : TestGeoAtom2, 60 'w3cgeo1' : TestW3CGeo1, 61 'w3cgeo2' : TestW3CGeo2, 62 'w3cgeo3' : TestW3CGeo3, 63}