|
1 from django.contrib.gis import feeds |
|
2 from django.contrib.gis.tests.utils import mysql |
|
3 from models import City, Country |
|
4 |
|
5 class 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 |
|
18 class 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 |
|
30 class TestGeoAtom1(TestGeoRSS1): |
|
31 feed_type = feeds.GeoAtom1Feed |
|
32 |
|
33 class 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 |
|
40 class TestW3CGeo1(TestGeoRSS1): |
|
41 feed_type = feeds.W3CGeoFeed |
|
42 |
|
43 # The following feeds are invalid, and will raise exceptions. |
|
44 class TestW3CGeo2(TestGeoRSS2): |
|
45 feed_type = feeds.W3CGeoFeed |
|
46 |
|
47 class 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. |
|
55 feed_dict = { |
|
56 'rss1' : TestGeoRSS1, |
|
57 'rss2' : TestGeoRSS2, |
|
58 'atom1' : TestGeoAtom1, |
|
59 'atom2' : TestGeoAtom2, |
|
60 'w3cgeo1' : TestW3CGeo1, |
|
61 'w3cgeo2' : TestW3CGeo2, |
|
62 'w3cgeo3' : TestW3CGeo3, |
|
63 } |