Skip to content

Commit

Permalink
[1463] Adds organization feeds by re-using a lot of the group feed bo…
Browse files Browse the repository at this point in the history
…ilerplate
  • Loading branch information
rossjones committed Jan 27, 2014
1 parent bb70fc5 commit f9e2880
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 24 deletions.
1 change: 1 addition & 0 deletions ckan/config/routing.py
Expand Up @@ -392,6 +392,7 @@ def make_map():
# feeds
with SubMapper(map, controller='feed') as m:
m.connect('/feeds/group/{id}.atom', action='group')
m.connect('/feeds/organization/{id}.atom', action='organization')
m.connect('/feeds/tag/{id}.atom', action='tag')
m.connect('/feeds/dataset.atom', action='general')
m.connect('/feeds/custom.atom', action='custom')
Expand Down
72 changes: 50 additions & 22 deletions ckan/controllers/feed.py
Expand Up @@ -166,45 +166,73 @@ def _alternate_url(self, params, **kwargs):
controller='package',
action='search')

def group(self, id):
try:
context = {'model': model, 'session': model.Session,
'user': c.user or c.author, 'auth_user_obj': c.userobj}
group_dict = logic.get_action('group_show')(context, {'id': id})
except logic.NotFound:
base.abort(404, _('Group not found'))
def _group_or_organization(self, obj_dict, is_org):

data_dict, params = self._parse_url_params()
data_dict['fq'] = 'groups:"%s"' % id
key = 'owner_org' if is_org else 'groups'
data_dict['fq'] = '%s:"%s"' % (key, obj_dict['id'],)
group_type = 'organization' if is_org else 'group'

item_count, results = _package_search(data_dict)

navigation_urls = self._navigation_urls(params,
item_count=item_count,
limit=data_dict['rows'],
controller='feed',
action='group',
id=id)

action=group_type,
id=obj_dict['name'])
feed_url = self._feed_url(params,
controller='feed',
action='group',
id=id)

alternate_url = self._alternate_url(params, groups=id)
action=group_type,
id=obj_dict['name'])

guid = _create_atom_id(u'/feeds/group/%s.atom' %
obj_dict['name'])
alternate_url = self._alternate_url(params, groups=obj_dict['name'])
desc = u'Recently created or updated datasets on %s by group: "%s"' %\
(g.site_title, obj_dict['title'])
title = u'%s - Group: "%s"' %\
(g.site_title, obj_dict['title'])

if is_org:
guid = _create_atom_id(u'/feeds/organization/%s.atom' %
obj_dict['name'])
alternate_url = self._alternate_url(params,
organization=obj_dict['name'])
desc = u'Recently created or updated datasets on %s '\
'by organization: "%s"' % (g.site_title, obj_dict['title'])
title = u'%s - Organization: "%s"' %\
(g.site_title, obj_dict['title'])

return self.output_feed(results,
feed_title=u'%s - Group: "%s"' %
(g.site_title, group_dict['title']),
feed_description=u'Recently created or '
'updated datasets on %s by group: "%s"' %
(g.site_title, group_dict['title']),
feed_title=title,
feed_description=desc,
feed_link=alternate_url,
feed_guid=_create_atom_id
(u'/feeds/groups/%s.atom' % id),
feed_guid=guid,
feed_url=feed_url,
navigation_urls=navigation_urls)

def group(self, id):
try:
context = {'model': model, 'session': model.Session,
'user': c.user or c.author, 'auth_user_obj': c.userobj}
group_dict = logic.get_action('group_show')(context, {'id': id})
except logic.NotFound:
base.abort(404, _('Group not found'))

return self._group_or_organization(group_dict, is_org=False)

def organization(self, id):
try:
context = {'model': model, 'session': model.Session,
'user': c.user or c.author, 'auth_user_obj': c.userobj}
group_dict = logic.get_action('organization_show')(context,
{'id': id})
except logic.NotFound:
base.abort(404, _('Organization not found'))

return self._group_or_organization(group_dict, is_org=True)

def tag(self, id):
data_dict, params = self._parse_url_params()
data_dict['fq'] = 'tags:"%s"' % id
Expand Down
4 changes: 2 additions & 2 deletions ckan/templates/organization/snippets/feeds.html
@@ -1,4 +1,4 @@
{%- set dataset_feed = h.url(controller='feed', action='group', id=c.group_dict.name) -%}
{%- set dataset_feed = h.url(controller='feed', action='organization', id=c.group_dict.name) -%}
{%- set history_feed = h.url(controller='revision', action='list', format='atom', days=1) -%}
<link rel="alternate" type="application/atom+xml" title="{{ g.site_title }} - {{ _('Datasets in group: {group}').format(group=c.group_dict.display_name) }}" href="{{ dataset_feed }}" />
<link rel="alternate" type="application/atom+xml" title="{{ g.site_title }} - {{ _('Datasets in organization: {group}').format(group=c.group_dict.display_name) }}" href="{{ dataset_feed }}" />
<link rel="alternate" type="application/atom+xml" title="{{ g.site_title }} - {{ _('Recent Revision History') }}" href="{{ history_feed }}" />

0 comments on commit f9e2880

Please sign in to comment.