[ckan-changes] commit/ckan: 5 new changesets
Bitbucket
commits-noreply at bitbucket.org
Wed Jul 27 12:41:03 UTC 2011
5 new changesets in ckan:
http://bitbucket.org/okfn/ckan/changeset/383875edb88c/
changeset: 383875edb88c
branch: feature-1229-db-out-of-controllers
user: amercader
date: 2011-07-27 11:38:38
summary: [controllers] Fix bug in package history
affected #: 1 file (38 bytes)
--- a/ckan/controllers/package.py Tue Jul 26 17:46:37 2011 +0100
+++ b/ckan/controllers/package.py Wed Jul 27 10:38:38 2011 +0100
@@ -284,14 +284,12 @@
language=unicode(get_lang()),
)
for revision_dict in c.pkg_revisions:
+ revision_date = datetime.datetime.strptime(revision_dict['timestamp'], '%Y-%m-%dT%H:%M:%S.%f')
try:
dayHorizon = int(request.params.get('days'))
except:
dayHorizon = 30
- try:
- dayAge = (datetime.now() - revision_dict['timestamp']).days
- except:
- dayAge = 0
+ dayAge = (datetime.datetime.now() - revision_date).days
if dayAge >= dayHorizon:
break
if revision_dict['message']:
@@ -302,7 +300,7 @@
item_description = _('Log message: ')
item_description += '%s' % (revision_dict['message'] or '')
item_author_name = revision_dict['author']
- item_pubdate = datetime.datetime.strptime(revision_dict['timestamp'], '%Y-%m-%dT%H:%M:%S.%f')
+ item_pubdate = revision_date
feed.add_item(
title=item_title,
link=item_link,
http://bitbucket.org/okfn/ckan/changeset/79362a486b09/
changeset: 79362a486b09
branch: feature-1229-db-out-of-controllers
user: amercader
date: 2011-07-27 11:59:46
summary: [logic] Move group history. Authz at template level still uses domain objects
affected #: 3 files (1.1 KB)
--- a/ckan/controllers/group.py Wed Jul 27 10:38:38 2011 +0100
+++ b/ckan/controllers/group.py Wed Jul 27 10:59:46 2011 +0100
@@ -1,4 +1,5 @@
import genshi
+import datetime
from sqlalchemy.orm import eagerload_all
from ckan.lib.base import BaseController, c, model, request, render, h
@@ -397,12 +398,6 @@
c.authz_groups_role_dict = authz_groups_role_dict
return render('group/authz.html')
-
-
-
-
-
-
def history(self, id):
if 'diff' in request.params or 'selected1' in request.params:
@@ -419,10 +414,19 @@
params['diff_entity'] = 'group'
h.redirect_to(controller='revision', action='diff', **params)
- c.group = model.Group.get(id)
- if not c.group:
+ context = {'model': model, 'session': model.Session,
+ 'user': c.user or c.author,
+ 'schema': self._form_to_db_schema()}
+ data_dict = {'id': id}
+ try:
+ c.group_dict = get.group_show(context, data_dict)
+ c.group_revisions = get.group_revision_list(context, data_dict)
+ #TODO: remove
+ # Still necessary for the authz check in group/layout.html
+ c.group = context['group']
+ except NotFound:
abort(404, _('Group not found'))
- if not self.authorizer.am_authorized(c, model.Action.READ, c.group):
+ except NotAuthorized:
abort(401, _('User %r not authorized to edit %r') % (c.user, id))
format = request.params.get('format', '')
@@ -431,31 +435,29 @@
from webhelpers.feedgenerator import Atom1Feed
feed = Atom1Feed(
title=_(u'CKAN Group Revision History'),
- link=h.url_for(controller='group', action='read', id=c.group.name),
+ link=h.url_for(controller='group', action='read', id=c.group_dict['name']),
description=_(u'Recent changes to CKAN Group: ') +
- c.group.display_name,
+ c.group_dict['display_name'],
language=unicode(get_lang()),
)
- for revision, obj_rev in c.group.all_related_revisions:
+ for revision_dict in c.group_revisions:
+ revision_date = datetime.datetime.strptime(revision_dict['timestamp'], '%Y-%m-%dT%H:%M:%S.%f')
try:
dayHorizon = int(request.params.get('days'))
except:
dayHorizon = 30
- try:
- dayAge = (datetime.now() - revision.timestamp).days
- except:
- dayAge = 0
+ dayAge = (datetime.datetime.now() - revision_date).days
if dayAge >= dayHorizon:
break
- if revision.message:
- item_title = u'%s' % revision.message.split('\n')[0]
+ if revision_dict['message']:
+ item_title = u'%s' % revision_dict['message'].split('\n')[0]
else:
- item_title = u'%s' % revision.id
- item_link = h.url_for(controller='revision', action='read', id=revision.id)
+ item_title = u'%s' % revision_dict['id']
+ item_link = h.url_for(controller='revision', action='read', id=revision_dict['id'])
item_description = _('Log message: ')
- item_description += '%s' % (revision.message or '')
- item_author_name = revision.author
- item_pubdate = revision.timestamp
+ item_description += '%s' % (revision_dict['message'] or '')
+ item_author_name = revision_dict['author']
+ item_pubdate = revision_date
feed.add_item(
title=item_title,
link=item_link,
@@ -465,7 +467,6 @@
)
feed.content_type = 'application/atom+xml'
return feed.writeString('utf-8')
- c.group_revisions = c.group.all_related_revisions
return render('group/history.html')
def _render_edit_form(self, fs):
--- a/ckan/logic/action/get.py Wed Jul 27 10:38:38 2011 +0100
+++ b/ckan/logic/action/get.py Wed Jul 27 10:59:46 2011 +0100
@@ -132,6 +132,21 @@
return [(group.id, group.name) for group in groups]
+def group_revision_list(context, data_dict):
+ model = context['model']
+ id = data_dict['id']
+ group = model.Group.get(id)
+ if group is None:
+ raise NotFound
+ check_access(group, model.Action.READ, context)
+
+ revision_dicts = []
+ for revision, object_revisions in group.all_related_revisions:
+ revision_dicts.append(model.revision_as_dict(revision,
+ include_packages=False,
+ include_groups=False))
+ return revision_dicts
+
def licence_list(context, data_dict):
model = context["model"]
license_register = model.Package.get_license_register()
--- a/ckan/templates/group/history.html Wed Jul 27 10:38:38 2011 +0100
+++ b/ckan/templates/group/history.html Wed Jul 27 10:59:46 2011 +0100
@@ -2,19 +2,19 @@
xmlns:xi="http://www.w3.org/2001/XInclude"
py:strip="">
- <py:def function="page_title">${c.group.display_name} - Groups - History</py:def>
+ <py:def function="page_title">${c.group_dict['display_name']} - Groups - History</py:def><div py:match="content" class="group"><h2 class="head">
- ${c.group.display_name}
+ ${c.group_dict['display_name']}
</h2><h3>
Revisions
<p class="atom-feed-link group-history-link"><a
- href="${url(controller='group', action='history', id=c.group.name, format='atom', days=7)}"
- title="${g.site_title} - Group History - ${c.group.name}"
+ href="${url(controller='group', action='history', id=c.group_dict['name'], format='atom', days=7)}"
+ title="${g.site_title} - Group History - ${c.group_dict['name']}"
>
Subscribe »</a></p>
@@ -28,24 +28,24 @@
Error: ${c.error}
</h3>
- <input type="hidden" name="group_name" value="${c.group.name}"/>
+ <input type="hidden" name="group_name" value="${c.group_dict['name']}"/><table><tr><th></th><th>Revision</th><th>Timestamp</th><th>Author</th><th>Log Message</th></tr>
- <py:for each="index, rev in enumerate([rev for rev, obj_revs in c.group_revisions])">
+ <py:for each="index, revision_dict in enumerate(c.group_revisions)"><tr><td nowrap="nowrap">
- ${h.radio("selected1", rev.id, checked=(index == 0))}
- ${h.radio("selected2", rev.id, checked=(index == len(c.group_revisions)-1))}
+ ${h.radio("selected1", revision_dict['id'], checked=(index == 0))}
+ ${h.radio("selected2", revision_dict['id'], checked=(index == len(c.group_revisions)-1))}
</td><td>
- <a href="${h.url_for(controller='revision',action='read',id=rev.id)}">${rev.id}</a>
+ <a href="${h.url_for(controller='revision',action='read',id=revision_dict['id'])}">${revision_dict['id']}</a></td>
- <td>${rev.timestamp}</td>
- <td>${h.linked_user(rev.author)}</td>
- <td>${rev.message}</td>
+ <td>${revision_dict['timestamp']}</td>
+ <td>${h.linked_user(revision_dict['author'])}</td>
+ <td>${revision_dict['message']}</td></tr></py:for></table>
@@ -55,7 +55,7 @@
<py:def function="optional_feed"><link rel="alternate" type="application/atom+xml" title="Group History"
- href="${url(controller='group', action='history', id=c.group.name, format='atom', days=7)}" />
+ href="${url(controller='group', action='history', id=c.group_dict['name'], format='atom', days=7)}" /></py:def><xi:include href="layout.html" />
http://bitbucket.org/okfn/ckan/changeset/f9149542f56b/
changeset: f9149542f56b
branch: feature-1229-db-out-of-controllers
user: amercader
date: 2011-07-27 12:05:12
summary: Put package object in context, as is needed at template level to check authz
affected #: 1 file (137 bytes)
--- a/ckan/controllers/package.py Wed Jul 27 10:59:46 2011 +0100
+++ b/ckan/controllers/package.py Wed Jul 27 11:05:12 2011 +0100
@@ -268,6 +268,10 @@
try:
c.pkg_dict = get.package_show(context, data_dict)
c.pkg_revisions = get.package_revision_list(context, data_dict)
+ #TODO: remove
+ # Still necessary for the authz check in group/layout.html
+ c.pkg = context['package']
+
except NotAuthorized:
abort(401, _('Unauthorized to read package %s') % '')
except NotFound:
http://bitbucket.org/okfn/ckan/changeset/85e4bcf10754/
changeset: 85e4bcf10754
branch: feature-1229-db-out-of-controllers
user: amercader
date: 2011-07-27 13:38:44
summary: [logic] Move API tag_counts and tag_autocomplete
affected #: 3 files (2.1 KB)
--- a/ckan/controllers/api.py Wed Jul 27 11:05:12 2011 +0100
+++ b/ckan/controllers/api.py Wed Jul 27 12:38:44 2011 +0100
@@ -474,12 +474,18 @@
return params
def tag_counts(self, ver=None):
- log.debug('tag counts')
- tags = model.Session.query(model.Tag).all()
+ c.q = request.params.get('q', '')
+
+ context = {'model': model, 'session': model.Session,
+ 'user': c.user or c.author}
+
+ data_dict = {'all_fields': True}
+
+ tag_list = get.tag_list(context, data_dict)
results = []
- for tag in tags:
- tag_count = len(tag.package_tags)
- results.append((tag.name, tag_count))
+ for tag in tag_list:
+ tag_count = len(tag['packages'])
+ results.append((tag['name'], tag_count))
return self._finish_ok(results)
def throughput(self, ver=None):
@@ -555,26 +561,21 @@
return self._finish_ok(response_data)
def tag_autocomplete(self):
- incomplete = request.params.get('incomplete', '')
- if incomplete:
- query = query_for('tag', backend='sql')
- query.run(query=incomplete,
- return_objects=True,
- limit=10,
- username=c.user)
- tagNames = [t.name for t in query.results]
- else:
- tagNames = []
+ q = request.params.get('incomplete', '')
+ tag_names = []
+ if q:
+ context = {'model': model, 'session': model.Session,
+ 'user': c.user or c.author}
+
+ data_dict = {'q':q,'limit':10}
+
+ tag_names = get.tag_autocomplete(context,data_dict)
+
resultSet = {
- "ResultSet": {
- "Result": []
+ 'ResultSet': {
+ 'Result': [{'Name': tag} for tag in tag_names]
}
}
- for tagName in tagNames[:10]:
- result = {
- "Name": tagName
- }
- resultSet["ResultSet"]["Result"].append(result)
return self._finish_ok(resultSet)
--- a/ckan/logic/action/get.py Wed Jul 27 11:05:12 2011 +0100
+++ b/ckan/logic/action/get.py Wed Jul 27 12:38:44 2011 +0100
@@ -155,10 +155,13 @@
return licences
def tag_list(context, data_dict):
- '''Lists tags by name'''
+ '''Returns a list of tags'''
+
model = context['model']
user = context['user']
+ all_fields = data_dict.get('all_fields',None)
+
q = data_dict.get('q','')
if q:
limit = data_dict.get('limit',25)
@@ -173,9 +176,16 @@
username=user)
tags = query.results
else:
- tags = model.Session.query(model.Tag).all() #TODO
+ tags = model.Session.query(model.Tag).all()
+
+ tag_list = []
+ if all_fields:
+ for tag in tags:
+ result_dict = tag_dictize(tag, context)
+ tag_list.append(result_dict)
+ else:
+ tag_list = [tag.name for tag in tags]
- tag_list = [tag.name for tag in tags]
return tag_list
def user_list(context, data_dict):
@@ -421,6 +431,28 @@
return pkg_list
+def tag_autocomplete(context, data_dict):
+ '''Returns tags containing the provided string'''
+ model = context['model']
+ session = context['session']
+ user = context['user']
+
+ q = data_dict.get('q',None)
+ if not q:
+ return []
+
+ limit = data_dict.get('limit',10)
+
+ like_q = u"%s%%" % q
+
+ query = query_for('tag', backend='sql')
+ query.run(query=like_q,
+ return_objects=True,
+ limit=10,
+ username=user)
+
+ return [tag.name for tag in query.results]
+
def package_search(context, data_dict):
model = context['model']
session = context['session']
--- a/ckan/tests/functional/api/test_action.py Wed Jul 27 11:05:12 2011 +0100
+++ b/ckan/tests/functional/api/test_action.py Wed Jul 27 12:38:44 2011 +0100
@@ -122,9 +122,21 @@
def test_06_tag_list(self):
postparams = '%s=1' % json.dumps({})
res = self.app.post('/api/action/tag_list', params=postparams)
- assert json.loads(res.body) == {'help': 'Lists tags by name',
+ assert json.loads(res.body) == {'help': 'Returns a list of tags',
'success': True,
'result': ['russian', 'tolstoy']}
+ #Get all fields
+ postparams = '%s=1' % json.dumps({'all_fields':True})
+ res = self.app.post('/api/action/tag_list', params=postparams)
+ res_obj = json.loads(res.body)
+ pprint(res_obj)
+ assert res_obj['success'] == True
+ assert res_obj['result'][0]['name'] == 'russian'
+ assert len(res_obj['result'][0]['packages']) == 3
+ assert res_obj['result'][1]['name'] == 'tolstoy'
+ assert len(res_obj['result'][1]['packages']) == 2
+ assert 'id' in res_obj['result'][0]
+ assert 'id' in res_obj['result'][1]
def test_07_tag_show(self):
postparams = '%s=1' % json.dumps({'id':'russian'})
@@ -336,4 +348,24 @@
'success': False
}
+ def test_15_tag_autocomplete(self):
+ #Empty query
+ postparams = '%s=1' % json.dumps({})
+ res = self.app.post('/api/action/tag_autocomplete', params=postparams)
+ res_obj = json.loads(res.body)
+ assert res_obj == {
+ 'help': 'Returns tags containing the provided string',
+ 'result': [],
+ 'success': True
+ }
+ #Normal query
+ postparams = '%s=1' % json.dumps({'q':'r'})
+ res = self.app.post('/api/action/tag_autocomplete', params=postparams)
+ res_obj = json.loads(res.body)
+ assert res_obj == {
+ 'help': 'Returns tags containing the provided string',
+ 'result': ['russian'],
+ 'success': True
+ }
+
http://bitbucket.org/okfn/ckan/changeset/c29a2fc340ec/
changeset: c29a2fc340ec
branch: feature-1229-db-out-of-controllers
user: amercader
date: 2011-07-27 14:14:38
summary: [logic] Move API user_autocomplete
affected #: 3 files (1.3 KB)
--- a/ckan/controllers/api.py Wed Jul 27 12:38:44 2011 +0100
+++ b/ckan/controllers/api.py Wed Jul 27 13:14:38 2011 +0100
@@ -511,21 +511,15 @@
def user_autocomplete(self):
q = request.params.get('q', '')
limit = request.params.get('limit', 20)
- try:
- limit = int(limit)
- except:
- limit = 20
- limit = min(50, limit)
-
- query = model.User.search(q)
- def convert_to_dict(user):
- out = {}
- for k in ['id', 'name', 'fullname']:
- out[k] = getattr(user, k)
- return out
- query = query.limit(limit)
- out = map(convert_to_dict, query.all())
- return out
+ user_list = []
+ if q:
+ context = {'model': model, 'session': model.Session,
+ 'user': c.user or c.author}
+
+ data_dict = {'q':q,'limit':limit}
+
+ user_list = get.user_autocomplete(context,data_dict)
+ return user_list
@jsonpify
@@ -562,12 +556,13 @@
def tag_autocomplete(self):
q = request.params.get('incomplete', '')
+ limit = request.params.get('limit', 10)
tag_names = []
if q:
context = {'model': model, 'session': model.Session,
'user': c.user or c.author}
- data_dict = {'q':q,'limit':10}
+ data_dict = {'q':q,'limit':limit}
tag_names = get.tag_autocomplete(context,data_dict)
--- a/ckan/logic/action/get.py Wed Jul 27 12:38:44 2011 +0100
+++ b/ckan/logic/action/get.py Wed Jul 27 13:14:38 2011 +0100
@@ -453,6 +453,29 @@
return [tag.name for tag in query.results]
+def user_autocomplete(context, data_dict):
+ '''Returns users containing the provided string'''
+ model = context['model']
+ session = context['session']
+ user = context['user']
+ q = data_dict.get('q',None)
+ if not q:
+ return []
+
+ limit = data_dict.get('limit',20)
+
+ query = model.User.search(q).limit(limit)
+
+ user_list = []
+ for user in query.all():
+ result_dict = {}
+ for k in ['id', 'name', 'fullname']:
+ result_dict[k] = getattr(user,k)
+
+ user_list.append(result_dict)
+
+ return user_list
+
def package_search(context, data_dict):
model = context['model']
session = context['session']
--- a/ckan/tests/functional/api/test_action.py Wed Jul 27 12:38:44 2011 +0100
+++ b/ckan/tests/functional/api/test_action.py Wed Jul 27 13:14:38 2011 +0100
@@ -369,3 +369,21 @@
'success': True
}
+ def test_16_user_autocomplete(self):
+ #Empty query
+ postparams = '%s=1' % json.dumps({})
+ res = self.app.post('/api/action/user_autocomplete', params=postparams)
+ res_obj = json.loads(res.body)
+ assert res_obj == {
+ 'help': 'Returns users containing the provided string',
+ 'result': [],
+ 'success': True
+ }
+
+ #Normal query
+ postparams = '%s=1' % json.dumps({'q':'joe'})
+ res = self.app.post('/api/action/user_autocomplete', params=postparams)
+ res_obj = json.loads(res.body)
+ assert res_obj['result'][0]['name'] == 'joeadmin'
+ assert 'id','fullname' in res_obj['result'][0]
+
Repository URL: https://bitbucket.org/okfn/ckan/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
More information about the ckan-changes
mailing list