Skip to content

Commit

Permalink
Merge branch '2375-demo-theme-development' of https://github.com/okfn…
Browse files Browse the repository at this point in the history
…/ckan into 2375-demo-theme-development
  • Loading branch information
rossjones committed Aug 29, 2012
2 parents 0ca640e + 61b33f6 commit 940c726
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 32 deletions.
33 changes: 21 additions & 12 deletions ckan/controllers/admin.py
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
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
22 changes: 13 additions & 9 deletions ckan/lib/base.py
Expand Up @@ -111,15 +111,19 @@ def render_template():
template_path = ''

log.debug('rendering %s [%s]' % (template_path, template_type))

debug_info = {'template_name' : template_name,
'template_path' : template_path,
'template_type' : template_type,
'vars' : globs,
'renderer' : renderer,}
if 'CKAN_DEBUG_INFO' not in request.environ:
request.environ['CKAN_DEBUG_INFO'] = []
request.environ['CKAN_DEBUG_INFO'].append(debug_info)
if config.get('debug'):
context_vars = globs.get('c')
if context_vars:
context_vars = dir(context_vars)
debug_info = {'template_name' : template_name,
'template_path' : template_path,
'template_type' : template_type,
'vars' : globs,
'c_vars': context_vars,
'renderer' : renderer,}
if 'CKAN_DEBUG_INFO' not in request.environ:
request.environ['CKAN_DEBUG_INFO'] = []
request.environ['CKAN_DEBUG_INFO'].append(debug_info)

# Jinja2 templates
if template_type == 'jinja2':
Expand Down
12 changes: 7 additions & 5 deletions ckan/lib/helpers.py
Expand Up @@ -1134,17 +1134,19 @@ def debug_full_info_as_list(debug_info):
'__sizeof__', '__str__', '__subclasshook__',
'__weakref__', 'action', 'environ', 'pylons',
'start_response']
for key in debug_info.keys():
debug_vars = debug_info['vars']
for key in debug_vars.keys():
if not key in ignored_keys:
data = pprint.pformat(debug_info.get(key))
data = pprint.pformat(debug_vars.get(key))
data = data.decode('utf-8')
out.append((key, data))

if 'tmpl_context' in debug_info:
for key in dir(debug_info['tmpl_context']):
print debug_info.keys()
if 'tmpl_context' in debug_vars:
for key in debug_info['c_vars']:

if not key in ignored_context_keys:
data = pprint.pformat(getattr(debug_info['tmpl_context'], key))
data = pprint.pformat(getattr(debug_vars['tmpl_context'], key))
data = data.decode('utf-8')
out.append(('c.%s' % key, data))

Expand Down
6 changes: 3 additions & 3 deletions ckan/templates/admin/config.html
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
@@ -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 %}
4 changes: 2 additions & 2 deletions ckan/templates/snippets/debug.html
Expand Up @@ -11,10 +11,10 @@
<b>Template path</b>: {{ info.template_path }}
<b>Template type</b>: {{ info.template_type }}
<b>Renderer</b>: {{ info.renderer }}
{% set debug_info = h.debug_full_info_as_list(info.vars) %}
{% set debug_info = h.debug_full_info_as_list(info) %}
{% if debug_info %}
<a class="toggle-debug-vars" style="color:#333"><b>Variables (toggle)</b></a>
<p style="display:block;">
<p style="display:block;white-space:normal;">
{%- for value in debug_info %}{{ value.0 }} {% endfor %}
</p><p style="display:none;">
{% for value in debug_info -%}
Expand Down

0 comments on commit 940c726

Please sign in to comment.