Commit 155ab993 authored by Marko Kuder's avatar Marko Kuder
Browse files

copy some previous resource_create fixes to resource_update

parent 6f890614
import ckan.logic as logic
from ckan import plugins
from ckan.lib.base import h
import ckan.lib.uploader as uploader
from ckanext.dgu.lib.helpers import tidy_up_package
_check_access = logic.check_access
......@@ -196,6 +197,10 @@ def opsi_action_resource_create(context, data_dict):
upload = uploader.ResourceUpload(data_dict)
# TODO: currently only the filename is stored in the URL field of uploaded files. It would be beneficial to find a
# way to generate a full URL here (e.g. by generating an ID for the resource beforehand) to avoid changing between
# the filename and a full URL later on after archiver processing etc.
pkg_dict['resources'].append(data_dict)
try:
......
......@@ -63,6 +63,32 @@ def opsi_action_resource_update(context, data_dict):
else:
log.error('Could not find resource %s after all', id)
raise NotFound(_('Resource was not found.'))
# Persist the datastore_active extra if already present and not provided
if ('datastore_active' in resource.extras and
'datastore_active' not in data_dict):
data_dict['datastore_active'] = resource.extras['datastore_active']
#OPSI edit: check access appends package and its id to data_dict which may cause incorrect generation of resource filenames, we remove it
if data_dict.get('package', ''):
del data_dict['package']
if data_dict.get('id', ''):
del data_dict['id']
#remove date if it is empty (should be saved as individual resource)
if data_dict.get('date', 'not existing') == '':
del data_dict['date']
#if description is missing, but name is specified, copy it
if not data_dict.get('description') and data_dict.get('name'):
data_dict['description'] = data_dict.get('name')
#pogostost_osvezevanja is override of package field and we remove it from resource
if data_dict.has_key('pogostost_osvezevanja'):
if data_dict.get('pogostost_osvezevanja') != '':
pkg_dict['pogostost_osvezevanja'] = data_dict['pogostost_osvezevanja']
del data_dict['pogostost_osvezevanja']
# resource has to be updated in all resource lists,
# otherwise it would be merged back to the list of resources
# and single resource could not be updated
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment