From c7e684a8d8affca2796ba281fe5dcb75129f1bea Mon Sep 17 00:00:00 2001 From: "pooya.oa" Date: Wed, 26 Jan 2022 15:24:13 +0100 Subject: [PATCH 1/2] let machine count more than resource count --- ckanext/semantic_media_wiki/controllers/media_wiki.py | 6 ++---- .../snippets/semantic_media_wiki_machines_dropdown.html | 4 +++- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ckanext/semantic_media_wiki/controllers/media_wiki.py b/ckanext/semantic_media_wiki/controllers/media_wiki.py index c35a2a8..8519e9f 100644 --- a/ckanext/semantic_media_wiki/controllers/media_wiki.py +++ b/ckanext/semantic_media_wiki/controllers/media_wiki.py @@ -8,7 +8,6 @@ import ckan.lib.helpers as h - class MediaWikiController(): def machines_view(id): @@ -27,13 +26,12 @@ def machines_view(id): def save_machines(): package_name = request.form.get('package') - resources_len = 0 + machine_count = request.form.get('machine_count') if package_name == None: return toolkit.abort(403, "bad request") try: package = toolkit.get_action('package_show')({}, {'name_or_id': package_name}) - resources_len = len(package['resources']) except: return toolkit.abort(400, "Package not found") @@ -46,7 +44,7 @@ def save_machines(): return redirect(h.url_for('dataset.read', id=str(package_name) , _external=True)) if action == 'finish_machine': - result = Helper.add_machine_links(request, resources_len) + result = Helper.add_machine_links(request, int(machine_count)) if result != false: return redirect(h.url_for('dataset.read', id=str(package_name) , _external=True)) diff --git a/ckanext/semantic_media_wiki/templates/snippets/semantic_media_wiki_machines_dropdown.html b/ckanext/semantic_media_wiki/templates/snippets/semantic_media_wiki_machines_dropdown.html index a7286b5..9ba4df1 100644 --- a/ckanext/semantic_media_wiki/templates/snippets/semantic_media_wiki_machines_dropdown.html +++ b/ckanext/semantic_media_wiki/templates/snippets/semantic_media_wiki_machines_dropdown.html @@ -1,4 +1,6 @@ -{% for res in resources %} +{% set machine_count = resources|length + 10 %} +{% for res in range(machine_count) %} +
{% snippet 'snippets/semantic_media_wiki_resources_modal.html', From 957546cb853a7739ea0f5058b505c2f5e37f1b4f Mon Sep 17 00:00:00 2001 From: "pooya.oa" Date: Wed, 26 Jan 2022 15:56:41 +0100 Subject: [PATCH 2/2] let machine count more than resource count for edit --- ckanext/semantic_media_wiki/controllers/media_wiki.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ckanext/semantic_media_wiki/controllers/media_wiki.py b/ckanext/semantic_media_wiki/controllers/media_wiki.py index 8519e9f..fd80b3b 100644 --- a/ckanext/semantic_media_wiki/controllers/media_wiki.py +++ b/ckanext/semantic_media_wiki/controllers/media_wiki.py @@ -57,7 +57,7 @@ def edit_machines_view(id): if not Helper.check_access_edit_package(id): return toolkit.abort(403, "You are not authorized to access this function" ) - package = toolkit.get_action('package_show')({}, {'name_or_id': id}) + package = toolkit.get_action('package_show')({}, {'name_or_id': id}) machines, machine_imageUrl = Helper.get_machines_list() resource_machine_data = {} machine_link_name = {} @@ -82,17 +82,17 @@ def edit_machines_view(id): def edit_save(): package_name = request.form.get('package') + machine_count = request.form.get('machine_count') package = toolkit.get_action('package_show')({}, {'name_or_id': package_name}) if not Helper.check_access_edit_package(package['id']): return toolkit.abort(403, "You are not authorized to access this function" ) - resources_len = int(request.form.get('resources_length')) action = request.form.get('save_btn') if action == 'go-dataset-veiw': # cancel button return redirect(h.url_for('dataset.read', id=str(package_name) , _external=True)) if action == 'update_machine': - result = Helper.update_resource_machine(request, resources_len, package) + result = Helper.update_resource_machine(request, int(machine_count), package) if result: return redirect(h.url_for('dataset.read', id=str(package_name) , _external=True))