Skip to content

Commit

Permalink
Remove webhelpers based class
Browse files Browse the repository at this point in the history
  • Loading branch information
amercader committed Nov 28, 2019
1 parent 26a790c commit d1ef3fa
Showing 1 changed file with 1 addition and 73 deletions.
74 changes: 1 addition & 73 deletions ckan/views/feed.py
Expand Up @@ -8,7 +8,7 @@
from six import text_type
from dateutil.tz import tzutc
from feedgen.feed import FeedGenerator
from ckan.common import _, config, g, request, response
from ckan.common import _, config, g, request
import ckan.lib.helpers as h
import ckan.lib.base as base
import ckan.model as model
Expand Down Expand Up @@ -564,78 +564,6 @@ def _create_atom_id(resource_path, authority_name=None, date_string=None):
return u':'.join(['tag', tagging_entity, resource_path])


class _FixedAtom1Feed(webhelpers.feedgenerator.Atom1Feed):
"""
The Atom1Feed defined in webhelpers doesn't provide all the fields we
might want to publish.
* In Atom1Feed, each <entry> is created with identical <updated> and
<published> fields. See [1] (webhelpers 1.2) for details.
So, this class fixes that by allow an item to set both an <updated> and
<published> field.
* In Atom1Feed, the feed description is not used. So this class uses the
<subtitle> field to publish that.
[1] https://bitbucket.org/bbangert/webhelpers/src/f5867a319abf/\
webhelpers/feedgenerator.py#cl-373
"""

def add_item(self, *args, **kwargs):
"""
Drop the pubdate field from the new item.
"""
if u'pubdate' in kwargs:
kwargs.pop(u'pubdate')
defaults = {u'updated': None, u'published': None}
defaults.update(kwargs)
super(_FixedAtom1Feed, self).add_item(*args, **defaults)

def latest_post_date(self):
"""
Calculates the latest post date from the 'updated' fields,
rather than the 'pubdate' fields.
"""
updates = [
item['updated'] for item in self.items
if item['updated'] is not None
]
if not len(updates): # delegate to parent for default behaviour
return super(_FixedAtom1Feed, self).latest_post_date()
return max(updates)

def add_item_elements(self, handler, item):
"""
Add the <updated> and <published> fields to each entry that's written
to the handler.
"""
super(_FixedAtom1Feed, self).add_item_elements(handler, item)

dfunc = webhelpers.feedgenerator.rfc3339_date

if (item['updated']):
handler.addQuickElement(u'updated',
dfunc(item['updated']).decode(u'utf-8'))

if (item['published']):
handler.addQuickElement(u'published',
dfunc(item['published']).decode(u'utf-8'))

def add_root_elements(self, handler):
"""
Add additional feed fields.
* Add the <subtitle> field from the feed description
* Add links other pages of the logical feed.
"""
super(_FixedAtom1Feed, self).add_root_elements(handler)

handler.addQuickElement(u'subtitle', self.feed['description'])

for page in [u'previous', u'next', u'first', u'last']:
if self.feed.get(page + u'_page', None):
handler.addQuickElement(u'link', u'', {
u'rel': page,
u'href': self.feed.get(page + u'_page')
})


# Routing
feeds.add_url_rule(u'/dataset.atom', methods=[u'GET'], view_func=general)
feeds.add_url_rule(u'/custom.atom', methods=[u'GET'], view_func=custom)
Expand Down

0 comments on commit d1ef3fa

Please sign in to comment.