Skip to content

Commit

Permalink
Add organiation to dataset
Browse files Browse the repository at this point in the history
  • Loading branch information
blagojabozinovski committed Jul 12, 2024
1 parent 68709a3 commit aa4ea00
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 48 deletions.
16 changes: 16 additions & 0 deletions ckanext/bulkupload/templates/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,22 @@
{{ form.input('date-end', type='date', id='field-date-end', label=_('Date end'), value='', error='') }}
<div style="margin:-20px 0px 20px 0px;"><small>{{ form.info('Date start') }}</small></div>


<div class="form-group control-medium">
<label for="field-organizations" class="control-label">{{ _('Organization') }}</label>
<div class="controls">
<select id="field-organizations" name="owner_org" data-module="autocomplete">

{% for organization in org_list %}
{# get out first org from users list only if there is not an existing org #}
<option value="{{ organization.id }}" {% if selected_org %} selected="selected" {% endif %}>{{ organization.display_name }}</option>
{% endfor %}
</select>
</div>
</div>



<div style="display:flex; gap:10px">
<button type='submit', class ='btn btn-primary', icon='plus-square'>{{_('Create Dataset')}}</button>
</div>
Expand Down
109 changes: 61 additions & 48 deletions ckanext/bulkupload/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,68 @@
except:
log.critical('''Please specify a ckan.storage_path in your config
for your uploads''')


def busoperator():

if flask.request.method == 'GET':
context = {
"model": model,
"session": model.Session,
"user": g.user,
"auth_user_obj": g.userobj,
}

user_dict = {
'id': g.user,
'permission':'create_dataset',
}

org_list = tk.get_action("organization_list_for_user")(context, user_dict)

try:
tk.check_access("bulk_resource_upload", context)
except:
return tk.abort(403)

extra_var = {
'org_list': org_list,
}

return base.render('test.html', extra_var)

elif flask.request.method == 'POST':
context = {
"model": model,
"session": model.Session,
"user": g.user,
"auth_user_obj": g.userobj,
}
try:
tk.check_access("bulk_resource_upload", context)
except:
return tk.abort(403)

form_data = clean_dict(
dict_fns.unflatten(tuplize_dict(parse_params(tk.request.form)))
)
name_validated = form_data['title'].replace(' ', '-').lower()

data_dict = {
'name': name_validated,
'title': form_data['title'],
'private': False,
'status': 'active',
'owner_org': form_data['owner_org'],
}
try:
x = tk.get_action("package_create")(context, data_dict)
pckg_title = x['title']

except:
pass

return h.redirect_to(f'/dataset/{pckg_title}/resource/new/bulkupload')

def bulk_resource_upload(pkg_name):

Expand Down Expand Up @@ -105,54 +166,6 @@ def bulk_resource_upload(pkg_name):
return base.render(
'package/activity_bulk.html', extra_vars
)


def busoperator():

if flask.request.method == 'GET':
context = {
"model": model,
"session": model.Session,
"user": g.user,
"auth_user_obj": g.userobj,
}
try:
tk.check_access("bulk_resource_upload", context)
except:
return tk.abort(403)

return base.render('test.html')

elif flask.request.method == 'POST':
context = {
"model": model,
"session": model.Session,
"user": g.user,
"auth_user_obj": g.userobj,
}
try:
tk.check_access("bulk_resource_upload", context)
except:
return tk.abort(403)

form_data = clean_dict(
dict_fns.unflatten(tuplize_dict(parse_params(tk.request.form)))
)
name_validated = form_data['title'].replace(' ', '-').lower()

data_dict = {
'name': name_validated,
'title': form_data['title'],
'private': False,
'status': 'active',
}
try:
x = tk.get_action("package_create")(context, data_dict)
pckg_title = x['title']

except:
pass
return h.redirect_to(f'/dataset/{pckg_title}/resource/new/bulkupload')


bulkupload.add_url_rule("/dataset/busoperator",
Expand Down

0 comments on commit aa4ea00

Please sign in to comment.