Skip to content

Commit

Permalink
Merge branch '2375-demo-theme-development' into 2375-demo-theme-stable
Browse files Browse the repository at this point in the history
  • Loading branch information
tobes committed Aug 20, 2012
2 parents 1706b36 + 657d1f2 commit fa015e2
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 8 deletions.
17 changes: 17 additions & 0 deletions 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 @@ -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
2 changes: 2 additions & 0 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 @@ -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)

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
18 changes: 14 additions & 4 deletions doc/templating.rst
Expand Up @@ -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.
Expand All @@ -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).
Expand Down Expand Up @@ -210,14 +216,17 @@ 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 %}

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
~~~~~~~

Expand Down Expand Up @@ -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

Expand Down

0 comments on commit fa015e2

Please sign in to comment.