From 2cdc9947f83c8a9872525175dea407fe3c488704 Mon Sep 17 00:00:00 2001 From: Toby Date: Mon, 26 Mar 2012 11:08:50 +0100 Subject: [PATCH 01/17] stash apply --- ckan/config/environment.py | 9 +++++++-- ckan/config/middleware.py | 22 ++++++++++++++++++++++ ckan/lib/base.py | 5 +++++ ckan/lib/helpers.py | 15 ++++++++++----- ckan/templates/layout_base.html | 15 ++++++++++++++- test-core.ini | 1 + 6 files changed, 59 insertions(+), 8 deletions(-) diff --git a/ckan/config/environment.py b/ckan/config/environment.py index 33e9360ff9d..c6a1d3c18a9 100644 --- a/ckan/config/environment.py +++ b/ckan/config/environment.py @@ -19,7 +19,7 @@ from genshi.filters.i18n import Translator import ckan.lib.app_globals as app_globals -import ckan.lib.helpers +import ckan.lib.helpers as h from ckan.config.routing import make_map from ckan import model from ckan import plugins @@ -97,7 +97,12 @@ def find_controller(self, controller): config['routes.map'] = make_map() config['pylons.app_globals'] = app_globals.Globals() - config['pylons.h'] = ckan.lib.helpers + + if asbool(config.get('ckan.restrict_template_vars', 'false')): + import ckan.lib.helpers_clean + config['pylons.h'] = ckan.lib.helpers_clean + else: + config['pylons.h'] = h ## redo template setup to use genshi.search_path (so remove std template setup) template_paths = [paths['templates'][0]] diff --git a/ckan/config/middleware.py b/ckan/config/middleware.py index c07948a51a8..771376838d5 100644 --- a/ckan/config/middleware.py +++ b/ckan/config/middleware.py @@ -1,5 +1,6 @@ """Pylons middleware initialization""" import urllib +import urllib2 import logging import json @@ -130,8 +131,29 @@ def make_app(global_conf, full_stack=True, static_files=True, **app_conf): if asbool(config.get('ckan.page_cache_enabled')): app = PageCacheMiddleware(app, config) + app = TrackingMiddleware(app, config) return app + +class TrackingMiddleware(object): + + def __init__(self, app, config): + self.app = app + + def __call__(self, environ, start_response): + path = environ['PATH_INFO'] + if path == '/_tracking': + # do the tracking + payload = environ['wsgi.input'].read() + parts = payload.split('&') + data = {} + for part in parts: + k, v = part.split('=') + data[k] = urllib2.unquote(v).decode("utf8") + start_response('200 OK', [('Content-Type', 'text/html')]) + return [] + return self.app(environ, start_response) + class I18nMiddleware(object): """I18n Middleware selects the language based on the url eg /fr/home is French""" diff --git a/ckan/lib/base.py b/ckan/lib/base.py index cf1ab99b007..80d61564c7e 100644 --- a/ckan/lib/base.py +++ b/ckan/lib/base.py @@ -35,6 +35,7 @@ ALLOWED_FIELDSET_PARAMS = ['package_form', 'restrict'] + def abort(status_code=None, detail='', headers=None, comment=None): if detail and status_code!=503: h.flash_error(detail) @@ -58,6 +59,10 @@ def render_template(): # Using pylons.url() directly destroys the localisation stuff so # we remove it so any bad templates crash and burn del globs['url'] + ##import pprint + ##print '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~' + ##pprint.pprint(globs) + ##print '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~' template = globs['app_globals'].genshi_loader.load(template_name, cls=loader_class) diff --git a/ckan/lib/helpers.py b/ckan/lib/helpers.py index 87c62f9617d..c68e5008667 100644 --- a/ckan/lib/helpers.py +++ b/ckan/lib/helpers.py @@ -127,6 +127,7 @@ def _add_i18n_to_url(url_to_amend, **kw): def lang(): return request.environ.get('CKAN_LANG') + class Message(object): """A message returned by ``Flash.pop_messages()``. @@ -204,19 +205,20 @@ def are_there_messages(self): from pylons import session return bool(session.get(self.session_key)) -_flash = _Flash() +flash = _Flash() +_flash = flash def flash_notice(message, allow_html=False): - _flash(message, category='alert-info', allow_html=allow_html) + flash(message, category='alert-info', allow_html=allow_html) def flash_error(message, allow_html=False): - _flash(message, category='alert-error', allow_html=allow_html) + flash(message, category='alert-error', allow_html=allow_html) def flash_success(message, allow_html=False): - _flash(message, category='alert-success', allow_html=allow_html) + flash(message, category='alert-success', allow_html=allow_html) def are_there_flash_messages(): - return _flash.are_there_messages() + return flash.are_there_messages() # FIXME: shouldn't have to pass the c object in to this. def nav_link(c, text, controller, **kwargs): @@ -548,5 +550,8 @@ def auto_log_message(context): return _('Edited settings.') return '' +<<<<<<< Updated upstream def content_span(body_class): return body_class.__str__() +======= +>>>>>>> Stashed changes diff --git a/ckan/templates/layout_base.html b/ckan/templates/layout_base.html index ac61a6fff0c..f6d5c631aa1 100644 --- a/ckan/templates/layout_base.html +++ b/ckan/templates/layout_base.html @@ -81,7 +81,7 @@ - +
${h.literal(m)} @@ -264,6 +264,19 @@

Meta

}); + + ${optional_footer()} diff --git a/test-core.ini b/test-core.ini index 3e7fde4831f..4e800b86d8a 100644 --- a/test-core.ini +++ b/test-core.ini @@ -35,6 +35,7 @@ ckan.extra_resource_fields = alt_url # disable this so we can test all types of indexing ckan.build_search_index_synchronously = false +#ckan.restrict_template_vars = true # Add additional test specific configuration options as necessary. auth.blacklist = 83.222.23.234 From ba37da05d8e90ddd0c4b5401622623e1b3b86366 Mon Sep 17 00:00:00 2001 From: Toby Date: Mon, 26 Mar 2012 11:20:27 +0100 Subject: [PATCH 02/17] merge fix --- ckan/lib/helpers.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/ckan/lib/helpers.py b/ckan/lib/helpers.py index c68e5008667..0954641e2a8 100644 --- a/ckan/lib/helpers.py +++ b/ckan/lib/helpers.py @@ -550,8 +550,5 @@ def auto_log_message(context): return _('Edited settings.') return '' -<<<<<<< Updated upstream def content_span(body_class): return body_class.__str__() -======= ->>>>>>> Stashed changes From c91403b4ad5dd01abc1527aec777e8d25897ab3e Mon Sep 17 00:00:00 2001 From: Toby Date: Mon, 26 Mar 2012 11:22:34 +0100 Subject: [PATCH 03/17] Revert "merge fix" This reverts commit ba37da05d8e90ddd0c4b5401622623e1b3b86366. --- ckan/lib/helpers.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ckan/lib/helpers.py b/ckan/lib/helpers.py index 0954641e2a8..c68e5008667 100644 --- a/ckan/lib/helpers.py +++ b/ckan/lib/helpers.py @@ -550,5 +550,8 @@ def auto_log_message(context): return _('Edited settings.') return '' +<<<<<<< Updated upstream def content_span(body_class): return body_class.__str__() +======= +>>>>>>> Stashed changes From a1edf5aa7b8d565db5bf2732d16ea6b359cee3b6 Mon Sep 17 00:00:00 2001 From: Toby Date: Mon, 26 Mar 2012 11:26:57 +0100 Subject: [PATCH 04/17] Revert "stash apply" This reverts commit 2cdc9947f83c8a9872525175dea407fe3c488704. --- ckan/config/environment.py | 9 ++------- ckan/config/middleware.py | 22 ---------------------- ckan/lib/base.py | 5 ----- ckan/lib/helpers.py | 15 +++++---------- ckan/templates/layout_base.html | 15 +-------------- test-core.ini | 1 - 6 files changed, 8 insertions(+), 59 deletions(-) diff --git a/ckan/config/environment.py b/ckan/config/environment.py index c6a1d3c18a9..33e9360ff9d 100644 --- a/ckan/config/environment.py +++ b/ckan/config/environment.py @@ -19,7 +19,7 @@ from genshi.filters.i18n import Translator import ckan.lib.app_globals as app_globals -import ckan.lib.helpers as h +import ckan.lib.helpers from ckan.config.routing import make_map from ckan import model from ckan import plugins @@ -97,12 +97,7 @@ def find_controller(self, controller): config['routes.map'] = make_map() config['pylons.app_globals'] = app_globals.Globals() - - if asbool(config.get('ckan.restrict_template_vars', 'false')): - import ckan.lib.helpers_clean - config['pylons.h'] = ckan.lib.helpers_clean - else: - config['pylons.h'] = h + config['pylons.h'] = ckan.lib.helpers ## redo template setup to use genshi.search_path (so remove std template setup) template_paths = [paths['templates'][0]] diff --git a/ckan/config/middleware.py b/ckan/config/middleware.py index 771376838d5..c07948a51a8 100644 --- a/ckan/config/middleware.py +++ b/ckan/config/middleware.py @@ -1,6 +1,5 @@ """Pylons middleware initialization""" import urllib -import urllib2 import logging import json @@ -131,29 +130,8 @@ def make_app(global_conf, full_stack=True, static_files=True, **app_conf): if asbool(config.get('ckan.page_cache_enabled')): app = PageCacheMiddleware(app, config) - app = TrackingMiddleware(app, config) return app - -class TrackingMiddleware(object): - - def __init__(self, app, config): - self.app = app - - def __call__(self, environ, start_response): - path = environ['PATH_INFO'] - if path == '/_tracking': - # do the tracking - payload = environ['wsgi.input'].read() - parts = payload.split('&') - data = {} - for part in parts: - k, v = part.split('=') - data[k] = urllib2.unquote(v).decode("utf8") - start_response('200 OK', [('Content-Type', 'text/html')]) - return [] - return self.app(environ, start_response) - class I18nMiddleware(object): """I18n Middleware selects the language based on the url eg /fr/home is French""" diff --git a/ckan/lib/base.py b/ckan/lib/base.py index 80d61564c7e..cf1ab99b007 100644 --- a/ckan/lib/base.py +++ b/ckan/lib/base.py @@ -35,7 +35,6 @@ ALLOWED_FIELDSET_PARAMS = ['package_form', 'restrict'] - def abort(status_code=None, detail='', headers=None, comment=None): if detail and status_code!=503: h.flash_error(detail) @@ -59,10 +58,6 @@ def render_template(): # Using pylons.url() directly destroys the localisation stuff so # we remove it so any bad templates crash and burn del globs['url'] - ##import pprint - ##print '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~' - ##pprint.pprint(globs) - ##print '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~' template = globs['app_globals'].genshi_loader.load(template_name, cls=loader_class) diff --git a/ckan/lib/helpers.py b/ckan/lib/helpers.py index c68e5008667..87c62f9617d 100644 --- a/ckan/lib/helpers.py +++ b/ckan/lib/helpers.py @@ -127,7 +127,6 @@ def _add_i18n_to_url(url_to_amend, **kw): def lang(): return request.environ.get('CKAN_LANG') - class Message(object): """A message returned by ``Flash.pop_messages()``. @@ -205,20 +204,19 @@ def are_there_messages(self): from pylons import session return bool(session.get(self.session_key)) -flash = _Flash() -_flash = flash +_flash = _Flash() def flash_notice(message, allow_html=False): - flash(message, category='alert-info', allow_html=allow_html) + _flash(message, category='alert-info', allow_html=allow_html) def flash_error(message, allow_html=False): - flash(message, category='alert-error', allow_html=allow_html) + _flash(message, category='alert-error', allow_html=allow_html) def flash_success(message, allow_html=False): - flash(message, category='alert-success', allow_html=allow_html) + _flash(message, category='alert-success', allow_html=allow_html) def are_there_flash_messages(): - return flash.are_there_messages() + return _flash.are_there_messages() # FIXME: shouldn't have to pass the c object in to this. def nav_link(c, text, controller, **kwargs): @@ -550,8 +548,5 @@ def auto_log_message(context): return _('Edited settings.') return '' -<<<<<<< Updated upstream def content_span(body_class): return body_class.__str__() -======= ->>>>>>> Stashed changes diff --git a/ckan/templates/layout_base.html b/ckan/templates/layout_base.html index f6d5c631aa1..ac61a6fff0c 100644 --- a/ckan/templates/layout_base.html +++ b/ckan/templates/layout_base.html @@ -81,7 +81,7 @@
- +
${h.literal(m)} @@ -264,19 +264,6 @@

Meta

}); - - ${optional_footer()} diff --git a/test-core.ini b/test-core.ini index 4e800b86d8a..3e7fde4831f 100644 --- a/test-core.ini +++ b/test-core.ini @@ -35,7 +35,6 @@ ckan.extra_resource_fields = alt_url # disable this so we can test all types of indexing ckan.build_search_index_synchronously = false -#ckan.restrict_template_vars = true # Add additional test specific configuration options as necessary. auth.blacklist = 83.222.23.234 From 0e79b2736378eb069685dab2a8ae607e40b87a15 Mon Sep 17 00:00:00 2001 From: Toby Date: Tue, 27 Mar 2012 10:32:10 +0100 Subject: [PATCH 05/17] apply stash --- ckan/lib/base.py | 3 ++ ckan/lib/helpers.py | 80 +++++++++++++++++++++++------- ckan/templates/layout_base.html | 6 +-- ckan/templates/package/layout.html | 6 +-- test-core.ini | 1 + 5 files changed, 73 insertions(+), 23 deletions(-) diff --git a/ckan/lib/base.py b/ckan/lib/base.py index cf1ab99b007..23426969d7a 100644 --- a/ckan/lib/base.py +++ b/ckan/lib/base.py @@ -54,6 +54,9 @@ def render_template(): globs = extra_vars or {} globs.update(pylons_globals()) globs['actions'] = model.Action + # add the template name to the context to help us know where we are + # used in depreciating functions etc + c.__template_name = template_name # Using pylons.url() directly destroys the localisation stuff so # we remove it so any bad templates crash and burn diff --git a/ckan/lib/helpers.py b/ckan/lib/helpers.py index 87c62f9617d..14f36f49934 100644 --- a/ckan/lib/helpers.py +++ b/ckan/lib/helpers.py @@ -10,6 +10,7 @@ import re import urllib +from paste.deploy.converters import asbool from webhelpers.html import escape, HTML, literal, url_escape from webhelpers.html.tools import mail_to from webhelpers.html.tags import * @@ -27,6 +28,9 @@ import i18n import ckan.exceptions from pylons import request +from pylons import session +from pylons import c +from pylons.i18n import _ get_available_locales = i18n.get_available_locales get_locales_dict = i18n.get_locales_dict @@ -178,7 +182,7 @@ def __call__(self, message, category=None, ignore_duplicate=False, allow_html=Fa # Don't store Message objects in the session, to avoid unpickling # errors in edge cases. new_message_tuple = (category, message, allow_html) - from pylons import session + #from pylons import session messages = session.setdefault(self.session_key, []) # ``messages`` is a mutable list, so changes to the local variable are # reflected in the session. @@ -193,7 +197,7 @@ def __call__(self, message, category=None, ignore_duplicate=False, allow_html=Fa session.save() def pop_messages(self): - from pylons import session + #from pylons import session messages = session.pop(self.session_key, []) # only save session if it has changed if messages: @@ -201,7 +205,7 @@ def pop_messages(self): return [Message(*m) for m in messages] def are_there_messages(self): - from pylons import session + #from pylons import session return bool(session.get(self.session_key)) _flash = _Flash() @@ -218,8 +222,21 @@ def flash_success(message, allow_html=False): def are_there_flash_messages(): return _flash.are_there_messages() -# FIXME: shouldn't have to pass the c object in to this. -def nav_link(c, text, controller, **kwargs): + + +def nav_link(*args, **kwargs): + # nav_link() used to need c passing as the first arg + # this is depriciated as pointless + # throws error if ckan.restrict_template_vars is True + # When we move to strict helpers then this should be removed as a wrapper + if len(args) > 2 or (len(args) > 1 and 'controller' in kwargs): + if not asbool(config.get('ckan.restrict_template_vars', 'false')): + return _nav_link(*args[1:], **kwargs) + raise Exception('nav_link() calling has been changed. remove c in template %s' % c.__template_name) + return _nav_link(*args, **kwargs) + +def _nav_link(text, controller, **kwargs): + highlight_actions = kwargs.pop("highlight_actions", kwargs["action"]).split() return link_to( @@ -230,7 +247,19 @@ def nav_link(c, text, controller, **kwargs): else '') ) -def nav_named_link(c, text, name, **kwargs): +def nav_named_link(*args, **kwargs): + # subnav_link() used to need c passing as the first arg + # this is depriciated as pointless + # throws error if ckan.restrict_template_vars is True + # When we move to strict helpers then this should be removed as a wrapper + if len(args) > 3 or (len(args) > 1 and 'text' in kwargs) or \ + (len(args) > 2 and 'name' in kwargs): + if not asbool(config.get('ckan.restrict_template_vars', 'false')): + return _nav_named_link(*args[1:], **kwargs) + raise Exception('nav_named_link() calling has been changed. remove c in template %s' % c.__template_name) + return _nav_named_link(*args, **kwargs) + +def _nav_named_link(c, text, name, **kwargs): return link_to( text, url_for(name, **kwargs), @@ -239,15 +268,37 @@ def nav_named_link(c, text, name, **kwargs): # else '') ) -# FIXME: shouldn't have to pass the c object in to this. -def subnav_link(c, text, action, **kwargs): +def subnav_link(*args, **kwargs): + # subnav_link() used to need c passing as the first arg + # this is depriciated as pointless + # throws error if ckan.restrict_template_vars is True + # When we move to strict helpers then this should be removed as a wrapper + if len(args) > 2 or (len(args) > 1 and 'action' in kwargs): + if not asbool(config.get('ckan.restrict_template_vars', 'false')): + return _subnav_link(*args[1:], **kwargs) + raise Exception('subnav_link() calling has been changed. remove c in template %s' % c.__template_name) + return _subnav_link(*args, **kwargs) + +def _subnav_link(text, action, **kwargs): return link_to( text, url_for(action=action, **kwargs), class_=('active' if c.action == action else '') ) -def subnav_named_route(c, text, routename,**kwargs): +def subnav_named_route(*args, **kwargs): + # subnav_link() used to need c passing as the first arg + # this is depriciated as pointless + # throws error if ckan.restrict_template_vars is True + # When we move to strict helpers then this should be removed as a wrapper + if len(args) > 2 or (len(args) > 0 and 'text' in kwargs) or \ + (len(args) > 1 and 'routename' in kwargs): + if not asbool(config.get('ckan.restrict_template_vars', 'false')): + return _subnav_named_route(*args[1:], **kwargs) + raise Exception('subnav_named_route() calling has been changed. remove c in template %s' % c.__template_name) + return _subnav_named_route(*args, **kwargs) + +def _subnav_named_route(text, routename, **kwargs): """ Generate a subnav element based on a named route """ return link_to( text, @@ -256,7 +307,7 @@ def subnav_named_route(c, text, routename,**kwargs): ) def default_group_type(): - from pylons import config + #from pylons import config return str( config.get('ckan.default.group_type', 'group') ) def facet_items(c, name, limit=10): @@ -271,7 +322,7 @@ def facet_items(c, name, limit=10): return sorted(facets, key=lambda (k, v): v, reverse=True)[:limit] def facet_title(name): - from pylons import config + #from pylons import config return config.get('search.facets.%s.title' % name, name.capitalize()) def am_authorized(c, action, domain_object=None): @@ -284,7 +335,6 @@ def am_authorized(c, action, domain_object=None): def check_access(action,data_dict=None): from ckan import model - from ckan.lib.base import c from ckan.logic import check_access as check_access_logic,NotAuthorized context = {'model': model, @@ -300,7 +350,6 @@ def check_access(action,data_dict=None): def linked_user(user, maxlength=0): from ckan import model - from urllib import quote if user in [model.PSEUDO_USER__LOGGED_IN, model.PSEUDO_USER__VISITOR]: return user if not isinstance(user, model.User): @@ -319,7 +368,6 @@ def linked_user(user, maxlength=0): def linked_authorization_group(authgroup, maxlength=0): from ckan import model - from urllib import quote if not isinstance(authgroup, model.AuthorizationGroup): authgroup_name = unicode(authgroup) authgroup = model.AuthorizationGroup.get(authgroup_name) @@ -388,7 +436,7 @@ def linked_gravatar(email_hash, size=100, default=None): _VALID_GRAVATAR_DEFAULTS = ['404', 'mm', 'identicon', 'monsterid', 'wavatar', 'retro'] def gravatar(email_hash, size=100, default=None): if default is None: - from pylons import config + #from pylons import config default = config.get('ckan.gravatar_default', 'identicon') if not default in _VALID_GRAVATAR_DEFAULTS: @@ -535,11 +583,9 @@ def group_link(group): return link_to(group['name'], url) def dump_json(obj): - import json return json.dumps(obj) def auto_log_message(context): - from pylons.i18n import _ if (context.action=='new') : return _('Created new dataset.') elif (context.action=='editresources'): diff --git a/ckan/templates/layout_base.html b/ckan/templates/layout_base.html index ac61a6fff0c..72fffd9f9b2 100644 --- a/ckan/templates/layout_base.html +++ b/ckan/templates/layout_base.html @@ -73,10 +73,10 @@
diff --git a/ckan/templates/package/layout.html b/ckan/templates/package/layout.html index 4f44c2803ac..ae30578002a 100644 --- a/ckan/templates/package/layout.html +++ b/ckan/templates/package/layout.html @@ -38,15 +38,15 @@ -
  • ${h.subnav_link(c, h.icon('page_stack') + _('History'), controller='package', action='history', id=c.pkg.name)}
  • +
  • ${h.subnav_link(h.icon('page_stack') + _('History'), controller='package', action='history', id=c.pkg.name)}
  •   |  
  • - ${h.subnav_link(c, h.icon('package_edit') + _('Settings'), controller='package', action='edit', id=c.pkg.name)} + ${h.subnav_link(h.icon('package_edit') + _('Settings'), controller='package', action='edit', id=c.pkg.name)}
  • - ${h.subnav_link(c, h.icon('lock') + _('Authorization'), controller='package', action='authz', id=c.pkg.name)} + ${h.subnav_link(h.icon('lock') + _('Authorization'), controller='package', action='authz', id=c.pkg.name)}
  • - ${h.subnav_named_route( c,h.icon('group_edit') + _('Edit'), c.group.type + '_action', action='edit', id=c.group.name )} + ${h.subnav_named_route(h.icon('group_edit') + _('Edit'), c.group.type + '_action', action='edit', id=c.group.name )}
  • - ${h.subnav_named_route(c, h.icon('lock') + _('Authorization'), c.group.type + '_action', controller='group', action='authz', id=c.group.name)} + ${h.subnav_named_route(h.icon('lock') + _('Authorization'), c.group.type + '_action', controller='group', action='authz', id=c.group.name)}
  • - ${h.subnav_named_route(c, h.icon('group') + _('List Groups'), "%s_index" % h.default_group_type(), action="index" )} + ${h.subnav_named_route(h.icon('group') + _('List Groups'), "%s_index" % h.default_group_type(), action="index" )}
  • - ${h.subnav_link(c, h.icon('group_add') + _('Login to Add a Group'), controller='group', action='new')} + ${h.subnav_link(h.icon('group_add') + _('Login to Add a Group'), controller='group', action='new')}
  • diff --git a/ckan/templates/home/index.html b/ckan/templates/home/index.html index 1fcc09c9d46..b2da98e6321 100644 --- a/ckan/templates/home/index.html +++ b/ckan/templates/home/index.html @@ -34,7 +34,7 @@

    Share data

    Add your own datasets to share them with others and to find other people interested in your data. - + Create a dataset » Sign up » diff --git a/ckan/templates/layout_base.html b/ckan/templates/layout_base.html index 72fffd9f9b2..f8b4bad1ce8 100644 --- a/ckan/templates/layout_base.html +++ b/ckan/templates/layout_base.html @@ -75,13 +75,13 @@
    - +
    ${h.literal(m)} diff --git a/ckan/templates/package/layout.html b/ckan/templates/package/layout.html index bb47b9df78b..2751557fd0e 100644 --- a/ckan/templates/package/layout.html +++ b/ckan/templates/package/layout.html @@ -7,7 +7,7 @@ diff --git a/ckan/templates/package/new_package_form.html b/ckan/templates/package/new_package_form.html index 8b39047265d..707b9635d6c 100644 --- a/ckan/templates/package/new_package_form.html +++ b/ckan/templates/package/new_package_form.html @@ -257,7 +257,7 @@

    Errors in form

    Briefly describe the changes you have made...

    - +
    diff --git a/ckan/templates/package/read_core.html b/ckan/templates/package/read_core.html index c3c97eb36f7..92a3384ade7 100644 --- a/ckan/templates/package/read_core.html +++ b/ckan/templates/package/read_core.html @@ -25,7 +25,7 @@

    Resources   - ${h.subnav_link(c, _('(edit)'), controller='package', action='editresources', id=c.pkg.name)} + ${h.subnav_link(_('(edit)'), controller='package', action='editresources', id=c.pkg.name)}

      @@ -48,7 +48,7 @@

      Resources

      Additional Information   - ${h.subnav_link(c, _('(settings)'), controller='package', action='edit', id=c.pkg.name)} + ${h.subnav_link(_('(settings)'), controller='package', action='edit', id=c.pkg.name)}

      diff --git a/ckan/templates/revision/layout.html b/ckan/templates/revision/layout.html index e4f032648b3..a5f16a5b084 100644 --- a/ckan/templates/revision/layout.html +++ b/ckan/templates/revision/layout.html @@ -6,10 +6,10 @@ > From 914682506b95643d47b1c49b225de136e5d71c6e Mon Sep 17 00:00:00 2001 From: Toby Date: Wed, 28 Mar 2012 15:50:12 +0100 Subject: [PATCH 14/17] fixes to helpers.py --- ckan/lib/helpers.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ckan/lib/helpers.py b/ckan/lib/helpers.py index f78d95946f0..2e777ca5802 100644 --- a/ckan/lib/helpers.py +++ b/ckan/lib/helpers.py @@ -264,14 +264,14 @@ def nav_named_link(*args, **kwargs): # this is depriciated as pointless # throws error if ckan.restrict_template_vars is True # When we move to strict helpers then this should be removed as a wrapper - if len(args) > 3 or (len(args) > 1 and 'text' in kwargs) or \ - (len(args) > 2 and 'name' in kwargs): + if len(args) > 3 or (len(args) > 0 and 'text' in kwargs) or \ + (len(args) > 1 and 'name' in kwargs): if not asbool(config.get('ckan.restrict_template_vars', 'false')): return _nav_named_link(*args[1:], **kwargs) raise Exception('nav_named_link() calling has been changed. remove c in template %s or included one' % c.__template_name) return _nav_named_link(*args, **kwargs) -def _nav_named_link(c, text, name, **kwargs): +def _nav_named_link(text, name, **kwargs): return link_to( text, url_for(name, **kwargs), From 563376ed6cd97debbdc2c0b131c15c9e1c827f11 Mon Sep 17 00:00:00 2001 From: Toby Date: Wed, 28 Mar 2012 15:51:08 +0100 Subject: [PATCH 15/17] fix facet_items() --- ckan/lib/helpers.py | 15 ++++++++++++++- ckan/templates/facets.html | 10 +++++----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/ckan/lib/helpers.py b/ckan/lib/helpers.py index 2e777ca5802..16b0542da70 100644 --- a/ckan/lib/helpers.py +++ b/ckan/lib/helpers.py @@ -321,7 +321,20 @@ def _subnav_named_route(text, routename, **kwargs): def default_group_type(): return str( config.get('ckan.default.group_type', 'group') ) -def facet_items(c, name, limit=10): + +def facet_items(*args, **kwargs): + # facet_items() used to need c passing as the first arg + # this is depriciated as pointless + # throws error if ckan.restrict_template_vars is True + # When we move to strict helpers then this should be removed as a wrapper + if len(args) > 2 or (len(args) > 0 and 'name' in kwargs) or (len(args) > 1 and 'limit' in kwargs): + if not asbool(config.get('ckan.restrict_template_vars', 'false')): + return _facet_items(*args[1:], **kwargs) + raise Exception('facet_items() calling has been changed. remove c in template %s or included one' % c.__template_name) + return _facet_items(*args, **kwargs) + + +def _facet_items(name, limit=10): if not c.facets or not c.facets.get(name): return [] facets = [] diff --git a/ckan/templates/facets.html b/ckan/templates/facets.html index aa47b6d1e22..f50ac3b662f 100644 --- a/ckan/templates/facets.html +++ b/ckan/templates/facets.html @@ -6,17 +6,17 @@ > -
      +

      ${title(code)}

      -

      ${if_empty}

      +

      ${if_empty}

      @@ -30,8 +30,8 @@

      ${title(code)}

      If if_empty is not None and there are no facets to filter on, then a single
    • element is generated, with the text specified by if_empty --> -
    • ${if_empty}
    • -
    • ${if_empty}
    • +
    • ${label(name)} (${count})
    • From 80476272950a2d41f0206435577acb010e88c8f7 Mon Sep 17 00:00:00 2001 From: Toby Date: Wed, 28 Mar 2012 16:22:12 +0100 Subject: [PATCH 16/17] helpers.py more cleanups and added some doc strings --- ckan/lib/helpers.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/ckan/lib/helpers.py b/ckan/lib/helpers.py index 16b0542da70..ff837a08883 100644 --- a/ckan/lib/helpers.py +++ b/ckan/lib/helpers.py @@ -143,6 +143,7 @@ def _add_i18n_to_url(url_to_amend, **kw): return url def lang(): + ''' Reurn the language code for the current locale eg `en` ''' return request.environ.get('CKAN_LANG') class Message(object): @@ -220,18 +221,23 @@ def are_there_messages(self): return bool(session.get(self.session_key)) flash = _Flash() +# this is here for backwards compatability _flash = flash def flash_notice(message, allow_html=False): + ''' Show a flash message of type notice ''' flash(message, category='alert-info', allow_html=allow_html) def flash_error(message, allow_html=False): + ''' Show a flash message of type error ''' flash(message, category='alert-error', allow_html=allow_html) def flash_success(message, allow_html=False): + ''' Show a flash message of type success ''' flash(message, category='alert-success', allow_html=allow_html) def are_there_flash_messages(): + ''' Returns True if there are flash messages for the current user ''' return flash.are_there_messages() @@ -356,7 +362,7 @@ def am_authorized(c, action, domain_object=None): domain_object = model.System() return Authorizer.am_authorized(c, action, domain_object) -def check_access(action,data_dict=None): +def check_access(action, data_dict=None): from ckan import model from ckan.logic import check_access as check_access_logic,NotAuthorized @@ -459,7 +465,6 @@ def linked_gravatar(email_hash, size=100, default=None): _VALID_GRAVATAR_DEFAULTS = ['404', 'mm', 'identicon', 'monsterid', 'wavatar', 'retro'] def gravatar(email_hash, size=100, default=None): if default is None: - #from pylons import config default = config.get('ckan.gravatar_default', 'identicon') if not default in _VALID_GRAVATAR_DEFAULTS: @@ -538,7 +543,7 @@ def parse_rfc_2822_date(date_str, tz_aware=True): Returns None if the string cannot be parse as a valid datetime. """ time_tuple = email.utils.parsedate_tz(date_str) - + if not time_tuple: return None From a89bba5b07abb87bca82a6d997754e2332ff0977 Mon Sep 17 00:00:00 2001 From: Toby Date: Wed, 28 Mar 2012 16:59:21 +0100 Subject: [PATCH 17/17] add some documentation for new config option --- doc/configuration.rst | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/doc/configuration.rst b/doc/configuration.rst index bc62dab5668..4cb3ee2de6f 100644 --- a/doc/configuration.rst +++ b/doc/configuration.rst @@ -660,3 +660,21 @@ Example:: This is a directory where SQL database backups are to be written, assuming a script has been installed to do this. + + +Compatability +------------- + +.. index:: + single: restrict_template_vars + +restrict_template_vars +^^^^^^^^^^^^^^^^^^^^^^ + +Example:: + + ckan.restrict_template_vars = true + +Default value: ``false`` + +This is used to limit the functions available via h in templates. It also forces correct usage of functions as some function signatures have changed. It's main purpose is to allow transition to a cleaner world.