Skip to content

Commit

Permalink
Merge branch 'master' into 2733-feature-datastore
Browse files Browse the repository at this point in the history
  • Loading branch information
rufuspollock committed Aug 14, 2012
2 parents b8eb66d + ef5e4a0 commit c09fc64
Show file tree
Hide file tree
Showing 183 changed files with 69,636 additions and 31,004 deletions.
2 changes: 1 addition & 1 deletion .tx/config
@@ -1,7 +1,7 @@
[main]
host = http://www.transifex.net

[ckan.1-7]
[ckan.1-8]
file_filter = ckan/i18n/<lang>/LC_MESSAGES/ckan.po
source_file = ckan/i18n/ckan.pot
source_lang = en
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.txt
Expand Up @@ -30,6 +30,7 @@ v1.8
available by `setting ckan.restrict_template_vars = false` in your
.ini config file. Only restricted functions will be allowed in
future versions of CKAN.
* [#2842] Allow sort ordering of dataset listings on group pages

API changes and deprecation:
* [#2313] Deprecated functions related to the old faceting data structure have
Expand Down
2 changes: 1 addition & 1 deletion ckan/__init__.py
@@ -1,4 +1,4 @@
__version__ = '1.8a'
__version__ = '1.8b'
__description__ = 'Comprehensive Knowledge Archive Network (CKAN) Software'
__long_description__ = \
'''CKAN software provides a hub for datasets. The flagship site running CKAN
Expand Down
3 changes: 2 additions & 1 deletion ckan/config/routing.py
Expand Up @@ -159,7 +159,8 @@ def make_map():

with SubMapper(map, controller='related') as m:
m.connect('related_list', '/dataset/{id}/related', action='list')
m.connect('related_read', '/dataset/{id}/related/{related_id}', action='read')
m.connect('related_read', '/apps/{id}', action='read')
m.connect('related_dashboard', '/apps', action='dashboard')

with SubMapper(map, controller='package') as m:
m.connect('/dataset', action='search')
Expand Down
13 changes: 9 additions & 4 deletions ckan/controllers/group.py
Expand Up @@ -34,7 +34,7 @@ def _form_to_db_schema(self, group_type=None):
def _db_to_form_schema(self, group_type=None):
'''This is an interface to manipulate data from the database
into a format suitable for the form (optional)'''
return lookup_group_plugin(group_type).form_to_db_schema()
return lookup_group_plugin(group_type).db_to_form_schema()

def _setup_template_variables(self, context, data_dict, group_type=None):
return lookup_group_plugin(group_type).\
Expand Down Expand Up @@ -100,8 +100,8 @@ def read(self, id):
group_type = self._get_group_type(id.split('@')[0])
context = {'model': model, 'session': model.Session,
'user': c.user or c.author,
'schema': self._form_to_db_schema(group_type=group_type),
'for_view': True}
'schema': self._db_to_form_schema(group_type=group_type),
'for_view': True, 'extras_as_string': True}
data_dict = {'id': id}
# unicode format (decoded from utf8)
q = c.q = request.params.get('q', '')
Expand Down Expand Up @@ -139,6 +139,7 @@ def read(self, id):
# most search operations should reset the page counter:
params_nopage = [(k, v) for k, v in request.params.items()
if k != 'page']
sort_by = request.params.get('sort', None)

def search_url(params):
url = h.url_for(controller='group', action='read',
Expand Down Expand Up @@ -170,7 +171,7 @@ def pager_url(q=None, page=None):
c.fields = []
search_extras = {}
for (param, value) in request.params.items():
if not param in ['q', 'page'] \
if not param in ['q', 'page', 'sort'] \
and len(value) and not param.startswith('_'):
if not param.startswith('ext_'):
c.fields.append((param, value))
Expand All @@ -188,6 +189,7 @@ def pager_url(q=None, page=None):
'fq': fq,
'facet.field': g.facets,
'rows': limit,
'sort': sort_by,
'start': (page - 1) * limit,
'extras': search_extras
}
Expand All @@ -209,6 +211,9 @@ def pager_url(q=None, page=None):

c.search_facets = query['search_facets']
c.page.items = query['results']

c.sort_by_selected = sort_by

except SearchError, se:
log.error('Group search error: %r', se.args)
c.query_error = True
Expand Down
10 changes: 5 additions & 5 deletions ckan/controllers/package.py
Expand Up @@ -305,7 +305,7 @@ def read(self, id, format='html'):

# used by disqus plugin
c.current_package_id = c.pkg.id
c.related_count = len(c.pkg.related)
c.related_count = c.pkg.related_count

# Add the package's activity stream (already rendered to HTML) to the
# template context for the package/read.html template to retrieve
Expand Down Expand Up @@ -420,7 +420,7 @@ def history(self, id):
feed.content_type = 'application/atom+xml'
return feed.writeString('utf-8')

c.related_count = len(c.pkg.related)
c.related_count = c.pkg.related_count
return render(self._history_template(c.pkg_dict.get('type',
package_type)))

Expand Down Expand Up @@ -499,7 +499,7 @@ def edit(self, id, data=None, errors=None, error_summary=None):

self._setup_template_variables(context, {'id': id},
package_type=package_type)
c.related_count = len(c.pkg.related)
c.related_count = c.pkg.related_count

# TODO: This check is to maintain backwards compatibility with the
# old way of creating custom forms. This behaviour is now deprecated.
Expand Down Expand Up @@ -791,7 +791,7 @@ def resource_read(self, id, resource_id):
c.datastore_api = h.url_for('datastore_read', id=c.resource.get('id'),
qualified=True)

c.related_count = len(c.pkg.related)
c.related_count = c.pkg.related_count
return render('package/resource_read.html')

def resource_download(self, id, resource_id):
Expand Down Expand Up @@ -824,7 +824,7 @@ def followers(self, id=None):
c.followers = get_action('dataset_follower_list')(context,
{'id': c.pkg_dict['id']})

c.related_count = len(c.pkg.related)
c.related_count = c.pkg.related_count
except NotFound:
abort(404, _('Dataset not found'))
except NotAuthorized:
Expand Down
80 changes: 77 additions & 3 deletions ckan/controllers/related.py
Expand Up @@ -4,14 +4,86 @@
import ckan.logic as logic
import ckan.lib.base as base
import ckan.lib.helpers as h
import urllib

c = base.c
_get_action=logic.get_action


class RelatedController(base.BaseController):

def list(self, id):
def dashboard(self):
""" List all related items regardless of dataset """
context = {'model': model, 'session': model.Session,
'user': c.user or c.author, 'extras_as_string': True,
'for_view': True}
data_dict = {
'type_filter': base.request.params.get('type', ''),
'sort': base.request.params.get('sort', ''),
'featured': base.request.params.get('featured', '')
}

params_nopage = [(k, v) for k,v in base.request.params.items()
if k != 'page']
try:
page = int(base.request.params.get('page', 1))
except ValueError, e:
abort(400, ('"page" parameter must be an integer'))

# Update ordering in the context
query = logic.get_action('related_list')(context,data_dict)

def search_url(params):
url = h.url_for(controller='related', action='dashboard')
params = [(k, v.encode('utf-8')
if isinstance(v, basestring) else str(v))
for k, v in params]
return url + u'?' + urllib.urlencode(params)

def pager_url(q=None, page=None):
params = list(params_nopage)
params.append(('page', page))
return search_url(params)


c.page = h.Page(
collection=query.all(),
page=page,
url=pager_url,
item_count=query.count(),
items_per_page=8
)

c.filters = dict(params_nopage)

return base.render( "related/dashboard.html")

def read(self, id):
context = {'model': model, 'session': model.Session,
'user': c.user or c.author, 'extras_as_string': True,
'for_view': True}
data_dict = {'id': id}

try:
logic.check_access('related_show', context, data_dict)
except logic.NotAuthorized:
abort(401, _('Not authorized to see this page'))

related = model.Session.query(model.Related).\
filter(model.Related.id == id).first()
if not related:
abort(404, _('The requested related item was not found'))

related.view_count = model.Related.view_count + 1

model.Session.add(related)
model.Session.commit()

base.redirect(related.url)


def list(self, id):
""" List all related items for a specific dataset """
context = {'model': model, 'session': model.Session,
'user': c.user or c.author, 'extras_as_string': True,
'for_view': True}
Expand All @@ -33,6 +105,8 @@ def list(self, id):
except logic.NotAuthorized:
base.abort(401, base._('Unauthorized to read package %s') % id)

c.related_count = len(c.pkg.related)
c.action = 'related'
return base.render("package/related_list.html")
c.related_count = c.pkg.related_count
c.num_followers = _get_action('dataset_follower_count')(context,
{'id':c.pkg.id})
return base.render( "related/related_list.html")
3 changes: 3 additions & 0 deletions ckan/controllers/storage.py
Expand Up @@ -269,6 +269,9 @@ def get_metadata(self, label):
label=label,
qualified=False
)
if url.startswith('/'):
url = config.get('ckan.site_url','').rstrip('/') + '/' + url

if not self.ofs.exists(bucket, label):
abort(404)
metadata = self.ofs.get_metadata(bucket, label)
Expand Down
10 changes: 9 additions & 1 deletion ckan/controllers/user.py
Expand Up @@ -106,6 +106,8 @@ def read(self, id=None):
except NotAuthorized:
abort(401, _('Not authorized to see this page'))

context['with_related'] = True

self._setup_template_variables(context, data_dict)

c.about_formatted = self._format_about(c.user_dict['about'])
Expand Down Expand Up @@ -382,12 +384,18 @@ def request_reset(self):

def perform_reset(self, id):
context = {'model': model, 'session': model.Session,
'user': c.user}
'user': c.user,
'keep_sensitive_data': True}

data_dict = {'id': id}

try:
user_dict = get_action('user_show')(context, data_dict)

# Be a little paranoid, and get rid of sensitive data that's
# not needed.
user_dict.pop('apikey', None)
user_dict.pop('reset_key', None)
user_obj = context['user_obj']
except NotFound, e:
abort(404, _('User not found'))
Expand Down
Binary file modified ckan/i18n/bg/LC_MESSAGES/ckan.mo
Binary file not shown.

0 comments on commit c09fc64

Please sign in to comment.