Skip to content

Commit

Permalink
[#638] PEP8
Browse files Browse the repository at this point in the history
  • Loading branch information
johnglover committed Mar 19, 2013
1 parent b293002 commit dce07c1
Showing 1 changed file with 30 additions and 33 deletions.
63 changes: 30 additions & 33 deletions ckan/controllers/group.py
Expand Up @@ -34,6 +34,7 @@

lookup_group_plugin = ckan.lib.plugins.lookup_group_plugin


class GroupController(base.BaseController):

group_type = 'group'
Expand All @@ -53,7 +54,7 @@ def _db_to_form_schema(self, group_type=None):

def _setup_template_variables(self, context, data_dict, group_type=None):
return lookup_group_plugin(group_type).\
setup_template_variables(context, data_dict)
setup_template_variables(context, data_dict)

def _new_template(self, group_type):
return lookup_group_plugin(group_type).new_template()
Expand Down Expand Up @@ -82,7 +83,6 @@ def _admins_template(self, group_type):
def _bulk_process_template(self, group_type):
return lookup_group_plugin(group_type).bulk_process_template()


## end hooks
def _replace_group_org(self, string):
''' substitute organization for group if this is an org'''
Expand Down Expand Up @@ -139,8 +139,7 @@ def index(self):
'with_private': False}

q = c.q = request.params.get('q', '')
data_dict = {'all_fields': True,
'q': q,}
data_dict = {'all_fields': True, 'q': q}
sort_by = c.sort_by_selected = request.params.get('sort')
if sort_by:
data_dict['sort'] = sort_by
Expand Down Expand Up @@ -201,7 +200,7 @@ def _read(self, id, limit):

try:
description_formatted = ckan.misc.MarkdownFormat().to_html(
c.group_dict.get('description', ''))
c.group_dict.get('description', ''))
c.description_formatted = genshi.HTML(description_formatted)
except Exception, e:
error_msg = "<span class='inline-warning'>%s</span>" %\
Expand Down Expand Up @@ -236,8 +235,7 @@ def search_url(params):
action='read',
id=id)
else:
url = self._url_for(controller='group', action='read',
id=id)
url = self._url_for(controller='group', action='read', id=id)
params = [(k, v.encode('utf-8') if isinstance(v, basestring)
else str(v)) for k, v in params]
return url + u'?' + urlencode(params)
Expand All @@ -252,8 +250,8 @@ def drill_down_url(**by):

def remove_field(key, value=None, replace=None):
return h.remove_url_param(key, value=value, replace=replace,
controller='group', action='read',
extras=dict(id=c.group_dict.get('name')))
controller='group', action='read',
extras=dict(id=c.group_dict.get('name')))

c.remove_field = remove_field

Expand Down Expand Up @@ -285,9 +283,9 @@ def pager_url(q=None, page=None):
facets = OrderedDict()

default_facet_titles = {'groups': _('Groups'),
'tags': _('Tags'),
'res_format': _('Formats'),
'license': _('Licence'), }
'tags': _('Tags'),
'res_format': _('Formats'),
'license': _('Licence')}

for facet in g.facets:
if facet in default_facet_titles:
Expand All @@ -304,7 +302,8 @@ def pager_url(q=None, page=None):
facets = plugin.group_facets(
facets, self.group_type, None)

if 'capacity' in facets and (self.group_type != 'organization' or not user_member_of_orgs):
if 'capacity' in facets and (self.group_type != 'organization' or
not user_member_of_orgs):
del facets['capacity']

c.facet_titles = facets
Expand All @@ -330,9 +329,8 @@ def pager_url(q=None, page=None):
)

c.facets = query['facets']
maintain.deprecate_context_item(
'facets',
'Use `c.search_facets` instead.')
maintain.deprecate_context_item('facets',
'Use `c.search_facets` instead.')

c.search_facets = query['search_facets']
c.search_facets_limits = {}
Expand All @@ -349,15 +347,13 @@ def pager_url(q=None, page=None):
c.facets = {}
c.page = h.Page(collection=[])



def bulk_process(self, id):
''' Allow bulk processing of datasets for an organization. Make
private/public or delete. For organization admins.'''

group_type = self._get_group_type(id.split('@')[0])

if group_type != 'organization':
if group_type != 'organization':
# FIXME: better error
raise Exception('Must be an organization')

Expand Down Expand Up @@ -387,7 +383,8 @@ def bulk_process(self, id):
c.packages = c.page.items
return render(self._bulk_process_template(group_type))

# process the action first find the datasets to perform the action on. they are prefixed by dataset_ in the form data
# process the action first find the datasets to perform the action on.
# they are prefixed by dataset_ in the form data
datasets = []
for param in request.params:
if param.startswith('dataset_'):
Expand All @@ -405,8 +402,9 @@ def bulk_process(self, id):
get_action(action_functions[action])(context, data_dict)
except NotAuthorized:
abort(401, _('Not authorized to perform bulk update'))
base.redirect(h.url_for(controller='organization', action='bulk_process',
id=id))
base.redirect(h.url_for(controller='organization',
action='bulk_process',
id=id))

def new(self, data=None, errors=None, error_summary=None):
group_type = self._guess_group_type(True)
Expand Down Expand Up @@ -559,7 +557,7 @@ def authz(self, id):
if not c.authz_editable:
abort(401,
_('User %r not authorized to edit %s authorizations') %
(c.user, id))
(c.user, id))

roles = self._handle_update_of_authz(group)
self._prepare_authz_info_for_render(roles)
Expand Down Expand Up @@ -597,8 +595,9 @@ def members(self, id):
'user': c.user or c.author}

try:
c.members = self._action('member_list')(context, {'id': id,
'object_type': 'user'})
c.members = self._action('member_list')(
context, {'id': id, 'object_type': 'user'}
)
c.group_dict = self._action('group_show')(context, {'id': id})
except NotAuthorized:
abort(401, _('Unauthorized to delete group %s') % '')
Expand Down Expand Up @@ -660,7 +659,6 @@ def member_delete(self, id):
abort(404, _('Group not found'))
return self._render_template('group/confirm_delete_member.html')


def history(self, id):
if 'diff' in request.params or 'selected1' in request.params:
try:
Expand All @@ -684,7 +682,7 @@ def history(self, id):
try:
c.group_dict = self._action('group_show')(context, data_dict)
c.group_revisions = self._action('group_revision_list')(context,
data_dict)
data_dict)
#TODO: remove
# Still necessary for the authz check in group/layout.html
c.group = context['group']
Expand All @@ -700,7 +698,7 @@ def history(self, id):
feed = Atom1Feed(
title=_(u'CKAN Group Revision History'),
link=self._url_for(controller='group', action='read',
id=c.group_dict['name']),
id=c.group_dict['name']),
description=_(u'Recent changes to CKAN Group: ') +
c.group_dict['display_name'],
language=unicode(get_lang()),
Expand Down Expand Up @@ -757,7 +755,7 @@ def activity(self, id, offset=0):
# Add the group's activity stream (already rendered to HTML) to the
# template context for the group/read.html template to retrieve later.
c.group_activity_stream = get_action('group_activity_list_html')(
context, {'id': c.group_dict['id'], 'offset': offset})
context, {'id': c.group_dict['id'], 'offset': offset})

#return render('group/activity_stream.html')
return render(self._activity_template(c.group_dict['type']))
Expand All @@ -775,7 +773,7 @@ def follow(self, id):
group_dict['title']))
except ValidationError as e:
error_message = (e.extra_msg or e.message or e.error_summary
or e.error_dict)
or e.error_dict)
h.flash_error(error_message)
except NotAuthorized as e:
h.flash_error(e.extra_msg)
Expand All @@ -794,7 +792,7 @@ def unfollow(self, id):
group_dict['title']))
except ValidationError as e:
error_message = (e.extra_msg or e.message or e.error_summary
or e.error_dict)
or e.error_dict)
h.flash_error(error_message)
except (NotFound, NotAuthorized) as e:
error_message = e.extra_msg or e.message
Expand All @@ -806,8 +804,7 @@ def followers(self, id):
'user': c.user or c.author}
c.group_dict = self._get_group_dict(id)
try:
c.followers = get_action('group_follower_list')(context,
{'id': id})
c.followers = get_action('group_follower_list')(context, {'id': id})
except NotAuthorized:
abort(401, _('Unauthorized to view followers %s') % '')
return render('group/followers.html')
Expand Down

0 comments on commit dce07c1

Please sign in to comment.