[ckan-dev] Reading error after adding a new field in Organization [ codes in github]
Qifeng.Bai at csiro.au
Qifeng.Bai at csiro.au
Tue May 13 03:39:49 UTC 2014
Today I ran two different tests, and I found:
Case 1:
If I defined the method def db_to_form_schema like below:
def db_to_form_schema(self):
# Import core converters and validators
_convert_from_extras = tk.get_converter('convert_from_extras')
_ignore_missing = tk.get_validator('ignore_missing')
schema = super(NlmpProjectFormPlugin, self).form_to_db_schema()
default_validators = [_convert_from_extras, _ignore_missing]
schema.update({
'project_leader':default_validators
})
return schema
Response from API request: http://127.0.0.1:5000/api/3/action/organization_show?id=project1
result: {
packages: [ ],
display_name: "Project1",
approval_status: "approved",
image_display_url: "",
title: "Project1",
name: "project1",
is_organization: true,
state: "active",
image_url: "",
groups: [ ],
users: [
{
capacity: "admin",
name: "baiqif"
}
],
project_leader: "P1",
type: "organization",
id: "b8728257-6e11-40c4-90ff-cea0f7289f71",
tags: [ ],
description: "This is a project1"
}
}
CKAN page http://127.0.0.1:5000/organization/project1 returned exception: ValidationError: {'name': [u'Missing value']}
However, http://127.0.0.1:5000/organization/edit/project1 returned a correct page !!!
--------------------------------------------------------------------
Case 2
If I defined the method def db_to_form_schema like below:
def db_to_form_schema(self):
pass
Response from API request: http://127.0.0.1:5000/api/3/action/organization_show?id=project1 and CKAN page http://127.0.0.1:5000/organization/project1 returned an normal page.
The difference of response between case 1 and case 2 are:
Case 2 has more info about user;
Case 2 treated project_leader as an extra field -- It is understandable.
result: {
users: [
{
openid: null,
about: null,
capacity: "admin",
name: "baiqif",
created: "2014-05-13T11:41:02.277859",
email_hash: "81dac013a19010300b2259b19a74baf5",
sysadmin: false,
activity_streams_email_notifications: false,
state: "active",
number_of_edits: 2,
number_administered_packages: 0,
display_name: "Qifeng Bai",
fullname: "Qifeng Bai",
id: "85172d99-476f-4191-9636-9281865db753"
}
],
display_name: "Project1",
description: "This is a project1",
image_display_url: "",
title: "Project1",
package_count: 0,
created: "2014-05-13T11:41:22.463945",
approval_status: "approved",
is_organization: true,
state: "active",
extras: [
{
value: "P1",
state: "active",
key: "project_leader",
revision_id: "7b968b54-118c-47cc-b353-0231bc0f9014",
group_id: "b8728257-6e11-40c4-90ff-cea0f7289f71",
id: "cbd5fcb7-9764-4e3f-8d43-f2ab3390de3d"
}
],
image_url: "",
groups: [ ],
num_followers: 0,
revision_id: "7b968b54-118c-47cc-b353-0231bc0f9014",
packages: [ ],
type: "organization",
id: "b8728257-6e11-40c4-90ff-cea0f7289f71",
tags: [ ],
name: "project1"
}
Wonder if "user" schema causes the "ValidationError: {'name': [u'Missing value']}"
From: ckan-dev [mailto:ckan-dev-bounces at lists.okfn.org] On Behalf Of Qifeng.Bai at csiro.au
Sent: Tuesday, 13 May 2014 10:06 AM
To: ckan-dev at lists.okfn.org
Subject: [ExternalEmail] [ckan-dev] Reading error after adding a new field in Organization [ codes in github]
I have developed a plugin which adds a field "project_leader" into "organization' . I can use API method to retrieve this project and get the value of "project_leader". However, when I use CKAN page, for example: http://127.0.0.1:5000/organization/project6, it returns me "ValidationError: {'name': [u'Missing value']}"
I have commit my code to https://github.com/baiqif/ckanext/tree/master/nlmp
There are two main classes in plugin.py:
ExampleIDatasetFormPlugin - it is the example the CKAN webiste gave
NlmpProjectFormPlugin - add a 'project_leader' to 'organization'. This is the example I got errors.
It can write 'project_leader' field into the CKAN database and I can read the value for API request. But CKAN web reports an error of {'name': [u'Missing value']}
Many thanks for your help
Bai
[cid:image001.gif at 01CC55BF.85E7FEB0]
Qifeng Bai
Software Engineer
CSIRO Land and Water
Black Mountain, Canberra
Ph: +61-2-62465704
Web: www.clw.csiro.au<http://www.clw.csiro.au>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.okfn.org/pipermail/ckan-dev/attachments/20140513/a012d36e/attachment-0003.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.gif
Type: image/gif
Size: 2094 bytes
Desc: image001.gif
URL: <http://lists.okfn.org/pipermail/ckan-dev/attachments/20140513/a012d36e/attachment-0003.gif>
More information about the ckan-dev
mailing list