[ckan-changes] commit/ckan: kindly: [schema] 1339 fix int and date validators to convert empty string to None
Bitbucket
commits-noreply at bitbucket.org
Wed Sep 14 14:17:45 UTC 2011
1 new changeset in ckan:
http://bitbucket.org/okfn/ckan/changeset/a4af115116bb/
changeset: a4af115116bb
user: kindly
date: 2011-09-14 16:17:30
summary: [schema] 1339 fix int and date validators to convert empty string to None
affected #: 2 files (441 bytes)
--- a/ckan/logic/schema.py Wed Sep 14 12:00:18 2011 +0100
+++ b/ckan/logic/schema.py Wed Sep 14 15:17:30 2011 +0100
@@ -27,19 +27,11 @@
user_passwords_match,
user_password_not_empty,
isodate,
+ int_validator,
user_about_validator)
from formencode.validators import OneOf
import ckan.model
-def int_converter(indata):
- if isinstance(indata, basestring):
- cleaned = indata.strip()
- if cleaned != '':
- return int(indata)
- else:
- return None
- else:
- return int(indata)
def default_resource_schema():
@@ -61,10 +53,10 @@
'mimetype_inner': [ignore_missing, unicode],
'webstore_url': [ignore_missing, unicode],
'cache_url': [ignore_missing, unicode],
- 'size': [ignore_missing, int_converter],
- 'last_modified': [ignore_empty, isodate],
- 'cache_last_updated': [ignore_empty, isodate],
- 'webstore_last_updated': [ignore_empty, isodate],
+ 'size': [ignore_missing, int_validator],
+ 'last_modified': [ignore_missing, isodate],
+ 'cache_last_updated': [ignore_missing, isodate],
+ 'webstore_last_updated': [ignore_missing, isodate],
'__extras': [ignore_missing, extras_unicode_convert, keep_extras],
}
--- a/ckan/logic/validators.py Wed Sep 14 12:00:18 2011 +0100
+++ b/ckan/logic/validators.py Wed Sep 14 15:17:30 2011 +0100
@@ -15,13 +15,23 @@
'This key is read-only') % (package.id, value))
return value
+def int_validator(value, context):
+ if isinstance(value, int):
+ return value
+ try:
+ if value.strip() == '':
+ return None
+ return int(value)
+ except (AttributeError, ValueError), e:
+ raise Invalid(_('Invalid integer'))
+
def isodate(value, context):
-
if isinstance(value, datetime.datetime):
return value
+ if value == '':
+ return None
try:
date = date_str_to_datetime(value)
- context['revision_date'] = date
except (TypeError, ValueError), e:
raise Invalid(_('Date format incorrect'))
return date
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