[ckan-changes] [okfn/ckan] 27c9be: [#901] Refactor the new_resource action

GitHub noreply at github.com
Thu Jun 6 14:05:09 UTC 2013


  Branch: refs/heads/901-bug-save-and-add-another
  Home:   https://github.com/okfn/ckan
  Commit: 27c9be028c8dbc189784fe7087fec732ee535b73
      https://github.com/okfn/ckan/commit/27c9be028c8dbc189784fe7087fec732ee535b73
  Author: Sean Hammond <seanhammond at lavabit.com>
  Date:   2013-06-06 (Thu, 06 Jun 2013)

  Changed paths:
    M ckan/controllers/package.py

  Log Message:
  -----------
  [#901] Refactor the new_resource action

Refactor the package controller's new_resource action.

Fixes #901: clicking the "Save & add another" button on the new resource
page if you had not entered any values into the resource form, but had
already saved some resources for this dataset, would take you to the
*Additional data* page which is wrong (it should reload the new resource
page).

The logic in the controller action was pretty tangled and hard to debug
or edit, because this one controller method deals with so many different
actions. The logic for handling each of the buttons on the new resource
form is similar, but slightly different for each button. Trying to
handle every button in one method leads to a long method of spaghetti
code. Handling each button in its own method leads to code duplication.
So I've split it up into a method for each button, but with several
shared helper methods.

There are no frontend tests for this so I likely introducted some new
bugs with this refactoring.

Paths I tested manually:

- Entering the new resource page, either by clicking the "Next: Add
  Data" button on the "Create dataset", by clicking the "+ Add New
  Resource" button on the "Edit Dataset" page (when editing an existing
  dataset), or by clicking the "Previous" button on the "Additional
  data" page (when adding a new dataset).

- The "Save & add another" button on the new resource form: try to add a
  new resource using the data entered into the form, then reload the new
  resource page, if there were errors the page reloads with the form
  data refilled and showing the error messages.

- The "Previous" button on the new resource form: the same as "Save &
  add another" but if there are no errors, go back to the "Create
  dataset" page instead.

  Also this one has a special case that if no data was entered in the
  form, it just goes back to the previous page, doesn't reload the new
  resource form with an error like the "Save & add another" button
  would.

- The "Next" button on the new resource form: the same as "Save & add
  another" but if there are no errors, go forward to the "Additional
  data" page instead.

  Also this one has a special case: if the user entered no data in the
  form, but they have already saved some resources for this dataset,
  then we go forward to the "Additional data" page rather than reloading
  the new resource page with errors as we would with the "Save & add
  another" button.

- The "Add" button on the new resource form (this one only shows when
  adding a new resource when editing a dataset, not when adding a new
  dataset): the same as "Save & add another" but if there are no errors,
  go back to the dataset read page instead.

- When editing a dataset, editing or deleting an existing resource is
  already handled by a different controller.

- With any of the buttons, if invalid data is entered (eg. a
  description, name and file format are entered, but no URL) the add
  resource page reloads with the data prefilled in the form and showing
  an error message.

- When adding a new dataset, clicking on the already-saved resources in
  the sidebar and then editing them works as expected when you click on
  any of the buttons.





More information about the ckan-changes mailing list