Code

Opened 6 years ago

Closed 6 years ago

Last modified 3 years ago

#6547 closed (fixed)

Support GeoRSS in syndication of Geographic Models

Reported by: jbronn Owned by: jbronn
Component: GIS Version: gis
Severity: Keywords: gis georss feed rss
Cc: jbronn@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description (last modified by jbronn)

There should be a django.contrib.gis.syndication module, that will contain a subclass of Feed, that will include GeoRSS information for geographic models.

GeoRSS support for Django was discussed earlier in django-users. The solution should be simple, and be familiar to those who have used Django's syndication feeds -- in other words, keep the API consistent with what Django already has. See also [browser:django/trunk/django/utils/feedgenerator.py].

Attachments (4)

georss_syndication_patch.diff (12.4 KB) - added by jbronn 6 years ago.
Patch for GeoRSS; also includes some internal changes to Feed
georss_syndication_patch_v2.diff (13.0 KB) - added by jbronn 6 years ago.
Version 2; uses W3C Geo for RSS points.
georss_syndication_patch_v3.diff (15.0 KB) - added by jbronn 6 years ago.
W3C Geo is no longer default for points on RSS feeds, but is now its own subclass.
georss_syndication_patch_v4.diff (7.3 KB) - added by jbronn 6 years ago.
Less intrusive patch to contrib.syndication.

Download all attachments as: .zip

Change History (17)

comment:1 Changed 6 years ago by jbronn

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 6 years ago by jbronn

  • Description modified (diff)

comment:3 Changed 6 years ago by hanne.moa@…

There's no need to limit this to only GeoDjango. All that's needed is to add item_location to the base SyndicationFeed that adds a location (tuple?) to item, then change the syndictation-types to spit out a <georss:point>-line if item has a location.

Then pepole would override item_location in the exact same way they already do for links, authors, categories etc.

Now if growing feeds by adding extra xml-tags becomes common, there should probably be a generic way of adding such tags, especially if they are as undemanding as georss.

comment:4 Changed 6 years ago by jbronn

  • milestone set to 1.0 beta
  • Status changed from new to assigned

comment:5 Changed 6 years ago by rcoup

I looked at this a bit tonight (because I want to generate some GeoRSS feeds)... comments are below. Mostly referring to Atom but similar concepts apply to RSS - noted in (brackets):

  • creating a subclass of django.contrib.syndication.feeds.Feed with item_location and location parameters won't be a problem to extract a geometry field from a model
  • the problem comes with respect to django.utils.feedgenerator.SyndicationFeed:
    • we want to add a <georss:where> clause to the feed(channel), each entry(item), or both.
    • we need to add the georss namespace declaration to <feed> (<channel>)
    • there are no hooks for extending either the feed or the entry, which means we'd have to reimplement/duplicate the entire write() and write_items() for each feed format. :(

Ok, so that's not gonna happen.

Extensions I think should be added to SyndicationFeed & its implementations to allow us to GeoRSS-ify stuff:

  • SyndicationFeed.__init__() and SyndicationFeed.add_item() should take kwargs which are added into the feed/item dictionaries respectively.
  • extra_attrs(): Add attributes to the root feed(channel) element. eg. xmlns:georss="http://...". Returns a dictionary. Called from write()
  • extras(handler): Add elements within the feed(channel) element. eg. a <georss:where> for the feed. Called from write()
  • item_extra_attrs(item): Add attributes to the entry(item) elements (called once for each item). Returns a dictionary. Called from write_items()
  • item_extras(handler, item): Add elements within the entry(item) elements (called once for each item). Would be where the georss would be added. Called from write_items()

Once we have those hooks we can do a mixin with each of the existing SyndicationFeed implementations and a GeoRSS implementation that knows how to turn a geometry object into a suitable GeoRSS clause. It would not just do georss then, but could also do media: or any other extensions. Thats quite a sizeable set of changes though, so I guess we need to bring it up on django-dev, and who knows whether it'll get through pre-1.0. I think those hooks make things much more flexible without needing to go to the lengths of rewriting the whole framework.

See also:

Probably should be another ticket, but I thought i'd get some initial feedback first.

comment:6 Changed 6 years ago by jacob

(In [8310]) Added a couple of extra syndication tests, and generally sanitized the existing ones. Refs #6547.

comment:7 Changed 6 years ago by jacob

(In [8311]) Added a number of callbacks to SyndicationFeed for adding custom attributes and elements to feeds. Refs #6547.

comment:8 Changed 6 years ago by jacob

OK, Justin, it's all you now.

comment:9 Changed 6 years ago by jacob

  • milestone changed from 1.0 beta to 1.0

Now that [8311] and [8331] are in, there's no reason this needs to block the beta.

comment:10 Changed 6 years ago by rcoup

Awesome Jacob, I'll work up a patch for the GeoRSS bit :)

Changed 6 years ago by jbronn

Patch for GeoRSS; also includes some internal changes to Feed

comment:11 Changed 6 years ago by jbronn

In my patch I added django.contrib.gis.feeds.Feed, which has support for simple GeoRSS. You may specify a geometry element on the entire feed by defining a geometry function; similarly, geometries in the feed may be specified by item_geometry method -- both should return a WGS84 (GEOS|OGR)Geometry.

Some big internal changes to the original Feed class, specifically abstracting a lot to the (now) subclassable get_feed_kwargs and get_item_kwargs methods. Tests pass, but I want some input on whether it's OK to make some of those variables class-wide (e.g., self.current_site, and the templates). This makes subclassing Feed easier, granting access to the __get_dynamic_attr magic.

Changed 6 years ago by jbronn

Version 2; uses W3C Geo for RSS points.

Changed 6 years ago by jbronn

W3C Geo is no longer default for points on RSS feeds, but is now its own subclass.

Changed 6 years ago by jbronn

Less intrusive patch to contrib.syndication.

comment:12 Changed 6 years ago by jbronn

  • Resolution set to fixed
  • Status changed from assigned to closed

(In [8414]) Fixed #6547, added support for GeoRSS feeds in django.contrib.gis.feeds; added the feed_extra_kwargs and item_extra_kwargs to the Feed baseclass so that it's possible for subclasses to add dynamic attributes.

comment:13 Changed 3 years ago by jacob

  • milestone 1.0 deleted

Milestone 1.0 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.