Commit 7ea64a26 authored by Marko Kuder's avatar Marko Kuder
Browse files

fix problem with broken uploaded files when user changed fields after submitting file

parent beb68145
......@@ -662,12 +662,35 @@ def schema_codelist_validator(key, data, errors, context):
def new_resource_if_url_and_description_change(key, data, errors, context):
from ckan.lib.base import h
import ckan.lib.munge as munge
from urlparse import urlparse
id_ = data[key]
if not id_:
return
old_resource = model.Resource.get(id_)
if not old_resource:
return
#taken from model_dictize to avoid problems if user edits resource description
#after uploading resource, but before saving the package, because the database
#holds only the filename in the URL (as stored by uploader), while the user is
#given the full url in the input field.
if old_resource.url_type == 'upload':
resource_group = model.Session.query(model.ResourceGroup).get(old_resource.resource_group_id)
last_part = old_resource.url.split('/')[-1]
cleaned_name = munge.munge_filename(last_part)
old_resource.url = h.url_for(controller='package',
action='resource_download',
id=resource_group.package_id,
resource_id=id_,
filename=cleaned_name,
qualified=True)
#compare only subpaths because proxy server might make domains different
if urlparse(old_resource.url).path == urlparse(data[(key[0], key[1], 'url')]).path:
return
if data[(key[0], key[1], 'url')] != old_resource.url and \
data[(key[0], key[1], 'description')] != old_resource.description:
# Resource has changed so much we consider it a new one by deleting its
......
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