/django/contrib/gis/tests/geoapp/feeds.py

https://code.google.com/p/mango-py/ · Python · 63 lines · 41 code · 14 blank · 8 comment · 0 complexity · 65964f73beae99434f1c0515d36f84b0 MD5 · raw file

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