From 110e43d3637b81977d01470ea7bacc78540db226 Mon Sep 17 00:00:00 2001 From: Konstantin Sivakov Date: Fri, 3 Aug 2018 19:54:48 +0200 Subject: [PATCH] [#4382] strip full URL before saving to DB --- ckan/lib/dictization/model_save.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ckan/lib/dictization/model_save.py b/ckan/lib/dictization/model_save.py index b0abf1abcea..d9670030fa4 100644 --- a/ckan/lib/dictization/model_save.py +++ b/ckan/lib/dictization/model_save.py @@ -13,7 +13,9 @@ log = logging.getLogger(__name__) + def resource_dict_save(res_dict, context): + model = context["model"] session = context["session"] @@ -30,6 +32,11 @@ def resource_dict_save(res_dict, context): table = class_mapper(model.Resource).mapped_table fields = [field.name for field in table.c] + # Strip the full url for resources of type 'upload' + if res_dict.get('url_type') == u'upload': + url = res_dict.get('url') + res_dict[u'url'] = url[url.rfind(u"/")+1:] + # Resource extras not submitted will be removed from the existing extras # dict new_extras = {}