[ckan-changes] commit/ckan: 5 new changesets

Bitbucket commits-noreply at bitbucket.org
Wed Nov 2 14:06:17 UTC 2011


5 new commits in ckan:


https://bitbucket.org/okfn/ckan/changeset/9e02bd9c6f73/
changeset:   9e02bd9c6f73
branch:      feature-1371-task-status-logic-layer
user:        John Glover
date:        2011-11-02 12:21:55
summary:     Bug fix: 'group' and 'log' are not defined in this scope
affected #:  1 file

diff -r be2c10b12d72d34e002c91eb36ad39779ccfc53c -r 9e02bd9c6f73036abdb59cf1c32e109100f46e55 ckan/controllers/group.py
--- a/ckan/controllers/group.py
+++ b/ckan/controllers/group.py
@@ -80,18 +80,16 @@
         except NotAuthorized:
             abort(401, _('Unauthorized to read group %s') % id)
         try:
-            description_formatted = ckan.misc.MarkdownFormat().to_html(group.get('description',''))
+            description_formatted = ckan.misc.MarkdownFormat().to_html(c.group.get('description',''))
             c.description_formatted = genshi.HTML(description_formatted)
         except Exception, e:
             error_msg = "<span class='inline-warning'>%s</span>" % _("Cannot render description")
             c.description_formatted = genshi.HTML(error_msg)
         
         try:
- 
             desc_formatted = ckan.misc.MarkdownFormat().to_html(c.group.description)
             desc_formatted = genshi.HTML(desc_formatted)
         except genshi.ParseError, e:
-            log.error('Could not print group description: %r Error: %r', c.group.description, e)
             desc_formatted = 'Error: Could not parse group description'
         c.group_description_formatted = desc_formatted
         c.group_admins = self.authorizer.get_admins(c.group)



https://bitbucket.org/okfn/ckan/changeset/c039ccb79fb1/
changeset:   c039ccb79fb1
branch:      feature-1371-task-status-logic-layer
user:        John Glover
date:        2011-11-02 12:22:58
summary:     [logic] add function to show all packages belonging to a group
affected #:  2 files

diff -r 9e02bd9c6f73036abdb59cf1c32e109100f46e55 -r c039ccb79fb197d1af2019adcc0a705a8211a86d ckan/logic/action/get.py
--- a/ckan/logic/action/get.py
+++ b/ckan/logic/action/get.py
@@ -30,6 +30,31 @@
 
 log = logging.getLogger('ckan.logic')
 
+def _package_list_with_resources(context, package_revision_list):
+    package_list = []
+    model = context["model"]
+    for package in package_revision_list:
+        result_dict = table_dictize(package, context)
+        res_rev = model.resource_revision_table
+        resource_group = model.resource_group_table
+        query = select([res_rev], from_obj = res_rev.join(resource_group,
+                   resource_group.c.id == res_rev.c.resource_group_id))
+        query = query.where(resource_group.c.package_id == package.id)
+        result = query.where(res_rev.c.current == True).execute()
+        result_dict["resources"] = resource_list_dictize(result, context)
+        license_id = result_dict['license_id']
+        if license_id:
+            try:
+                isopen = model.Package.get_license_register()[license_id].isopen()
+                result_dict['isopen'] = isopen
+            except KeyError:
+                # TODO: create a log message this error?
+                result_dict['isopen'] = False
+        else:
+            result_dict['isopen'] = False
+        package_list.append(result_dict)
+    return package_list
+
 def site_read(context,data_dict=None):
     check_access('site_read',context,data_dict)
     return True
@@ -66,28 +91,7 @@
     if limit:
         query = query.limit(limit)
     pack_rev = query.all()
-    package_list = []
-    for package in pack_rev:
-        result_dict = table_dictize(package, context)
-        res_rev = model.resource_revision_table
-        resource_group = model.resource_group_table
-        query = select([res_rev], from_obj = res_rev.join(resource_group,
-                   resource_group.c.id == res_rev.c.resource_group_id))
-        query = query.where(resource_group.c.package_id == package.id)
-        result = query.where(res_rev.c.current == True).execute()
-        result_dict["resources"] = resource_list_dictize(result, context)
-        license_id = result_dict['license_id']
-        if license_id:
-            try:
-                isopen = model.Package.get_license_register()[license_id].isopen()
-                result_dict['isopen'] = isopen
-            except KeyError:
-                # TODO: create a log message this error?
-                result_dict['isopen'] = False
-        else:
-            result_dict['isopen'] = False
-        package_list.append(result_dict)
-    return package_list
+    return _package_list_with_resources(context, pack_rev)
 
 def revision_list(context, data_dict):
 
@@ -149,7 +153,6 @@
 
     If 'available_only' is specified, the existing groups in the package are
     removed.
-
     '''
     model = context['model']
     user = context['user']
@@ -157,7 +160,6 @@
 
     check_access('group_list_authz',context, data_dict)
 
-    from ckan.authz import Authorizer
     query = Authorizer().authorized_query(user, model.Group, model.Action.EDIT)
     groups = set(query.all())
     
@@ -402,6 +404,29 @@
 
     return group_dict
 
+def group_package_show(context, data_dict):
+    """
+    Shows all packages belonging to a group.
+    """
+    model = context["model"]
+    user = context["user"]
+    id = data_dict['id']
+    limit = data_dict.get("limit")
+
+    check_access('group_show', context, data_dict)
+
+    query = model.Session.query(model.PackageRevision)\
+        .filter(model.PackageRevision.state=='active')\
+        .filter(model.PackageRevision.current==True)\
+        .join(model.PackageGroup, model.PackageGroup.package_id==model.PackageRevision.id)\
+        .join(model.Group, model.Group.id==model.PackageGroup.group_id)\
+        .filter_by(id=id)
+
+    query = query.order_by(model.package_revision_table.c.revision_timestamp.desc())
+    if limit:
+        query = query.limit(limit)
+    pack_rev = query.all()
+    return _package_list_with_resources(context, pack_rev)
 
 def tag_show(context, data_dict):
     '''Shows tag details'''


diff -r 9e02bd9c6f73036abdb59cf1c32e109100f46e55 -r c039ccb79fb197d1af2019adcc0a705a8211a86d ckan/tests/functional/api/test_action.py
--- a/ckan/tests/functional/api/test_action.py
+++ b/ckan/tests/functional/api/test_action.py
@@ -714,7 +714,6 @@
         resource_dict = resource_dictize(resource, {'model': model})
         result.pop('revision_timestamp')
         assert result == resource_dict, (result, resource_dict)
-
     
     def test_27_get_site_user_not_authorized(self):
         assert_raises(NotAuthorized,
@@ -723,7 +722,7 @@
         user = model.User.get('test.ckan.net')
         assert not user
 
-        user=get_action('get_site_user')({'model': model, 'ignore_auth': True}, {})
+        user = get_action('get_site_user')({'model': model, 'ignore_auth': True}, {})
         assert user['name'] == 'test.ckan.net'
 
         user = model.User.get('test.ckan.net')
@@ -735,10 +734,38 @@
         user = model.Session.query(model.User).filter_by(name='test.ckan.net').one()
         assert user
 
+    def test_28_group_package_show(self):
+        group_id = model.Group.get('david').id
+        group_packages = get_action('group_package_show')(
+            {'model': model, 'user': self.normal_user.name, 'ignore_auth': True}, 
+            {'id': group_id}
+        )
+        assert len(group_packages) == 2, group_packages
+        group_names = set([g.get('name') for g in group_packages])
+        assert group_names == set(['annakarenina', 'warandpeace']), group_names
 
+    def test_29_group_package_show_pending(self):
+        context = {'model': model, 'session': model.Session, 'user': self.sysadmin_user.name}
+        group = {
+            'name': 'test_group_pending_package',
+            'packages': [{'id': model.Package.get('annakarenina').id}]
+        }
+        group = get_action('group_create')(context, group)
 
+        pkg = {
+            'name': 'test_pending_package',
+            'groups': [{'id': group['id']}]
+        }
+        pkg = get_action('package_create')(context, pkg)
+        # can't seem to add a package with 'pending' state, so update it
+        pkg['state'] = 'pending'
+        get_action('package_update')(context, pkg)
 
+        group_packages = get_action('group_package_show')(context, {'id': group['id']})
+        assert len(group_packages) == 2, group_packages
+        group_names = set([g.get('name') for g in group_packages])
+        assert group_names == set(['annakarenina', 'test_pending_package']), group_names
 
+        get_action('group_delete')(context, group)
+        get_action('package_delete')(context, pkg)
 
-
-



https://bitbucket.org/okfn/ckan/changeset/f0859a2e917f/
changeset:   f0859a2e917f
branch:      feature-1371-task-status-logic-layer
user:        John Glover
date:        2011-11-02 14:54:58
summary:     [logic] Bug fix: allow id in group_package_show to be a group name as well as a group ID
affected #:  1 file

diff -r c039ccb79fb197d1af2019adcc0a705a8211a86d -r f0859a2e917f96909788fd228d3dbbe0e34a994f ckan/logic/action/get.py
--- a/ckan/logic/action/get.py
+++ b/ckan/logic/action/get.py
@@ -413,6 +413,11 @@
     id = data_dict['id']
     limit = data_dict.get("limit")
 
+    group = model.Group.get(id)
+    context['group'] = group
+    if group is None:
+        raise NotFound
+
     check_access('group_show', context, data_dict)
 
     query = model.Session.query(model.PackageRevision)\
@@ -420,7 +425,7 @@
         .filter(model.PackageRevision.current==True)\
         .join(model.PackageGroup, model.PackageGroup.package_id==model.PackageRevision.id)\
         .join(model.Group, model.Group.id==model.PackageGroup.group_id)\
-        .filter_by(id=id)
+        .filter_by(id=group.id)
 
     query = query.order_by(model.package_revision_table.c.revision_timestamp.desc())
     if limit:



https://bitbucket.org/okfn/ckan/changeset/7c6ddd39bf39/
changeset:   7c6ddd39bf39
branch:      feature-1371-task-status-logic-layer
user:        John Glover
date:        2011-11-02 15:03:10
summary:     [controllers] Bug fix: make group controller use new group_package_show logic function. Fixes bug where packages with a 'pending' state would not show up in the group list.
affected #:  2 files

diff -r f0859a2e917f96909788fd228d3dbbe0e34a994f -r 7c6ddd39bf396a784d9ce331138fdfbe521ccf79 ckan/controllers/group.py
--- a/ckan/controllers/group.py
+++ b/ckan/controllers/group.py
@@ -53,11 +53,11 @@
         data_dict = {'all_fields': True}
 
         try:
-            check_access('site_read',context)
+            check_access('site_read', context)
         except NotAuthorized:
             abort(401, _('Not authorized to see this page'))
         
-        results = get_action('group_list')(context,data_dict)
+        results = get_action('group_list')(context, data_dict)
 
         c.page = Page(
             collection=results,
@@ -94,8 +94,10 @@
         c.group_description_formatted = desc_formatted
         c.group_admins = self.authorizer.get_admins(c.group)
 
+        results = get_action('group_package_show')(context, data_dict)
+
         c.page = Page(
-            collection=c.group.active_packages(),
+            collection=results,
             page=request.params.get('page', 1),
             items_per_page=50
         )


diff -r f0859a2e917f96909788fd228d3dbbe0e34a994f -r 7c6ddd39bf396a784d9ce331138fdfbe521ccf79 ckan/templates/group/read.html
--- a/ckan/templates/group/read.html
+++ b/ckan/templates/group/read.html
@@ -29,7 +29,7 @@
     <h3>Datasets:</h3><p i18n:msg="item_count">There are ${c.page.item_count} datasets in this group.</p>
     ${c.page.pager()}
-    ${package_list(c.page.items)}
+    ${package_list_from_dict(c.page.items)}
     ${c.page.pager()}
   </py:match>
 



https://bitbucket.org/okfn/ckan/changeset/1cab385cf5fb/
changeset:   1cab385cf5fb
branch:      feature-1371-task-status-logic-layer
user:        John Glover
date:        2011-11-02 15:06:05
summary:     [merge] merge with David R's changes
affected #:  1 file

diff -r 7c6ddd39bf396a784d9ce331138fdfbe521ccf79 -r 1cab385cf5fb72771c3d3c14375f108381b984bb ckan/logic/schema.py
--- a/ckan/logic/schema.py
+++ b/ckan/logic/schema.py
@@ -255,7 +255,7 @@
         'entity_type': [not_empty, unicode],
         'task_type': [not_empty, unicode],
         'key': [not_empty, unicode],
-        'value': [not_missing],
+        'value': [ignore_missing],
         'state': [ignore_missing],
         'last_updated': [ignore_missing],
         'error': [ignore_missing]

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