Skip to content

Commit

Permalink
[#2750] Add a convert_to_extras field to ExampleIDatasetFormPlugin
Browse files Browse the repository at this point in the history
Add another custom field to ExampleIDatasetFormPlugin, one that uses
convert_to/from_extras instead of convert_to/from_tags.

I also had to make the plugin disable DefaultDatasetForm's
check_data_dict() because it breaks with the new three-stage dataset
creation when using convert_to_extras.
  • Loading branch information
Sean Hammond committed Feb 27, 2013
1 parent 9de978e commit aeb2687
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
20 changes: 18 additions & 2 deletions ckanext/example_idatasetform/plugin.py
Expand Up @@ -75,6 +75,13 @@ def form_to_db_schema(self):
converters.convert_to_tags('country_codes')]
})

# Add our custom_test metadata field to the schema, this one will use
# convert_to_extras instead of convert_to_tags.
schema.update({
'custom_text': [validators.ignore_missing,
converters.convert_to_extras]
})

return schema

def db_to_form_schema(self):
Expand All @@ -91,6 +98,12 @@ def db_to_form_schema(self):
validators.ignore_missing]
})

# Add our custom_text field to the dataset schema.
schema.update({
'custom_text': [
converters.convert_from_extras, validators.ignore_missing]
})

return schema

def setup_template_variables(self, context, data_dict=None):
Expand Down Expand Up @@ -140,5 +153,8 @@ def package_form(self):

def check_data_dict(self, data_dict, schema=None):
ExampleIDatasetFormPlugin.num_times_check_data_dict_called += 1
return lib_plugins.DefaultDatasetForm.check_data_dict(self, data_dict,
schema)
# Disable DefaultDatasetForm's check_data_dict(), because it breaks
# with the new three-stage dataset creation when using
# convert_to_extras.
#return lib_plugins.DefaultDatasetForm.check_data_dict(self, data_dict,
# schema)
Expand Up @@ -33,6 +33,8 @@
</select>
</div>

{{ form.input('custom_text', label=_('Custom Text'), id='field-custom_text', placeholder=_('custom text'), value=data.custom_text, error=errors.custom_text, classes=['control-medium']) }}

{#
{% block custom_fields %}
{% snippet 'snippets/custom_form_fields.html', extras=data.extras, errors=errors, limit=3 %}
Expand Down

2 comments on commit aeb2687

@seanh
Copy link
Contributor

@seanh seanh commented on aeb2687 Feb 28, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kindly Do you have a point of view on this? It seems that with the new three-stage dataset creation you can't use convert_to_extras because stages 1 and 2 submit only a partial dataset dict, which then gets passed to check_data_dict() which raises an error because keys are missing from the dict. In this commit I worked around it in the plugin. But we should fix it in core. Do we want to fix it or do we just want to remove check_data_dict()? I'm not really sure what check_data_dict() is for when we have the schemas.

@seanh
Copy link
Contributor

@seanh seanh commented on aeb2687 Feb 28, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We didn't seem to have this problem when using convert_to_tags, I haven't looked into it to see exactly why yet

Please sign in to comment.