Skip to content

Commit

Permalink
[#3656] Simplify logic for setting logo image
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksandar Jovanov authored and tino097 committed Dec 10, 2018
1 parent 35be44e commit e4cd06c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
17 changes: 3 additions & 14 deletions ckan/logic/action/update.py
Expand Up @@ -1275,23 +1275,12 @@ def config_option_update(context, data_dict):
model.Session.rollback()
raise ValidationError(errors)

image_in_ckan = False
public_path = config.get('ckan.static_files', 'public')
ckan_images_path = os.path.abspath(os.path.join(os.path.dirname(__file__),
'..', '..', public_path, 'base',
'images'))

for key, value in data.iteritems():

# Set full Logo url
if key == 'ckan.site_logo' and value and not value.startswith('http'):
if os.path.isfile('{0}/{1}'.format(ckan_images_path, value)):
image_in_ckan = True

if image_in_ckan:
image_path = 'base/images/'
else:
image_path = 'uploads/admin/'
if key == 'ckan.site_logo' and value and not value.startswith('http')\
and not value.startswith('/'):
image_path = 'uploads/admin/'

value = h.url_for_static('{0}{1}'.format(image_path, value))

Expand Down
5 changes: 5 additions & 0 deletions ckan/public/base/javascript/modules/image-upload.js
Expand Up @@ -129,6 +129,11 @@ this.ckan.module('image-upload', function($) {
* Returns String.
*/
_fileNameFromUpload: function(url) {
// If it's a local CKAN image return the entire URL.
if (/^\/base\/images/.test(url)) {
return url;
}

// remove fragment (#)
url = url.substring(0, (url.indexOf("#") === -1) ? url.length : url.indexOf("#"));
// remove query string
Expand Down

0 comments on commit e4cd06c

Please sign in to comment.