Skip to content

Commit

Permalink
Merge branch 'feature-2579-sort-functions-to-helpers' into feature-23…
Browse files Browse the repository at this point in the history
…75-demo-theme

Conflicts:
	ckan/controllers/group.py
fix function clash trivial
	ckan/controllers/package.py
fix function clash trivial
	ckan/lib/helpers.py
fix function clash trivial
  • Loading branch information
tobes committed Jun 21, 2012
2 parents 374887a + eabd99d commit 59f2d1a
Show file tree
Hide file tree
Showing 15 changed files with 165 additions and 142 deletions.
23 changes: 6 additions & 17 deletions ckan/controllers/group.py
Expand Up @@ -147,27 +147,16 @@ def search_url(params):
return url + u'?' + urlencode(params)

def drill_down_url(**by):
params = list(params_nopage)
params.extend(by.items())
return search_url(set(params))
return h.drill_down_url(alternative_url=None,
controller='group', action='read',
id=c.group_dict.get('name'), **by)

c.drill_down_url = drill_down_url

def remove_field(key, value=None, replace=None):
"""
Remove a key from the current search parameters. A specific
key/value pair can be removed by passing a second value argument
otherwise all pairs matching the key will be removed.
If replace is given then a new param key=replace will be added.
"""
params = list(params_nopage)
if value:
params.remove((key, value))
else:
[params.remove((k, v)) for (k, v) in params[:] if k==key]
if replace is not None:
params.append((key, replace))
return search_url(params)
return h.remove_field(key, value=value, replace=replace,
controller='group', action='read',
id=c.group_dict.get('name'))

c.remove_field = remove_field

Expand Down
56 changes: 8 additions & 48 deletions ckan/controllers/package.py
Expand Up @@ -94,14 +94,6 @@ def _guess_package_type(self, expecting_name=False):

return pt

def _setup_follow_button(self, context):
'''Setup some template context variables used for the Follow button.'''

# If the user is logged in set the am_following variable.
if c.user:
c.pkg_dict['am_following'] = get_action('am_following_dataset')(
context, {'id': c.pkg.id})

authorizer = ckan.authz.Authorizer()

def search(self):
Expand All @@ -127,34 +119,20 @@ def search(self):
params_nopage = [(k, v) for k,v in request.params.items() if k != 'page']

def drill_down_url(alternative_url=None, **by):
params = set(params_nopage)
params |= set(by.items())
if alternative_url:
return url_with_params(alternative_url, params)
return search_url(params)
return h.drill_down_url(alternative_url=alternative_url,
controller='package', action='search', **by)

c.drill_down_url = drill_down_url

def remove_field(key, value=None, replace=None):
"""
Remove a key from the current search parameters. A specific
key/value pair can be removed by passing a second value argument
otherwise all pairs matching the key will be removed.
If replace is given then a new param key=replace will be added.
"""
params = list(params_nopage)
if value:
params.remove((key, value))
else:
[params.remove((k, v)) for (k, v) in params[:] if k==key]
if replace is not None:
params.append((key, replace))
return search_url(params)
return h.remove_field(key, value=value, replace=replace,
controller='package', action='search')

c.remove_field = remove_field

sort_by = request.params.get('sort', None)
params_nosort = [(k, v) for k,v in params_nopage if k != 'sort']

def _sort_by(fields):
"""
Sort by the given list of fields.
Expand All @@ -171,6 +149,7 @@ def _sort_by(fields):
sort_string = ', '.join( '%s %s' % f for f in fields )
params.append(('sort', sort_string))
return search_url(params)

c.sort_by = _sort_by
if sort_by is None:
c.sort_by_fields = []
Expand Down Expand Up @@ -320,10 +299,6 @@ def read(self, id, format='html'):
get_action('package_activity_list_html')(context,
{'id': c.current_package_id})

c.num_followers = get_action('dataset_follower_count')(context,
{'id':c.pkg.id})
self._setup_follow_button(context)

PackageSaver().render_package(c.pkg_dict, context)

template = self._read_template( package_type )
Expand Down Expand Up @@ -387,10 +362,6 @@ def history(self, id):
except NotFound:
abort(404, _('Dataset not found'))

c.num_followers = get_action('dataset_follower_count')(
context, {'id':c.pkg.id})
self._setup_follow_button(context)

format = request.params.get('format', '')
if format == 'atom':
# Generate and return Atom 1.0 document.
Expand Down Expand Up @@ -537,10 +508,6 @@ def edit(self, id, data=None, errors=None, error_summary=None):
else:
c.form = render(self._package_form(package_type=package_type), extra_vars=vars)

c.num_followers = get_action('dataset_follower_count')(context,
{'id':c.pkg.id})
self._setup_follow_button(context)

if (c.action == u'editresources'):
return render('package/editresources.html')
else:
Expand Down Expand Up @@ -668,6 +635,8 @@ def _save_new(self, context, package_type=None):

def _save_edit(self, name_or_id, context):
from ckan.lib.search import SearchIndexError
log.debug('Package save request name: %s POST: %r',
name_or_id, request.POST)
try:
data_dict = clean_dict(unflatten(
tuplize_dict(parse_params(request.POST))))
Expand Down Expand Up @@ -741,10 +710,6 @@ def authz(self, id):
roles = self._handle_update_of_authz(pkg)
self._prepare_authz_info_for_render(roles)

c.num_followers = get_action('dataset_follower_count')(context,
{'id':c.pkg.id})
self._setup_follow_button(context)

# c.related_count = len(pkg.related)

return render('package/authz.html')
Expand Down Expand Up @@ -833,9 +798,6 @@ def resource_read(self, id, resource_id):
qualified=True)

c.related_count = len(c.pkg.related)
c.num_followers = get_action('dataset_follower_count')(context,
{'id':c.pkg.id})
self._setup_follow_button(context)
return render('package/resource_read.html')

def resource_download(self, id, resource_id):
Expand Down Expand Up @@ -867,8 +829,6 @@ def followers(self, id=None):
c.pkg = context['package']
c.followers = get_action('dataset_follower_list')(context,
{'id': c.pkg_dict['id']})
c.num_followers = len(c.followers)
self._setup_follow_button(context)

c.related_count = len(c.pkg.related)
except NotFound:
Expand Down
7 changes: 0 additions & 7 deletions ckan/controllers/related.py
Expand Up @@ -43,13 +43,6 @@ def list(self, id):

c.related_count = len(c.pkg.related)

c.num_followers = logic.get_action('dataset_follower_count')(context,
{'id': c.pkg_dict['id']})
# If the user is logged in set the am_following variable.
if c.user:
c.pkg_dict['am_following'] = logic.get_action('am_following_dataset')(
context, {'id': c.pkg.id})

return base.render( "package/related_list.html")


Expand Down
19 changes: 0 additions & 19 deletions ckan/controllers/user.py
Expand Up @@ -46,22 +46,6 @@ def _db_to_edit_form_schema(self):
'''This is an interface to manipulate data from the database
into a format suitable for the form (optional)'''

def _setup_follow_button(self, context):
'''Setup some template context variables needed for the Follow/Unfollow
button.
'''

# If the user is logged in set the am_following variable.
userid = context.get('user')
if not userid:
return
userobj = model.User.get(userid)
if not userobj:
return
c.user_dict['am_following'] = get_action('am_following_user')(context,
{'id': c.user_dict['id']})

def _setup_template_variables(self, context, data_dict):
c.is_sysadmin = Authorizer().is_sysadmin(c.user)
try:
Expand All @@ -72,9 +56,6 @@ def _setup_template_variables(self, context, data_dict):
abort(401, _('Not authorized to see this page'))
c.user_dict = user_dict
c.is_myself = user_dict['name'] == c.user
c.num_followers = get_action('user_follower_count')(context,
{'id':c.user_dict['id']})
self._setup_follow_button(context)

## end hooks

Expand Down
6 changes: 6 additions & 0 deletions ckan/lib/authenticator.py
@@ -1,8 +1,12 @@
import logging

from zope.interface import implements
from repoze.who.interfaces import IAuthenticator

from ckan.model import User, Session

log = logging.getLogger(__name__)

class OpenIDAuthenticator(object):
implements(IAuthenticator)

Expand All @@ -25,8 +29,10 @@ def authenticate(self, environ, identity):
return None
user = User.by_name(identity.get('login'))
if user is None:
log.debug('Login failed - username %r not found', identity.get('login'))
return None
if user.validate_password(identity.get('password')):
return user.name
log.debug('Login as %r failed - password not valid', identity.get('login'))
return None

3 changes: 3 additions & 0 deletions ckan/lib/base.py
Expand Up @@ -31,6 +31,8 @@
from ckan.lib.helpers import json
import ckan.model as model

log = logging.getLogger(__name__)

PAGINATE_ITEMS_PER_PAGE = 50

APIKEY_HEADER_NAME_KEY = 'apikey_header_name'
Expand Down Expand Up @@ -176,6 +178,7 @@ def render_template():
response.headers["Cache-Control"] = "private"
# Prevent any further rendering from being cached.
request.environ['__no_cache__'] = True
log.debug('Template cache-control: %s' % response.headers["Cache-Control"])

# Render Time :)
try:
Expand Down
2 changes: 2 additions & 0 deletions ckan/lib/create_test_data.py
Expand Up @@ -511,6 +511,7 @@ def create(cls, auth_profile="", package_type=None):

model.repo.commit_and_remove()

# method used in DGU and all good tests elsewhere
@classmethod
def create_users(cls, user_dicts):
needs_commit = False
Expand All @@ -537,6 +538,7 @@ def _create_user_without_commit(cls, name='', **user_dict):
user = model.User(name=unicode(name), **user_dict)
model.Session.add(user)
cls.user_refs.append(user_ref)
return user

@classmethod
def create_user(cls, name='', **kwargs):
Expand Down

0 comments on commit 59f2d1a

Please sign in to comment.