Skip to content

Instantly share code, notes, and snippets.

@amercader
Created January 19, 2017 16:38
Show Gist options
  • Save amercader/8b637e5e3a9358d11852a040aa84144c to your computer and use it in GitHub Desktop.
Save amercader/8b637e5e3a9358d11852a040aa84144c to your computer and use it in GitHub Desktop.
diff --git a/ckan/controllers/admin.py b/ckan/controllers/admin.py
index ed295d5..d2895a4 100644
--- a/ckan/controllers/admin.py
+++ b/ckan/controllers/admin.py
@@ -50,7 +50,8 @@ class AdminController(base.BaseController):
{'name': 'ckan.site_title', 'control': 'input', 'label': _('Site Title'), 'placeholder': ''},
{'name': 'ckan.main_css', 'control': 'select', 'options': styles, 'label': _('Style'), 'placeholder': ''},
{'name': 'ckan.site_description', 'control': 'input', 'label': _('Site Tag Line'), 'placeholder': ''},
- {'name': 'ckan.site_logo', 'control': 'image_upload', 'label': _('Site Tag Logo'), 'placeholder': '', 'upload_enabled':h.uploads_enabled()},
+ {'name': 'ckan.site_logo', 'control': 'image_upload', 'label': _('Site Tag Logo'), 'placeholder': '', 'upload_enabled':h.uploads_enabled(),
+ 'field_url': 'ckan.site_logo', 'field_upload': 'logo_upload', 'field_clear': 'clear_logo_upload'},
{'name': 'ckan.site_about', 'control': 'markdown', 'label': _('About'), 'placeholder': _('About page text')},
{'name': 'ckan.site_intro_text', 'control': 'markdown', 'label': _('Intro Text'), 'placeholder': _('Text on home page')},
{'name': 'ckan.site_custom_css', 'control': 'textarea', 'label': _('Custom CSS'), 'placeholder': _('Customisable css inserted into the page header')},
diff --git a/ckan/logic/action/update.py b/ckan/logic/action/update.py
index 3ff509c..a5fba86 100644
--- a/ckan/logic/action/update.py
+++ b/ckan/logic/action/update.py
@@ -1248,9 +1250,8 @@ def config_option_update(context, data_dict):
raise ValidationError(msg, error_summary={'message': msg})
upload = uploader.get_uploader('admin')
- #upload.upload(uploader.get_max_image_size())
- upload.update_data_dict(data_dict, 'image_url',
- 'image_upload', 'clear_upload')
+ upload.update_data_dict(data_dict, 'ckan.site_logo',
+ 'logo_upload', 'clear_logo_upload')
upload.upload(uploader.get_max_image_size())
data, errors = _validate(data_dict, schema, context)
if errors:
diff --git a/ckan/logic/schema.py b/ckan/logic/schema.py
index 1e8409e..286c536 100644
--- a/ckan/logic/schema.py
+++ b/ckan/logic/schema.py
@@ -665,9 +665,8 @@ def default_update_configuration_schema():
'ckan.site_custom_css': [unicode],
'ckan.main_css': [unicode],
'ckan.homepage_style': [is_positive_integer],
- 'image_url': [ignore_missing, unicode],
- 'image_upload': [ignore_missing, unicode],
- 'clear_upload': [ignore_missing, unicode],
+ 'logo_upload': [ignore_missing, unicode],
+ 'clear_logo_upload': [ignore_missing, unicode],
}
# Add ignore_missing to all fields, otherwise you need to provide them all
diff --git a/ckan/public/base/javascript/modules/image-upload.js b/ckan/public/base/javascript/modules/image-upload.js
index b4774c4..6d077e8 100644
--- a/ckan/public/base/javascript/modules/image-upload.js
+++ b/ckan/public/base/javascript/modules/image-upload.js
@@ -51,7 +51,7 @@ this.ckan.module('image-upload', function($) {
}
// Adds the hidden clear input to the form
- this.field_clear = $('<input type="hidden" name="clear_upload">')
+ this.field_clear = $('<input type="hidden" name="' + options.field_clear + '">')
.appendTo(this.el);
// Button to set the field to be a URL
diff --git a/ckan/templates/macros/autoform.html b/ckan/templates/macros/autoform.html
index 280c63d..d3a8895 100644
--- a/ckan/templates/macros/autoform.html
+++ b/ckan/templates/macros/autoform.html
@@ -52,9 +52,16 @@ Example
</div>
</div>
{% elif control == 'image_upload' %}
- {% set is_upload = data.image_url and not data.image_url.startswith('http') %}
- {% set is_url = data.image_url and data.image_url.startswith('http') %}
- {{ form.image_upload(data, errors, is_upload_enabled=item.upload_enabled, is_url=is_url, is_upload=is_upload, upload_label = _('Site logo'), url_label=_('Site logo')) }}
+
+ {% set field_url = item.field_url or 'image_url' %}
+ {% set is_upload = data[field_url] and not data[field_url].startswith('http') %}
+ {% set is_url = data[field_url] and data[field_url].startswith('http') %}
+
+ {% set field_upload = item.field_upload or 'image_upload' %}
+ {% set field_clear = item.field_clear or 'clear_upload' %}
+
+ {{ form.image_upload(data, errors, is_upload_enabled=item.upload_enabled, is_url=is_url, is_upload=is_upload, upload_label = _('Site logo'), url_label=_('Site logo'),
+ field_url=field_url, field_upload=field_upload, field_clear=field_clear)}}
{% else %}
{% call form[control](name, id=id, label=label, placeholder=placeholder, value=value, error=error, classes=classes) %}
{% if item.extra_info %}{{ form.info(item.extra_info) }}{% endif %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment