Skip to content

Commit

Permalink
Allow addition of dataset without resources
Browse files Browse the repository at this point in the history
Temporary fix for ckan#377:

When ckan is configured with
`CKAN__DATASET__CREATE_ON_UI_REQUIRES_RESOURCES=False`, you should be
able to create a dataset without any resources but the scheming plugin
overrides this as it sets the state to draft until any resources are
added. This temporary fix means that the resources step is omitted from
the add dataset form and a catalog entry is created with no resources.

Not a solution worth actually using - the correct fix would allow the
option for something like "save without adding resources" on the
resource page instead of skipping over the resources. I haven't done
that since I don't need it for what I'm doing right now and it sounds
like the maintainers are on fixing the issue.
  • Loading branch information
madelinekosse committed Jul 10, 2023
1 parent 3046c05 commit de9f078
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions ckanext/scheming/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from flask import Response, Blueprint
from flask.views import MethodView
from werkzeug.datastructures import MultiDict

from ckantoolkit import config
from ckan.plugins.toolkit import (
h, request, get_action, abort, _, ObjectNotFound, NotAuthorized,
ValidationError,
Expand Down Expand Up @@ -83,8 +83,15 @@ def post(self, package_type, id, page):
data_dict[u'tag_string']
)
data_dict.pop('pkg_name', None)
data_dict['state'] = 'draft'
# END: roughly copied from ckan/views/dataset.py


# Only set the state to draft if wither we need to add resources, or this is the last page of metadata
create_on_ui_requires_resources = config.get('ckan.dataset.create_on_ui_requires_resources')
pages = h.scheming_get_dataset_form_pages(package_type)
is_last_page = page == len(pages)
if not is_last_page or create_on_ui_requires_resources:
data_dict['state'] = 'draft'


data_dict['id'] = id
try:
Expand All @@ -109,9 +116,8 @@ def post(self, package_type, id, page):
)
# END: roughly copied from ckan/views/dataset.py

if page == len(h.scheming_get_dataset_form_pages(package_type)):
# BEGIN: roughly copied from ckan/views/dataset.py
if 'resource_fields' in h.scheming_get_dataset_schema(package_type):
if page == len(pages):
if 'resource_fields' in h.scheming_get_dataset_schema(package_type) and create_on_ui_requires_resources:
return h.redirect_to(
'{}_resource.new'.format(package_type),
id=data['name'],
Expand All @@ -121,7 +127,18 @@ def post(self, package_type, id, page):
id=data['name'],
)
# END: roughly copied from ckan/views/dataset.py

url = h.url_for(
u'{}_resource.new'.format(package_type),
id=data[u'name']
)
if create_on_ui_requires_resources:
# redirect to add dataset resources if
# create_on_ui_requires_resources is set to true
url = h.url_for(
u'{}_resource.new'.format(package_type),
id=data[u'name']
)
return h.redirect_to(url)
return h.redirect_to(
'{}.scheming_new_page'.format(package_type),
id=complete_data['name'],
Expand Down

0 comments on commit de9f078

Please sign in to comment.