[ckan-dev] Customizing forms in CKAN 2.0
Renato Guevara
guevara.renato at gmail.com
Thu Oct 23 20:52:36 UTC 2014
I tried to follow the example in the following link:
http://docs.ckan.org/en/latest/extensions/adding-custom-fields.html
I only went up to right before "Cleaning up the code". However when I run
the plugin I get
[Thu Oct 23 13:23:35 2014] [error] [client 127.0.0.1] Error - <type
'exceptions.AttributeError'>: 'NoneType' object has no attribute 'iteritems'
[Thu Oct 23 13:23:35 2014] [error] [client 127.0.0.1] URL:
http://bael-pf-describe01.pf.cee-w.net/dataset/edit/cohesive-integration-broker
[Thu Oct 23 13:23:35 2014] [error] [client 127.0.0.1] File
'/usr/lib/ckan/default/lib/python2.7/site-packages/weberror/errormiddleware.py',
line 162 in __call__
[Thu Oct 23 13:23:35 2014] [error] [client 127.0.0.1] app_iter =
self.application(environ, sr_checker)
[Thu Oct 23 13:23:35 2014] [error] [client 127.0.0.1] File
'/usr/lib/ckan/default/lib/python2.7/site-packages/webob/dec.py', line 147
in __call__
[Thu Oct 23 13:23:35 2014] [error] [client 127.0.0.1] resp =
self.call_func(req, *args, **self.kwargs)
[Thu Oct 23 13:23:35 2014] [error] [client 127.0.0.1] File
'/usr/lib/ckan/default/lib/python2.7/site-packages/webob/dec.py', line 208
in call_func
[Thu Oct 23 13:23:35 2014] [error] [client 127.0.0.1] return
self.func(req, *args, **kwargs)
[Thu Oct 23 13:23:35 2014] [error] [client 127.0.0.1] File
'/usr/lib/ckan/default/lib/python2.7/site-packages/fanstatic/publisher.py',
line 234 in __call__
[Thu Oct 23 13:23:35 2014] [error] [client 127.0.0.1] return
request.get_response(self.app)
[Thu Oct 23 13:23:35 2014] [error] [client 127.0.0.1] File
'/usr/lib/ckan/default/lib/python2.7/site-packages/webob/request.py', line
1053 in get_response
[Thu Oct 23 13:23:35 2014] [error] [client 127.0.0.1] application,
catch_exc_info=False)
[Thu Oct 23 13:23:35 2014] [error] [client 127.0.0.1] File
'/usr/lib/ckan/default/lib/python2.7/site-packages/webob/request.py', line
1022 in call_application
[Thu Oct 23 13:23:35 2014] [error] [client 127.0.0.1] app_iter =
application(self.environ, start_response)
[Thu Oct 23 13:23:35 2014] [error] [client 127.0.0.1] File
'/usr/lib/ckan/default/lib/python2.7/site-packages/webob/dec.py', line 147
in __call__
[Thu Oct 23 13:23:35 2014] [error] [client 127.0.0.1] resp =
self.call_func(req, *args, **self.kwargs)
[Thu Oct 23 13:23:35 2014] [error] [client 127.0.0.1] File
'/usr/lib/ckan/default/lib/python2.7/site-packages/webob/dec.py', line 208
in call_func
[Thu Oct 23 13:23:35 2014] [error] [client 127.0.0.1] return
self.func(req, *args, **kwargs)
[Thu Oct 23 13:23:35 2014] [error] [client 127.0.0.1] File
'/usr/lib/ckan/default/lib/python2.7/site-packages/fanstatic/injector.py',
line 54 in __call__
[Thu Oct 23 13:23:35 2014] [error] [client 127.0.0.1] response =
request.get_response(self.app)
[Thu Oct 23 13:23:35 2014] [error] [client 127.0.0.1] File
'/usr/lib/ckan/default/lib/python2.7/site-packages/webob/request.py', line
1053 in get_response
[Thu Oct 23 13:23:35 2014] [error] [client 127.0.0.1] application,
catch_exc_info=False)
[Thu Oct 23 13:23:35 2014] [error] [client 127.0.0.1] File
'/usr/lib/ckan/default/lib/python2.7/site-packages/webob/request.py', line
1022 in call_application
[Thu Oct 23 13:23:35 2014] [error] [client 127.0.0.1] app_iter =
application(self.environ, start_response)
[Thu Oct 23 13:23:35 2014] [error] [client 127.0.0.1] File
'/usr/lib/ckan/default/lib/python2.7/site-packages/beaker/middleware.py',
line 73 in __call__
[Thu Oct 23 13:23:35 2014] [error] [client 127.0.0.1] return
self.app(environ, start_response)
[Thu Oct 23 13:23:35 2014] [error] [client 127.0.0.1] File
'/usr/lib/ckan/default/lib/python2.7/site-packages/beaker/middleware.py',
line 155 in __call__
[Thu Oct 23 13:23:35 2014] [error] [client 127.0.0.1] return
self.wrap_app(environ, session_start_response)
[Thu Oct 23 13:23:35 2014] [error] [client 127.0.0.1] File
'/usr/lib/ckan/default/lib/python2.7/site-packages/routes/middleware.py',
line 131 in __call__
[Thu Oct 23 13:23:35 2014] [error] [client 127.0.0.1] response =
self.app(environ, start_response)
[Thu Oct 23 13:23:35 2014] [error] [client 127.0.0.1] File
'/usr/lib/ckan/default/lib/python2.7/site-packages/pylons/wsgiapp.py', line
125 in __call__
[Thu Oct 23 13:23:35 2014] [error] [client 127.0.0.1] response =
self.dispatch(controller, environ, start_response)
[Thu Oct 23 13:23:35 2014] [error] [client 127.0.0.1] File
'/usr/lib/ckan/default/lib/python2.7/site-packages/pylons/wsgiapp.py', line
324 in dispatch
[Thu Oct 23 13:23:35 2014] [error] [client 127.0.0.1] return
controller(environ, start_response)
[Thu Oct 23 13:23:35 2014] [error] [client 127.0.0.1] File
'/usr/lib/ckan/default/lib/python2.7/site-packages/ckan-2.2-py2.7.egg/ckan/lib/base.py',
line 346 in __call__
[Thu Oct 23 13:23:35 2014] [error] [client 127.0.0.1] res =
WSGIController.__call__(self, environ, start_response)
[Thu Oct 23 13:23:35 2014] [error] [client 127.0.0.1] File
'/usr/lib/ckan/default/lib/python2.7/site-packages/pylons/controllers/core.py',
line 221 in __call__
[Thu Oct 23 13:23:35 2014] [error] [client 127.0.0.1] response =
self._dispatch_call()
[Thu Oct 23 13:23:35 2014] [error] [client 127.0.0.1] File
'/usr/lib/ckan/default/lib/python2.7/site-packages/pylons/controllers/core.py',
line 172 in _dispatch_call
[Thu Oct 23 13:23:35 2014] [error] [client 127.0.0.1] response =
self._inspect_call(func)
[Thu Oct 23 13:23:35 2014] [error] [client 127.0.0.1] File
'/usr/lib/ckan/default/lib/python2.7/site-packages/pylons/controllers/core.py',
line 107 in _inspect_call
[Thu Oct 23 13:23:35 2014] [error] [client 127.0.0.1] result =
self._perform_call(func, args)
[Thu Oct 23 13:23:35 2014] [error] [client 127.0.0.1] File
'/usr/lib/ckan/default/lib/python2.7/site-packages/pylons/controllers/core.py',
line 60 in _perform_call
[Thu Oct 23 13:23:35 2014] [error] [client 127.0.0.1] return func(**args)
[Thu Oct 23 13:23:35 2014] [error] [client 127.0.0.1] File
'/usr/lib/ckan/default/lib/python2.7/site-packages/ckan-2.2-py2.7.egg/ckan/controllers/package.py',
line 784 in edit
[Thu Oct 23 13:23:35 2014] [error] [client 127.0.0.1] return
self._save_edit(id, context, package_type=package_type)
[Thu Oct 23 13:23:35 2014] [error] [client 127.0.0.1] File
'/usr/lib/ckan/default/lib/python2.7/site-packages/ckan-2.2-py2.7.egg/ckan/controllers/package.py',
line 1009 in _save_edit
[Thu Oct 23 13:23:35 2014] [error] [client 127.0.0.1] pkg =
get_action('package_update')(context, data_dict)
[Thu Oct 23 13:23:35 2014] [error] [client 127.0.0.1] File
'/usr/lib/ckan/default/lib/python2.7/site-packages/ckan-2.2-py2.7.egg/ckan/logic/__init__.py',
line 419 in wrapped
[Thu Oct 23 13:23:35 2014] [error] [client 127.0.0.1] result =
_action(context, data_dict, **kw)
[Thu Oct 23 13:23:35 2014] [error] [client 127.0.0.1] File
'/usr/lib/ckan/default/lib/python2.7/site-packages/ckan-2.2-py2.7.egg/ckan/logic/action/update.py',
line 294 in package_update
[Thu Oct 23 13:23:35 2014] [error] [client 127.0.0.1] data, errors =
_validate(data_dict, schema, context)
[Thu Oct 23 13:23:35 2014] [error] [client 127.0.0.1] File
'/usr/lib/ckan/default/lib/python2.7/site-packages/ckan-2.2-py2.7.egg/ckan/lib/navl/dictization_functions.py',
line 234 in validate
[Thu Oct 23 13:23:35 2014] [error] [client 127.0.0.1] converted_data,
errors = _validate(flattened, schema, context)
[Thu Oct 23 13:23:35 2014] [error] [client 127.0.0.1] File
'/usr/lib/ckan/default/lib/python2.7/site-packages/ckan-2.2-py2.7.egg/ckan/lib/navl/dictization_functions.py',
line 276 in _validate
[Thu Oct 23 13:23:35 2014] [error] [client 127.0.0.1] converted_data =
augment_data(data, schema)
[Thu Oct 23 13:23:35 2014] [error] [client 127.0.0.1] File
'/usr/lib/ckan/default/lib/python2.7/site-packages/ckan-2.2-py2.7.egg/ckan/lib/navl/dictization_functions.py',
line 120 in augment_data
[Thu Oct 23 13:23:35 2014] [error] [client 127.0.0.1] flattented_schema =
flatten_schema(schema)
[Thu Oct 23 13:23:35 2014] [error] [client 127.0.0.1] File
'/usr/lib/ckan/default/lib/python2.7/site-packages/ckan-2.2-py2.7.egg/ckan/lib/navl/dictization_functions.py',
line 67 in flatten_schema
[Thu Oct 23 13:23:35 2014] [error] [client 127.0.0.1] for key, value in
schema.iteritems():
[Thu Oct 23 13:23:35 2014] [error] [client 127.0.0.1] AttributeError:
'NoneType' object has no attribute 'iteritems'
These are what my files look like:
additional_info.html
------------------------------------------------------
{%ckan_extends %}
{% block extras %}
{% if pkg_dict.queryLanguage %}
<tr>
<th scope="row" class="dataset-label">{{ _("Query Language") }}</th>
<td class="dataset-details">{{ pkg_dict.queryLanguage }}</td>
</tr>
{% endif %}
{% endblock %}
------------------------------------------------------
package_basic_fields.html
------------------------------------------------------
{% ckan_extends %}
{% block package_basic_fields_custom %}
{{ form.input('queryLanguage', label=_('Query Language'),
id='field-queryLanguage', placeholder=_('Query Language'),
value=data.queryLanguage, error=errors.queryLanguage,
classes=['control-medium']) }}
{% endblock %}
------------------------------------------------------
package_metadata_fields.html
------------------------------------------------------
{% ckan_extends %}
{# Remove 'free extras' from the package form, as we don't want to support
them on our example. #}
{% block custom_fields %}
{% endblock %}
------------------------------------------------------
plugin.py
------------------------------------------------------
import ckan.plugins as p
import ckan.plugins.toolkit as tk
class DescribeFieldsPlugin(p.SingletonPlugin, tk.DefaultDatasetForm):
p.implements(p.IDatasetForm)
p.implements(p.IConfigurer)
def _modify_package_schema(self, schema):
schema.update({
'queryLanguage':
[tk.get_validator('ignore_missing'),
tk.get_converter('convert_to_extras')]
})
def create_package_schema(self):
schema = super(DescribeFieldsPlugin,
self).create_package_schema()
schema = self._modify_package_schema(schema)
return schema
def update_package_schema(self):
schema = super(DescribeFieldsPlugin,
self).update_package_schema()
schema = self._modify_package_schema(schema)
return schema
def show_package_schema(self):
schema = super(DescribeFieldsPlugin,
self).show_package_schema()
schema.update({
'queryLanguage':
[tk.get_converter('convert_from_extras'),
tk.get_validator('ignore_missing')]
})
return schema
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 True
def package_types(self):
# This plugin doesn't handle any special package types, it
just
# registers itself as the default (above).
return []
#update config
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')
------------------------------------------------------
What am I missing? I suspect it's in my HTML files but I'm not sure what I
could be missing or doing wrong. Any help would be greatly appreciated!
Renato Guevara
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.okfn.org/pipermail/ckan-dev/attachments/20141023/5379ff5f/attachment-0002.html>
More information about the ckan-dev
mailing list