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

Bitbucket commits-noreply at bitbucket.org
Tue Nov 1 12:15:40 UTC 2011


2 new commits in ckan:


https://bitbucket.org/okfn/ckan/changeset/e68926926bee/
changeset:   e68926926bee
branch:      release-v1.5
user:        dread
date:        2011-11-01 13:00:11
summary:     [dictization][s]: #1405 Avoid getting duplicate packages in a group.
affected #:  4 files

diff -r 474c02a927bd58d4fb044945cc8975ff6ef026f8 -r e68926926bee62cc020d0c6223cd4dba52f0d839 ckan/lib/dictization/model_save.py
--- a/ckan/lib/dictization/model_save.py
+++ b/ckan/lib/dictization/model_save.py
@@ -304,7 +304,7 @@
             pkg = session.query(Package).get(id)
         if not pkg:
             pkg = session.query(Package).filter_by(name=package["name"]).first()
-        if pkg:
+        if pkg and pkg not in packages:
             packages.append(pkg)
 
     if packages or not allow_partial_update:


diff -r 474c02a927bd58d4fb044945cc8975ff6ef026f8 -r e68926926bee62cc020d0c6223cd4dba52f0d839 ckan/lib/navl/dictization_functions.py
--- a/ckan/lib/navl/dictization_functions.py
+++ b/ckan/lib/navl/dictization_functions.py
@@ -332,7 +332,33 @@
 
 
 def unflatten(data):
-    '''unflatten a simple dict whos keys are tuples'''
+    '''Unflatten a simple dict whose keys are tuples.
+
+    e.g.
+    >>> unflatten(
+      {('name',): u'testgrp4',
+       ('title',): u'',
+       ('description',): u'',
+       ('packages', 0, 'name'): u'testpkg',
+       ('packages', 1, 'name'): u'testpkg',
+       ('extras', 0, 'key'): u'packages',
+       ('extras', 0, 'value'): u'["testpkg"]',
+       ('extras', 1, 'key'): u'',
+       ('extras', 1, 'value'): u'',
+       ('state',): u'active'
+       ('save',): u'Save Changes',
+       ('cancel',): u'Cancel'})
+    {'name': u'testgrp4',
+     'title': u'',
+     'description': u'',
+     'packages': [{'name': u'testpkg'}, {'name': u'testpkg'}],
+     'extras': [{'key': u'packages', 'value': u'["testpkg"]'},
+                {'key': u'', 'value': u''}],
+     'state': u'active',
+     'save': u'Save Changes',
+     'cancel': u'Cancel'}
+    
+    '''
 
     unflattened = {}
 


diff -r 474c02a927bd58d4fb044945cc8975ff6ef026f8 -r e68926926bee62cc020d0c6223cd4dba52f0d839 ckan/logic/__init__.py
--- a/ckan/logic/__init__.py
+++ b/ckan/logic/__init__.py
@@ -50,6 +50,27 @@
 
 
 def clean_dict(data_dict):
+    '''Takes a dict and if any of the values are lists of dicts,
+    the empty dicts are stripped from the lists (recursive).
+
+    e.g.
+    >>> clean_dict(
+        {'name': u'testgrp4',
+         'title': u'',
+         'description': u'',
+         'packages': [{'name': u'testpkg'}, {'name': u'testpkg'}],
+         'extras': [{'key': u'packages', 'value': u'["testpkg"]'},
+                    {'key': u'', 'value': u''},
+                    {'key': u'', 'value': u''}],
+         'state': u'active'}
+    {'name': u'testgrp4',
+     'title': u'',
+     'description': u'',
+     'packages': [{'name': u'testpkg'}, {'name': u'testpkg'}],
+     'extras': [{'key': u'packages', 'value': u'["testpkg"]'}],
+     'state': u'active'}
+
+    '''
     for key, value in data_dict.items():
         if not isinstance(value, list):
             continue


diff -r 474c02a927bd58d4fb044945cc8975ff6ef026f8 -r e68926926bee62cc020d0c6223cd4dba52f0d839 ckan/tests/functional/test_group.py
--- a/ckan/tests/functional/test_group.py
+++ b/ckan/tests/functional/test_group.py
@@ -1,9 +1,12 @@
-from ckan.tests import *
-import ckan.model as model
-from base import FunctionalTestCase
+from nose.tools import assert_equal
 
 from ckan.plugins import SingletonPlugin, implements, IGroupController
 from ckan import plugins
+import ckan.model as model
+from ckan.lib.create_test_data import CreateTestData
+
+from ckan.tests import *
+from base import FunctionalTestCase
 from ckan.tests import search_related, is_search_supported
 
 class MockGroupControllerPlugin(SingletonPlugin):
@@ -198,6 +201,30 @@
         assert 'annakarenina' in res, res
         assert 'newone' in res
         
+    def test_4_new_duplicate_package(self):
+        prefix = ''
+
+        # Create group
+        group_name = u'testgrp4'
+        CreateTestData.create_groups([{'name': group_name,
+                                       'packages': [self.packagename]}],
+                                     admin_user_name='russianfan')
+
+        # Add same package again
+        offset = url_for(controller='group', action='edit', id=group_name)
+        res = self.app.get(offset, status=200, extra_environ={'REMOTE_USER': 'russianfan'})
+        fv = res.forms['group-edit']
+        fv['packages__1__name'] = self.packagename
+        res = fv.submit('save', status=302, extra_environ={'REMOTE_USER': 'russianfan'})
+        res = res.follow()
+        assert group_name in res, res
+        model.Session.remove()
+
+        # check package only added to the group once
+        group = model.Group.by_name(group_name)
+        pkg_names = [pkg.name for pkg in group.packages]
+        assert_equal(pkg_names, [self.packagename])
+
     def test_edit_plugin_hook(self):
         plugin = MockGroupControllerPlugin()
         plugins.load(plugin)
@@ -275,7 +302,7 @@
         pkg = model.Package.by_name(self.packagename)
         assert group.packages == [pkg]
 
-    def test_3_new_duplicate(self):
+    def test_3_new_duplicate_group(self):
         prefix = ''
 
         # Create group



https://bitbucket.org/okfn/ckan/changeset/ba47e53da1c1/
changeset:   ba47e53da1c1
branch:      release-v1.5
user:        dread
date:        2011-11-01 13:11:18
summary:     [i18n][xs]: Fix minor syntax error caused in cset:474c02a927bd.
affected #:  1 file

diff -r e68926926bee62cc020d0c6223cd4dba52f0d839 -r ba47e53da1c17257398f9e5dc8bb81b4d0dfe850 ckan/lib/base.py
--- a/ckan/lib/base.py
+++ b/ckan/lib/base.py
@@ -187,10 +187,10 @@
             try:
                 request_data = json.loads(request_data, encoding='utf8')
             except ValueError, e:
-                raise ValueError, 'Error parsing JSON data. '
-                                    'Error: %r '
+                raise ValueError, 'Error parsing JSON data. ' \
+                                    'Error: %r ' \
                                     'JSON (Decoded and re-encoded): %r' % \
-                                    (e, request_data))
+                                    (e, request_data)
             if not isinstance(request_data, dict):
                 raise ValueError, "Request params must be in form of a json encoded dictionary."
             # ensure unicode values

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