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