okfn/ckan — pull request #651 by seanh (2013-03-19 12:44:02+00:00)
Title: [wip] IDatasetForm package schemas simplification

@kindly @amercader @tobes @wardi As you can see this isn't finished yet but I pushed it now so you can see what I'm trying to do and say if you hate it. Some tests on this branch are currently failing because of DefaultDatasetForm's check_data_dict() method, which has already been deleted in pull request . Some other tests are failing because the tests are invalid, again these have already been deleted in . Other than that the tests all pass. Of course there are no frontend tests, but testing manually the three-stage dataset creation and dataset editing seems to work.

ExampleIDatasetFormPlugin from has not been updated or tested with this yet. I'd like to merge into master then pull it into this branch and update it on this branch.

logic/schema.py:

Delete all the different package schemas, replace with just three schemas, one for each action function: default_create_package_schema(), default_update_package_schema() and default_show_package_schema():

- [x] Delete default_package_schema()
- [x] Delete already deprecated package_form_schema()
- [x] Delete form_to_db_package_schema(), stuff that was in this schema
got moved into default_create_package_schema() and/or
default_update_package_schema() or just deleted
- [x] Fix default_create_package_schema() to be used whenever creating packages
(eg web or api)
- [x] Fix default_update_package_schema() to be used whenever updating packages
(eg web or api)
- [ ] Rename db_to_form_package_schema() -> default_show_package_schema()

(Note: there should maybe be delete_package_schema() too, but currently package_delete() doesn't do schema validation at all, maybe it should do.)

package_create():

- [x] Delete package_create_validate() action function
- [x] Don't call form_to_db_schema_options() or form_to_db_schema() anymore
- [x] Call plugin's package_create_schema(), if
plugin doesn't have this function or if it returns None then fall back
on default_package_create_schema()

package_update(), follows same pattern as package_create():

- [x] Delete package_update_validate() action function
- [x] Don't call form_to_db_schema_options() or form_to_db_schema() anymore
- [x] Call plugin's package_update_schema(), if
plugin doesn't have this function or if it returns None then fall back
on default_package_update_schema()

package_show(), follows same pattern as package_create() and package_update():

- [ ] Don't call db_to_form_schema_options() or db_to_form_schema() anymore
- [ ] Call plugin's package_show_schema(), if
plugin doesn't have this function or if it returns None then fall back
on default_package_show_schema()

DefaultDatasetForm:

For creating and updating packages:

- [x] Delete DefaultDatasetForm.form_to_db_schema_options()
- [x] Delete DefaultDatasetForm.form_to_db_schema()
- [x] Delete DefaultDatasetForm.form_to_db_schema_api_create()
- [x] Delete DefaultDatasetForm.form_to_db_schema_api_update()
- [x] Add DefaultDatasetForm.create_package_schema(), just returns None
- [x] Add DefaultDatasetForm.update_package_schema(), just returns None

For showing packages:

- [ ] Delete DefaultDatasetForm.db_to_form_schema_options()
- [ ] Delete DefaultDatasetForm.db_to_form_schema()
- [ ] Add DefaultDatasetForm.show_package_schema(), just returns None

IDatasetForm, follow same pattern as DefaultDatasetForm, but there's less to do as half of the functions were missing from IDatasetForm anyway:

- [ ] Remove form_to_db_schema()
- [ ] Remove db_to_form_schema()
- [ ] Add create_package_schema()
- [ ] Add update_package_schema()
- [ ] Add show_package_schema()

Package controller:

- [x] Don't validate package dicts in package controller, this is done in
the logic functions, it was being done twice
- [ ] Remove validation-related hacks that are no longer valid or needed
(eg. sending api version to make DefaultDatasetForm's
form_to_db_schema_options() call form_to_db_schema_api_create/update()
even though we're using the web UI

Tests:

- [x] Lots of tests updated to make them pass
- [x] MockVocabsPlugin updated to use new IDatasetForm interface

ckanext/example_idatasetform:

- [ ] Update ExampleIDatasetFormPlugin to use the new IDatasetForm interface,
check that it works and its tests still pass (this depends on
getting merged first)

Note that to be consistent with naming of other schemas in schema.py, the schemas are named verb_object_schema(), eg. create_package_schema(), which ofcourse is inconsistent with the corresponding action functions which are named the other way round package_update() etc.