[ckan-changes] commit/ckan: kindly: [logic] validate for create and update

Bitbucket commits-noreply at bitbucket.org
Thu Jul 21 15:06:19 UTC 2011


1 new changeset in ckan:

http://bitbucket.org/okfn/ckan/changeset/b624a16744e7/
changeset:   b624a16744e7
branch:      feature-1211-drupal
user:        kindly
date:        2011-07-21 17:04:07
summary:     [logic] validate for create and update
affected #:  3 files (1.3 KB)

--- a/ckan/lib/dictization/model_save.py	Thu Jul 21 01:15:49 2011 +0100
+++ b/ckan/lib/dictization/model_save.py	Thu Jul 21 16:04:07 2011 +0100
@@ -126,7 +126,6 @@
     return result_dict
 
 def package_tag_list_save(tag_dicts, package, context):
-
     
     allow_partial_update = context.get("allow_partial_update", False)
     if not tag_dicts and allow_partial_update:


--- a/ckan/logic/action/create.py	Thu Jul 21 01:15:49 2011 +0100
+++ b/ckan/logic/action/create.py	Thu Jul 21 16:04:07 2011 +0100
@@ -77,6 +77,25 @@
     else:
         return data
 
+def package_create_validate(context, data_dict):
+    model = context['model']
+    user = context['user']
+    preview = context.get('preview', False)
+    schema = context.get('schema') or default_create_package_schema()
+    model.Session.remove()
+    model.Session()._context = context
+
+    check_access(model.System(), model.Action.PACKAGE_CREATE, context)
+    check_group_auth(context, data_dict)
+
+    data, errors = validate(data_dict, schema, context)
+
+    if errors:
+        model.Session.rollback()
+        raise ValidationError(errors, package_error_summary(errors))
+    else:
+        return data
+
 def resource_create(context, data_dict):
     model = context['model']
     user = context['user']


--- a/ckan/logic/action/update.py	Thu Jul 21 01:15:49 2011 +0100
+++ b/ckan/logic/action/update.py	Thu Jul 21 16:04:07 2011 +0100
@@ -190,6 +190,31 @@
         return package_dictize(pkg, context)
     return data
 
+def package_update_validate(context, data_dict):
+    model = context['model']
+    user = context['user']
+    
+    id = data_dict["id"]
+    preview = context.get('preview', False)
+    schema = context.get('schema') or default_update_package_schema()
+    model.Session.remove()
+    model.Session()._context = context
+
+    pkg = model.Package.get(id)
+    context["package"] = pkg
+
+    if pkg is None:
+        raise NotFound(_('Package was not found.'))
+    data_dict["id"] = pkg.id
+
+    check_access(pkg, model.Action.EDIT, context)
+    data, errors = validate(data_dict, schema, context)
+
+    if errors:
+        model.Session.rollback()
+        raise ValidationError(errors, package_error_summary(errors))
+    return data
+
 
 def _update_package_relationship(relationship, comment, context):
     model = context['model']

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