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

Bitbucket commits-noreply at bitbucket.org
Tue Oct 25 09:32:46 UTC 2011


2 new commits in ckanextiati:


https://bitbucket.org/okfn/ckanextiati/changeset/6664c049ddb2/
changeset:   6664c049ddb2
branch:      spreadsheet-support
user:        amercader
date:        2011-10-24 18:47:33
summary:     Fix small bug in error message
affected #:  1 file

diff -r 246815965ac858ab05b79941caecc58b126d8342 -r 6664c049ddb217bcc7c39e47b081ea5795e24427 ckanext/iati/controllers/spreadsheet.py
--- a/ckanext/iati/controllers/spreadsheet.py
+++ b/ckanext/iati/controllers/spreadsheet.py
@@ -189,7 +189,7 @@
                 parts = name.split('-')
                 group_name = parts[0] if len(parts) == 2 else '-'.join(parts[:-1])
                 if not group_name or not group_name in groups:
-                    raise ValueError('Dataset name does not follow the convention <publisher>-<code>: "%s"' % group_name)
+                    raise ValueError('Dataset name does not follow the convention <publisher>-<code>: "%s"' % name)
 
                 package_dict = self.get_package_dict_from_row(row)
                 self.create_or_update_package(package_dict,counts)



https://bitbucket.org/okfn/ckanextiati/changeset/f6e8075c3096/
changeset:   f6e8075c3096
branch:      spreadsheet-support
user:        amercader
date:        2011-10-25 11:32:34
summary:     Add filter to check dataset name convention (<publisher>-<code>)

Note that datasets from worldbank and minbuza_nl groups have been renamed,
and redirects put in place.
affected #:  3 files

diff -r 6664c049ddb217bcc7c39e47b081ea5795e24427 -r f6e8075c30961d55ce48bf5956acfdcfda3dccdc ckanext/iati/controllers/package_iati.py
--- a/ckanext/iati/controllers/package_iati.py
+++ b/ckanext/iati/controllers/package_iati.py
@@ -5,6 +5,7 @@
 from ckan.controllers.package import PackageController
 from ckan.authz import Authorizer
 
+from ckan.logic import get_action
 from ckan.logic.schema import package_form_schema
 from ckan.lib.navl.validators import (ignore_missing,
                                       not_empty,
@@ -12,6 +13,7 @@
                                       ignore,
                                       keep_extras,
                                      )
+from ckan.lib.navl.dictization_functions import unflatten
 from ckan.logic.converters import convert_from_extras, convert_to_extras, date_to_db, date_to_form
 from ckan.lib.navl.dictization_functions import Missing, Invalid
 from ckan.lib.field_types import DateType, DateConvertError
@@ -46,6 +48,8 @@
             'language': [convert_to_extras, ignore_missing],
         })
 
+        schema['name'].append(iati_dataset_name)
+
         return schema
 
     def _db_to_form_schema(self):
@@ -86,7 +90,7 @@
             url = url.replace('<NAME>', pkgname)
         else:
             url = h.url_for(controller='package', action='read', id=pkgname)
-        redirect(url)        
+        redirect(url)
 
     # End hooks
 
@@ -104,11 +108,11 @@
 
 
 def convert_to_comma_list(value, context):
-     
+
     return ', '.join(json.loads(value))
 
 def convert_from_comma_list(value, context):
-     
+
     return [x.strip() for x in value.split(',') if len(x)]
 
 def checkbox_value(value,context):
@@ -124,3 +128,21 @@
             raise Invalid(str(e))
         return value
 
+def iati_dataset_name(key,data,errors,context):
+
+    unflattened = unflatten(data)
+    value = data[key]
+    for grp in unflattened['groups']:
+        if grp['id']:
+            group_id = grp['id']
+            break
+    group = get_action('group_show')(context,{'id':group_id})
+    group_name = group['name']
+
+    parts = value.split('-')
+    code_part = parts[-1]
+    group_part = parts[0] if len(parts) == 2 else '-'.join(parts[:-1])
+    if not code_part or not group_part or not group_part == group_name:
+        errors[key].append('Dataset name does not follow the convention <publisher>-<code>: "%s" (using publisher %s)' % (value,group_name))
+
+


diff -r 6664c049ddb217bcc7c39e47b081ea5795e24427 -r f6e8075c30961d55ce48bf5956acfdcfda3dccdc ckanext/iati/plugin.py
--- a/ckanext/iati/plugin.py
+++ b/ckanext/iati/plugin.py
@@ -53,6 +53,11 @@
         map.connect('/csv/upload', controller=csv_controller, action='upload',
                     conditions=dict(method=['POST']))
 
+
+        # Redirects needed after updating the datasets name for some of the publishers
+        map.redirect('/dataset/wb-{code}','/dataset/worldbank-{code}',_redirect_code='301 Moved Permanently')
+        map.redirect('/dataset/minbuza_{code}','/dataset/minbuza_nl-{code}',_redirect_code='301 Moved Permanently')
+
         return map
 
     def after_map(self, map):


diff -r 6664c049ddb217bcc7c39e47b081ea5795e24427 -r f6e8075c30961d55ce48bf5956acfdcfda3dccdc ckanext/iati/templates/package/form_iati.html
--- a/ckanext/iati/templates/package/form_iati.html
+++ b/ckanext/iati/templates/package/form_iati.html
@@ -53,8 +53,9 @@
         <dl><py:for each="num, group in enumerate(data.get('groups', []))"><?python
-            authorized_group = [group_authz for group_authz in c.groups_authz if group_authz['id'] == group['id']]
-            authorized_group = authorized_group[0] if authorized_group else None
+            if 'id' in group:
+                authorized_group = [group_authz for group_authz in c.groups_authz if group_authz['id'] == group['id']]
+                authorized_group = authorized_group[0] if authorized_group else None
             ?><dt py:if="'id' in group">

Repository URL: https://bitbucket.org/okfn/ckanextiati/

--

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