Skip to content

Commit

Permalink
[#3005] Add group follow, unfollow and followers pages
Browse files Browse the repository at this point in the history
These are not properly integrated into the frontend yet: no
follow/unfollow buttons on the group pages, no link to group followers
page, group followers page does not look right. But they work.
  • Loading branch information
Sean Hammond committed Oct 24, 2012
1 parent e55ca20 commit bc3ac6a
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
5 changes: 4 additions & 1 deletion ckan/config/routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,10 @@ def make_map():
'edit',
'authz',
'delete',
'history'
'history',
'followers',
'follow',
'unfollow',
]))
)
m.connect('group_read', '/group/{id}', action='read')
Expand Down
50 changes: 50 additions & 0 deletions ckan/controllers/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,56 @@ def history(self, id):
return feed.writeString('utf-8')
return render(self._history_template(c.group_dict['type']))

def follow(self, id):
'''Start following this group.'''
context = {'model': model,
'session': model.Session,
'user': c.user or c.author}
data_dict = {'id': id}
try:
get_action('follow_group')(context, data_dict)
h.flash_success(_("You are now following {0}").format(id))
except ValidationError as e:
error_message = (e.extra_msg or e.message or e.error_summary
or e.error_dict)
h.flash_error(error_message)
except NotAuthorized as e:
h.flash_error(e.extra_msg)
h.redirect_to(controller='group', action='read', id=id)

def unfollow(self, id):
'''Stop following this group.'''
context = {'model': model,
'session': model.Session,
'user': c.user or c.author}
data_dict = {'id': id}
try:
get_action('unfollow_group')(context, data_dict)
h.flash_success(_("You are no longer following {0}").format(id))
except ValidationError as e:
error_message = (e.extra_msg or e.message or e.error_summary
or e.error_dict)
h.flash_error(error_message)
except (NotFound, NotAuthorized) as e:
error_message = e.extra_msg or e.message
h.flash_error(error_message)
h.redirect_to(controller='group', action='read', id=id)

def followers(self, id=None):
context = {'model': model, 'session': model.Session,
'user': c.user or c.author, 'for_view': True}
data_dict = {'id': id}
try:
c.group_dict = get_action('group_show')(context, data_dict)
c.followers = get_action('group_follower_list')(context,
{'id': c.group_dict['id']})
except NotFound:
abort(404, _('Group not found'))
except NotAuthorized:
abort(401, _('Unauthorized to read group %s') % id)

return render('group/followers.html')

def _render_edit_form(self, fs):
# errors arrive in c.error and fs.errors
c.fieldset = fs
Expand Down
10 changes: 10 additions & 0 deletions ckan/templates/group/followers.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% extends "page.html" %}

{% block subtitle %}{{ _('Followers') }} - {{ c.group_dict.title or c.group_dict.name }}{% endblock %}

{% block primary_content %}
<section class="module-content">
<h1 class="hide-heading">{{ _('Followers') }}</h1>
{% snippet "user/snippets/followers.html", followers=c.followers %}
</section>
{% endblock %}

0 comments on commit bc3ac6a

Please sign in to comment.