diff --git a/ckan/lib/app_globals.py b/ckan/lib/app_globals.py index 400ceb0c546..f2a812d2942 100644 --- a/ckan/lib/app_globals.py +++ b/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 @@ -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)) @@ -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 @@ -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') diff --git a/ckan/lib/base.py b/ckan/lib/base.py index 88dfde1ab6d..04ad8e25e7c 100644 --- a/ckan/lib/base.py +++ b/ckan/lib/base.py @@ -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 @@ -204,6 +205,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) diff --git a/ckan/templates/user/read.html b/ckan/templates/user/read.html index 336faceba54..cc1d60f3835 100644 --- a/ckan/templates/user/read.html +++ b/ckan/templates/user/read.html @@ -84,10 +84,18 @@

{{ _('Datasets') }}

{% if user.datasets %} {% snippet 'snippets/package_list.html', packages=user.datasets %} {% else %} -

- {{ _('You haven\'t created any datasets.') }} - {% link_for _('Create one now?'), controller='package', action='new' %}. -

+ + {% if c.is_myself %} +

+ {{ _('You haven\'t created any datasets.') }} + {% link_for _('Create one now?'), controller='package', action='new' %}. +

+ {% else %} +

+ {{ _('User hasn\'t created any datasets.') }} +

+ {% endif %} + {% endif %}
diff --git a/doc/templating.rst b/doc/templating.rst index 1620161921b..4db540b5a70 100644 --- a/doc/templating.rst +++ b/doc/templating.rst @@ -127,6 +127,9 @@ language. Includes ~~~~~~~~ +.. Note:: + Includes should be avoided as they are not portable use {% snippet %} tags whenever possible. + Snippets of text that are included using ``{% include %}`` should be kept in a directory called _snippets_. This should be kept in the same directory as the code that uses it. @@ -138,6 +141,9 @@ case the usage should be clearly documented. Snippets ~~~~~~~~ +.. Note:: + {% snippet %} tags should be used in favour of h.snippet() + Snippets are essentially middle ground between includes and macros in that they are includes that allow a specific context to be provided (includes just receive the parent context). @@ -210,7 +216,7 @@ portion that we wish to change. In this case the ``breadcrumb`` block. :: - {% ckan_extends "user/read.html" %} + {% ckan_extends %} {# Remove the breadcrumb #} {% block breadcrumb %}{% endblock %} @@ -218,6 +224,9 @@ portion that we wish to change. In this case the ``breadcrumb`` block. This function works recursively and so is ideal for extensions that wish to add a small snippet of functionality to the page. +.. Note:: + {% ckan_extend %} only extends templates of the same name. + snippet ~~~~~~~ @@ -474,9 +483,10 @@ Builds a form from the supplied form_info list/tuple. :: - form_info - A list of dicts describing the form field to build. - data - The form data object. - errors - The form errors object. + form_info - A list of dicts describing the form field to build. + data - The form data object. + errors - The form errors object. + error_summary - The form errors object. Example