[ckan-dev] Reading error after adding a new field in Organization
Qifeng.Bai at csiro.au
Qifeng.Bai at csiro.au
Mon May 12 00:17:32 UTC 2014
Hi, there
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.
n 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
From: ckan-dev [mailto:ckan-dev-bounces at lists.okfn.org] On Behalf Of Nigel Babu
Sent: Friday, 9 May 2014 4:58 PM
To: CKAN Development Discussions
Subject: Re: [ckan-dev] Reading error after adding a new field in Organization
Can you please upload your extension onto github so I can try it out. It's going to be really hard to debug this with just one piece of the puzzle.
Nigel Babu
Developer, Open Knowledge
On 9 May 2014 10:05, <Qifeng.Bai at csiro.au<mailto:Qifeng.Bai at csiro.au>> wrote:
Hi, there
I have been struggling into add a new field into “Organization” for a whole week. I have managed add 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: http://127.0.0.1:5000/organization/project6, it returns me “ValidationError: {'name': [u'Missing value']}”
Any comments are appreciated!
See below:
API method return correct value:
http://localhost:5000/api/3/action/organization_show?id=project6 .
It returns:
{
help: "Return the details of a organization. :param id: the id or name of the organization :type id: string :param include_datasets: include a list of the organization's datasets (optional, default: ``True``) :type id: boolean :rtype: dictionary .. note:: Only its first 1000 datasets are returned ",
success: true,
result: {
packages: [ ],
display_name: "project6",
approval_status: "approved",
image_display_url: "",
title: "project6",
name: "project6",
is_organization: true,
image_url: "",
groups: [ ],
users: [
{
capacity: "admin",
name: "baiqif"
}
],
project_leader: "p4",
type: "organization",
id: "e0439ec8-0895-49a1-bc4d-c2df0dce1d54",
tags: [ ],
description: ""
}
}
use CKAN page: http://127.0.0.1:5000/organization/project6 returns error:
File '/home/ckan/ckan/lib/default/src/ckan/ckan/controllers/group.py', line 187 in read
c.group_dict = self._action('group_show')(context, data_dict)
File '/home/ckan/ckan/lib/default/src/ckan/ckan/logic/__init__.py', line 419 in wrapped
result = _action(context, data_dict, **kw)
File '/home/ckan/ckan/lib/default/src/ckan/ckan/logic/action/get.py', line 1046 in organization_show
return _group_or_org_show(context, data_dict, is_org=True)
File '/home/ckan/ckan/lib/default/src/ckan/ckan/logic/action/get.py', line 989 in _group_or_org_show
group_dict = model_dictize.group_dictize(group, context)
File '/home/ckan/ckan/lib/default/src/ckan/ckan/lib/dictization/model_dictize.py', line 379 in group_dictize
search_results = logic.get_action('package_search')(context, q)
File '/home/ckan/ckan/lib/default/src/ckan/ckan/logic/__init__.py', line 419 in wrapped
result = _action(context, data_dict, **kw)
File '/home/ckan/ckan/lib/default/src/ckan/ckan/logic/action/get.py', line 1430 in package_search
raise ValidationError(errors)
ValidationError: {'name': [u'Missing value']}
Here are my codes:
class NlmpProjectFormPlugin(plugins.SingletonPlugin,DefaultOrganizationForm):
plugins.implements(plugins.IConfigurer, inherit=True)
plugins.implements(plugins.IGroupForm, inherit=True)
def update_config(self, config):
# Add this plugin's templates dir to CKAN's extra_template_paths, so
# that CKAN will use this plugin's custom templates.
tk.add_template_directory(config, 'templates')
def group_form(self):
return 'organization/new_organization_form.html'
def setup_template_variables(self, context, data_dict):
pass
def new_template(self):
return 'organization/new.html'
def about_template(self):
return 'organization/about.html'
def index_template(self):
return 'organization/index.html'
def admins_template(self):
return 'organization/admins.html'
def bulk_process_template(self):
return 'organization/bulk_process.html'
def read_template(self):
return 'organization/read.html'
# don't override history_template - use group template for history
def edit_template(self):
return 'organization/edit.html'
def activity_template(self):
return 'organization/activity_stream.html'
def is_fallback(self):
# Return True to register this plugin as the default handler for
# package types not handled by any other IDatasetForm plugin.
return False
def group_types(self):
# This plugin doesn't handle any special package types, it just
# registers itself as the default (above).
return ['organization']
def form_to_db_schema_options(self, options):
''' This allows us to select different schemas for different
purpose eg via the web interface or via the api or creation vs
updating. It is optional and if not available form_to_db_schema
should be used.
If a context is provided, and it contains a schema, it will be
returned.
'''
schema = options.get('context', {}).get('schema', None)
if schema:
return schema
if options.get('api'):
if options.get('type') == 'create':
return self.form_to_db_schema_api_create()
else:
return self.form_to_db_schema_api_update()
else:
return self.form_to_db_schema()
def form_to_db_schema_api_create(self):
schema = super(NlmpProjectFormPlugin, self).form_to_db_schema_api_create()
schema = self._modify_group_schema(schema)
return schema
def form_to_db_schema_api_update(self):
schema = super(NlmpProjectFormPlugin, self).form_to_db_schema_api_update()
schema = self._modify_group_schema(schema)
return schema
def form_to_db_schema(self):
schema = super(NlmpProjectFormPlugin, self).form_to_db_schema()
schema = self._modify_group_schema(schema)
return schema
def _modify_group_schema(self, schema):
#Import core converters and validators
_convert_to_extras = tk.get_converter('convert_to_extras')
_ignore_missing = tk.get_validator('ignore_missing')
default_validators = [_ignore_missing, _convert_to_extras]
schema.update({
'project_leader':default_validators
})
return schema
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
_______________________________________________
ckan-dev mailing list
ckan-dev at lists.okfn.org<mailto:ckan-dev at lists.okfn.org>
https://lists.okfn.org/mailman/listinfo/ckan-dev
Unsubscribe: https://lists.okfn.org/mailman/options/ckan-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.okfn.org/pipermail/ckan-dev/attachments/20140512/d642091c/attachment-0003.html>
More information about the ckan-dev
mailing list