Skip to content

Commit

Permalink
Merge branch '2375-demo-theme-development' into 2618-nested-resources
Browse files Browse the repository at this point in the history
  • Loading branch information
tobes committed Aug 28, 2012
2 parents ae78bf6 + 61b33f6 commit ec105c4
Show file tree
Hide file tree
Showing 21 changed files with 116 additions and 42 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
19 changes: 18 additions & 1 deletion ckan/lib/app_globals.py
@@ -1,6 +1,8 @@
''' The application's Globals object '''

import logging
import time
from threading import Lock

from paste.deploy.converters import asbool
from pylons import config
Expand Down Expand Up @@ -46,6 +48,7 @@ def set_global(key, value):
''' helper function for getting value from database or config file '''
model.set_system_info(key, value)
setattr(app_globals, get_globals_key(key), value)
model.set_system_info('ckan.config_update', str(time.time()))
# update the config
config[key] = value
log.info('config `%s` set to `%s`' % (key, value))
Expand Down Expand Up @@ -73,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 Expand Up @@ -106,6 +109,8 @@ def get_config_value(key, default=''):
app_globals.header_class = 'header-text-logo-tagline'




class _Globals(object):

''' Globals acts as a container for objects available throughout the
Expand All @@ -117,6 +122,18 @@ def __init__(self):
'app_globals' variable
'''
self._init()
self._config_update = None
self._mutex = Lock()

def _check_uptodate(self):
''' check the config is uptodate needed when several instances are
running '''
value = model.get_system_info('ckan.config_update')
if self._config_update != value:
if self._mutex.acquire(False):
reset()
self._config_update = value
self._mutex.release()

def _init(self):
self.favicon = config.get('ckan.favicon', '/images/icons/ckan.ico')
Expand Down
24 changes: 15 additions & 9 deletions ckan/lib/base.py
Expand Up @@ -28,6 +28,7 @@
from ckan.lib import i18n
import lib.render
import ckan.lib.helpers as h
import ckan.lib.app_globals as app_globals
from ckan.plugins import PluginImplementations, IGenshiStreamFilter
from ckan.lib.helpers import json
import ckan.model as model
Expand Down Expand Up @@ -110,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 Expand Up @@ -204,6 +209,7 @@ class BaseController(WSGIController):
def __before__(self, action, **params):
c.__timer = time.time()
c.__version__ = ckan.__version__
app_globals.app_globals._check_uptodate()
self._identify_user()
i18n.handle_request(request, c)

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
16 changes: 12 additions & 4 deletions ckan/templates/user/read.html
Expand Up @@ -84,10 +84,18 @@ <h2 class="tab-heading">{{ _('Datasets') }}</h2>
{% if user.datasets %}
{% snippet 'snippets/package_list.html', packages=user.datasets %}
{% else %}
<p class="empty">
{{ _('You haven\'t created any datasets.') }}
{% link_for _('Create one now?'), controller='package', action='new' %}.
</p>

{% if c.is_myself %}
<p class="empty">
{{ _('You haven\'t created any datasets.') }}
{% link_for _('Create one now?'), controller='package', action='new' %}.
</p>
{% else %}
<p class="empty">
{{ _('User hasn\'t created any datasets.') }}
</p>
{% endif %}

{% endif %}
</section>
<section id="activity" class="module-content module-activity tab-content">
Expand Down
13 changes: 7 additions & 6 deletions ckanext/organizations/forms.py
Expand Up @@ -8,6 +8,8 @@
from ckan.lib.base import c, model, abort, request
from ckan.lib.base import redirect, _, config, h
from ckan.lib.navl.dictization_functions import DataError
import ckan.plugins as p

from ckan.plugins import IGroupForm, IDatasetForm, IConfigurer, IRoutes
from ckan.plugins import implements, SingletonPlugin
from ckan.logic import check_access
Expand Down Expand Up @@ -64,12 +66,11 @@ def update_config(self, config):
This IConfigurer implementation causes CKAN to look in the
```templates``` directory when looking for the group_form()
"""
here = os.path.dirname(__file__)
rootdir = os.path.dirname(os.path.dirname(here))
template_dir = os.path.join(rootdir, 'ckanext',
'organizations', 'templates')
config['extra_template_paths'] = ','.\
join([template_dir, config.get('extra_template_paths', '')])
templates = 'templates'
if p.toolkit.asbool(config.get('ckan.legacy_templates', False)):
templates = 'templates_legacy'
p.toolkit.add_template_directory(config, templates)
p.toolkit.add_public_directory(config, 'public')

# Override /group/* as the default groups urls
config['ckan.default.group_type'] = 'organization'
Expand Down
@@ -0,0 +1,12 @@
Dear administrator,

A request has been made for membership of your organization $group.title by $requester.name {% if requester.fullname %}( $requester.fullname ){% end %}

The reason given for the request was:

"$reason"

Please contact the user to verify and then if you would like to add this user you can do so by visiting ${h.url_for(controller='ckanext.organizers.controllers:OrganizationController', action='users', id=group.name, qualified=True) }

If you do not wish to add this user you can safely disregard this email.

0 comments on commit ec105c4

Please sign in to comment.