Skip to content

Commit

Permalink
Add multiple resource_create action
Browse files Browse the repository at this point in the history
  • Loading branch information
blagojabozinovski committed Apr 11, 2024
1 parent 62a10c8 commit 7e8beeb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
{% endblock %}

{% block form %}
<form id="bulk_upload_form" method="post">
<form id="bulk_upload_form" method="post" enctype="multipart/form-data">

<input syle="margin-bottom:20px;" class ='btn btn-default' type="file" name="file[]" multiple="">
<input syle="margin-bottom:20px;" class ='btn btn-default' type="file" name="file[]" multiple>
{{ form.textarea('desc', id='field-description', label=_('Description'), value='') }}

<div style="display:flex; gap:10px">
Expand Down
21 changes: 13 additions & 8 deletions ckanext/bulkupload/views.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from flask import Blueprint
from flask import request
from ckan.common import config
import ckan.model as model
import ckan.logic as logic
import ckan.plugins.toolkit as tk
import ckan.lib.base as base


from ckan.common import g
from ckan.logic.action import get, create
import flask
Expand Down Expand Up @@ -38,15 +40,18 @@ def bulk_resource_upload(pkg_name):
"session": model.Session,
"user": g.user,
}
data_dict = {
'package_id': 'cloudstorage-03',
'name': 'Test Name3',
'url': 'Test Name3',
'url_type': 'upload',
'upload': open('/home/blagoja/Downloads/sample_data/5MB', 'rb'),
}
uploaded_files = flask.request.files.getlist("file[]")
for f in uploaded_files:

data_dict = {
'package_id': 'cloudstorage-03',
'name': f.filename,
'url': f.filename,
'url_type': 'upload',
'upload': open('/home/blagoja/Downloads/sample_data/5MB', 'rb'),
}

x = tk.get_action("resource_create")(context, data_dict)
x = tk.get_action("resource_create")(context, data_dict)

return base.render(
'package/upload_bulk_sucess.html'
Expand Down

0 comments on commit 7e8beeb

Please sign in to comment.