Skip to content

Commit

Permalink
[#2798] Improvements to admin config
Browse files Browse the repository at this point in the history
  • Loading branch information
tobes committed Aug 28, 2012
1 parent 8b13e3f commit 61b33f6
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 16 deletions.
33 changes: 21 additions & 12 deletions ckan/controllers/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ def __before__(self, action, **params):
model.Action.CHANGE_STATE,
model.Revision))

def config(self):

def _get_config_form_items(self):
# Styles for use in the form.select() macro.
styles = [{'text': 'Default', 'value': '/base/css/main.css'},
{'text': 'Red', 'value': '/base/css/red.css'},
Expand All @@ -48,25 +47,35 @@ def config(self):
{'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')},
]
return items

data = request.POST
if 'save' in data:
# update config from form
for item in items:
name = item['name']
if name in data:
app_globals.set_global(name, data[name])
app_globals.reset()
def reset_config(self):
if 'cancel' in request.params:
h.redirect_to(controller='admin', action='config')

if 'reset' in data:
if request.method == 'POST':
# remove sys info items
for item in items:
for item in self._get_config_form_items():
name = item['name']
app_globals.delete_global(name)
# reset to values in config
app_globals.reset()
h.redirect_to(controller='admin', action='config')

return base.render('admin/confirm_reset.html')

def config(self):

items = self._get_config_form_items()
data = request.POST
if 'save' in data:
# update config from form
for item in items:
name = item['name']
if name in data:
app_globals.set_global(name, data[name])
app_globals.reset()
h.redirect_to(controller='admin', action='config')

data = {}
for item in items:
Expand Down
2 changes: 1 addition & 1 deletion ckan/lib/app_globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def get_config_value(key, default=''):
config_value = config.get(key)
if key not in _CONFIG_CACHE:
_CONFIG_CACHE[key] = config_value
if value:
if value is not None:
log.debug('config `%s` set to `%s` from db' % (key, value))
else:
value = _CONFIG_CACHE[key]
Expand Down
6 changes: 3 additions & 3 deletions ckan/templates/admin/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ <h1 class="page-heading">{{ _('Configuration Settings') }}</h1>
<form method='post' action="" class="form-horizontal">
{{ autoform.generate(form_items, data, errors) }}
<div class="form-actions">
{# Update needs to come first so form submits when return is pressed #}
<button type="submit" class="btn btn-primary" name="save">Update</button>
<button type="submit" class="btn" name="reset">Reset</button>
{% set locale = h.dump_json({'content': _('Are you sure you want to reset the config?')}) %}
<a href="{% url_for controller='admin', action='reset_config' %}" class="btn btn-danger pull-left" data-module="confirm-action" data-module-i18n="{{ locale }}">{{ _('Reset') }}</a>
<button type="submit" class="btn btn-primary" name="save">{{ _('Update') }}</button>
</div>
</form>
</div>
Expand Down
19 changes: 19 additions & 0 deletions ckan/templates/admin/confirm_reset.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{% extends "page.html" %}

{% block subtitle %}{{ _("Confirm Reset") }}{% endblock %}

{% block maintag %}<div class="row" role="main">{% endblock %}

{% block main_content %}
<section class="module span6 offset3">
<div class="module-content">
<p>{{ _('Are you sure you want to reset the config?') }}</p>
<p class="form-actions">
<form action="{% url_for controller='admin', action='reset_config' %}" method="post">
<button class="btn" type="submit" name="cancel" >{{ _('Cancel') }}</button>
<button class="btn btn-primary" type="submit" name="delete" >{{ _('Confirm Reset') }}</button>
</form>
</p>
</div>
</section>
{% endblock %}

0 comments on commit 61b33f6

Please sign in to comment.