[ckan-dev] saving values of a combobox
Sean Hammond
sean.hammond at okfn.org
Mon Sep 17 09:06:48 UTC 2012
> Hello!
> I would like to add an combobox-field, called "type". therefore i created an extension, and added three methods to it. The extension is activated, since other fields from the extension are shown (and saved) correctly. Unfortunately, although the values of this combobox are shown correctly, it will be not saved (after saving, the field is empty again). Following the code-snippet from my controller:
> type = [('', ''),
> ('testID', 'testDescription'),
> ]
> def _setup_template_variables(self, context, data_dict=None, package_type=None):
> c.type = type
>
> def _form_to_db_schema(self, package_type=None):
> schema = package_form_schema()
> schema['type'] = [ unicode, convert_to_extras ]
> return schema
>
> def _db_to_form_schema(self, package_type=None):
> schema = package_form_schema()
> schema['type'] = [ convert_from_extras, ignore_missing ]
> return schema
>
> What´s wrong with my code? - does anyone have any idea?
It's _much_ easier for us to help you if you can post the complete code
for e.g. your extension to somewhere like github, rather than just
snippets. Also for error messages, paste the whole traceback.
It looks like you're using convert_to_extras() and convert_from_extras()
to save your custom field, so I suspect your problem might be a bug in
CKAN where the 'free extras' that are present in the package form by
default are not compatible with convert_to/from_extras(). If you delete
the <fieldset class="tab-pane fade" id='extras'> section from
ckan/templates/package/new_package_form.html?
By the way if you're using IDatasetForm you should try CKAN 1.8 beta
(the release-v1.8 branch) as it has some bug fixes that are not in
1.7.1.
More information about the ckan-dev
mailing list