[ckan-changes] [okfn/ckan] 82fe9f: [xs] bug fix: tag_name and tag_length validators a...
GitHub
noreply at github.com
Mon Apr 23 14:40:45 UTC 2012
Branch: refs/heads/master
Home: https://github.com/okfn/ckan
Commit: 82fe9f1ed5cd190156a2540bc4f4902f21cc0b7b
https://github.com/okfn/ckan/commit/82fe9f1ed5cd190156a2540bc4f4902f21cc0b7b
Author: John Glover <j at johnglover.net>
Date: 2012-04-23 (Mon, 23 Apr 2012)
Changed paths:
M ckan/logic/converters.py
Log Message:
-----------
[xs] bug fix: tag_name and tag_length validators are not necessary in fixed vocabs (tags should be checked when being added to the vocab so no need to recheck).
diff --git a/ckan/logic/converters.py b/ckan/logic/converters.py
index 5de75a7..6b927ae 100644
--- a/ckan/logic/converters.py
+++ b/ckan/logic/converters.py
@@ -60,13 +60,11 @@ def callable(key, data, errors, context):
context['vocabulary'] = v
for tag in new_tags:
- tag_length_validator(tag, context)
- tag_name_validator(tag, context)
tag_in_vocabulary_validator(tag, context)
for num, tag in enumerate(new_tags):
- data[('tags', num+n, 'name')] = tag
- data[('tags', num+n, 'vocabulary_id')] = v.id
+ data[('tags', num + n, 'name')] = tag
+ data[('tags', num + n, 'vocabulary_id')] = v.id
return callable
def convert_from_tags(vocab):
================================================================
Commit: f4f506c85dd1faffbfede363204cfd8ca8f31a14
https://github.com/okfn/ckan/commit/f4f506c85dd1faffbfede363204cfd8ca8f31a14
Author: John Glover <j at johnglover.net>
Date: 2012-04-23 (Mon, 23 Apr 2012)
Changed paths:
M ckan/config/environment.py
M ckan/lib/helpers.py
R ckan/lib/helpers_clean.py
M ckan/plugins/toolkit.py
M ckan/tests/functional/test_cors.py
M requires/lucid_missing.txt
Log Message:
-----------
Merge remote-tracking branch 'origin/master'
diff --git a/ckan/config/environment.py b/ckan/config/environment.py
index d5b91e4..8d42f4b 100644
--- a/ckan/config/environment.py
+++ b/ckan/config/environment.py
@@ -1,31 +1,85 @@
"""Pylons environment configuration"""
import os
-from urlparse import urlparse
import logging
import warnings
-
-from paste.deploy.converters import asbool
-
-# Suppress benign warning 'Unbuilt egg for setuptools'
-warnings.simplefilter('ignore', UserWarning)
-
+from urlparse import urlparse
import pylons
+from paste.deploy.converters import asbool
import sqlalchemy
-
from pylons import config
-from pylons.i18n.translation import ugettext
from genshi.template import TemplateLoader
from genshi.filters.i18n import Translator
-from paste.deploy.converters import asbool
-import ckan.lib.app_globals as app_globals
+import ckan.config.routing as routing
+import ckan.model as model
+import ckan.plugins as p
import ckan.lib.helpers as h
-from ckan.config.routing import make_map
-from ckan import model
-from ckan import plugins
+import ckan.lib.search as search
+import ckan.lib.app_globals as app_globals
+# Suppress benign warning 'Unbuilt egg for setuptools'
+warnings.simplefilter('ignore', UserWarning)
+
+class _Helpers(object):
+ ''' Helper object giving access to template helpers stopping
+ missing functions from causing template exceptions. Useful if
+ templates have helper functions provided by extensions that have
+ not been enabled. '''
+ def __init__(self, helpers, restrict=True):
+ functions = {}
+ allowed = helpers.__allowed_functions__
+ # list of functions due to be depreciated
+ self.depreciated = []
+
+ for helper in dir(helpers):
+ if helper not in allowed:
+ self.depreciated.append(helper)
+ if restrict:
+ continue
+ functions[helper] = getattr(helpers, helper)
+ self.functions = functions
+
+ # extend helper functions with ones supplied by plugins
+ extra_helpers = []
+ for plugin in p.PluginImplementations(p.ITemplateHelpers):
+ helpers = plugin.get_helpers()
+ for helper in helpers:
+ if helper in extra_helpers:
+ raise Exception('overwritting extra helper %s' % helper)
+ extra_helpers.append(helper)
+ functions[helper] = helpers[helper]
+ # logging
+ self.log = logging.getLogger('ckan.helpers')
+
+ @classmethod
+ def null_function(cls, *args, **kw):
+ ''' This function is returned if no helper is found. The idea is
+ to try to allow templates to be rendered even if helpers are
+ missing. Returning the empty string seems to work well.'''
+ return ''
+
+ def __getattr__(self, name):
+ ''' return the function/object requested '''
+ if name in self.functions:
+ if name in self.depreciated:
+ msg = 'Template helper function `%s` is depriciated' % name
+ self.log.warn(msg)
+ return self.functions[name]
+ else:
+ if name in self.depreciated:
+ msg = 'Template helper function `%s` is not available ' \
+ 'as it has been depriciated.\nYou can enable it ' \
+ 'by setting ckan.restrict_template_vars = true ' \
+ 'in your .ini file.' % name
+ self.log.critical(msg)
+ else:
+ msg = 'Helper function `%s` could not be found\n ' \
+ '(are you missing an extension?)' % name
+ self.log.critical(msg)
+ return self.null_function
+
def load_environment(global_conf, app_conf):
"""Configure the Pylons environment via the ``pylons.config``
@@ -65,12 +119,9 @@ def find_controller(self, controller):
config.init_app(global_conf, app_conf, package='ckan', paths=paths)
# load all CKAN plugins
- plugins.load_all(config)
+ p.load_all(config)
- from ckan.plugins import PluginImplementations
- from ckan.plugins.interfaces import IConfigurer
-
- for plugin in PluginImplementations(IConfigurer):
+ for plugin in p.PluginImplementations(p.IConfigurer):
# must do update in place as this does not work:
# config = plugin.update_config(config)
plugin.update_config(config)
@@ -90,33 +141,19 @@ def find_controller(self, controller):
config['ckan.site_id'] = ckan_host
# Init SOLR settings and check if the schema is compatible
- from ckan.lib.search import SolrSettings, check_solr_schema_version
- SolrSettings.init(config.get('solr_url'),
- config.get('solr_user'),
- config.get('solr_password'))
- check_solr_schema_version()
+ #from ckan.lib.search import SolrSettings, check_solr_schema_version
+ search.SolrSettings.init(config.get('solr_url'),
+ config.get('solr_user'),
+ config.get('solr_password'))
+ search.check_solr_schema_version()
- config['routes.map'] = make_map()
+ config['routes.map'] = routing.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
-
- # extend helper functions with ones supplied by plugins
- from ckan.plugins import PluginImplementations
- from ckan.plugins.interfaces import ITemplateHelpers
-
- extra_helpers = []
- for plugin in PluginImplementations(ITemplateHelpers):
- helpers = plugin.get_helpers()
- for helper in helpers:
- if helper in extra_helpers:
- raise Exception('overwritting extra helper %s' % helper)
- extra_helpers.append(helper)
- setattr(config['pylons.h'], helper, helpers[helper])
+ # add helper functions
+ restrict_helpers = asbool(config.get('ckan.restrict_template_vars', 'false'))
+ helpers = _Helpers(h, restrict_helpers)
+ config['pylons.h'] = helpers
## redo template setup to use genshi.search_path (so remove std template setup)
template_paths = [paths['templates'][0]]
@@ -157,9 +194,6 @@ def template_loaded(template):
if not model.meta.engine:
model.init_model(engine)
- from ckan.plugins import PluginImplementations
- from ckan.plugins.interfaces import IConfigurable
-
- for plugin in PluginImplementations(IConfigurable):
+ for plugin in p.PluginImplementations(p.IConfigurable):
plugin.configure(config)
diff --git a/ckan/lib/helpers.py b/ckan/lib/helpers.py
index 16de030..dfdc0a8 100644
--- a/ckan/lib/helpers.py
+++ b/ckan/lib/helpers.py
@@ -743,3 +743,67 @@ def process_names(items):
item = converter(obj, context)
items.append(item)
return items
+
+
+# these are the functions that will end up in `h` template helpers
+# if config option restrict_template_vars is true
+__allowed_functions__ = [
+ # functions defined in ckan.lib.helpers
+ 'redirect_to',
+ 'url',
+ 'url_for',
+ 'url_for_static',
+ 'lang',
+ 'flash',
+ 'flash_error',
+ 'flash_notice',
+ 'flash_success',
+ 'nav_link',
+ 'nav_named_link',
+ 'subnav_link',
+ 'subnav_named_route',
+ 'default_group_type',
+ 'facet_items',
+ 'facet_title',
+ # am_authorized, # depreciated
+ 'check_access',
+ 'linked_user',
+ 'linked_authorization_group',
+ 'group_name_to_title',
+ 'markdown_extract',
+ 'icon',
+ 'icon_html',
+ 'icon_url',
+ 'resource_icon',
+ 'format_icon',
+ 'linked_gravatar',
+ 'gravatar',
+ 'pager_url',
+ 'render_datetime',
+ 'date_str_to_datetime',
+ 'datetime_to_date_str',
+ 'parse_rfc_2822_date',
+ 'time_ago_in_words_from_str',
+ 'button_attr',
+ 'dataset_display_name',
+ 'dataset_link',
+ 'resource_display_name',
+ 'resource_link',
+ 'tag_link',
+ 'group_link',
+ 'dump_json',
+ 'auto_log_message',
+ 'snippet',
+ 'convert_to_dict',
+ 'activity_div',
+ # imported into ckan.lib.helpers
+ 'literal',
+ 'link_to',
+ 'get_available_locales',
+ 'get_locales_dict',
+ 'truncate',
+ 'file',
+ 'mail_to',
+ 'radio',
+ 'submit',
+]
diff --git a/ckan/lib/helpers_clean.py b/ckan/lib/helpers_clean.py
deleted file mode 100644
index 8cef519..0000000
--- a/ckan/lib/helpers_clean.py
+++ /dev/null
@@ -1,120 +0,0 @@
-''' This file is part of a plan to clean up the ckan.lib.helpers whilst
-keeping existing versions of ckan from breaking.
-
-
-When it is decided that we will make the template var cleanup
-permanent we will need to implement this using __all__ = [...] in
-lib.helpers itself. Unused imports can also be removed at this time.
-
-yes, yes `from ... import ...` is the work of Satan but this is just a
-short term botch :)
-
-'''
-
-
-from ckan.lib.helpers import (
- # functions defined in ckan.lib.helpers
- redirect_to,
- url,
- url_for,
- url_for_static,
- lang,
- flash,
- flash_error,
- flash_notice,
- flash_success,
- nav_link,
- nav_named_link,
- subnav_link,
- subnav_named_route,
- default_group_type,
- unselected_facet_items,
- facet_items,
- facet_title,
- # am_authorized, # depreciated
- check_access,
- linked_user,
- linked_authorization_group,
- group_name_to_title,
- markdown_extract,
- icon,
- icon_html,
- icon_url,
- resource_icon,
- format_icon,
- linked_gravatar,
- gravatar,
- pager_url,
- render_datetime,
- date_str_to_datetime,
- datetime_to_date_str,
- parse_rfc_2822_date,
- time_ago_in_words_from_str,
- button_attr,
- dataset_display_name,
- dataset_link,
- resource_display_name,
- resource_link,
- tag_link,
- group_link,
- dump_json,
- auto_log_message,
- snippet,
- convert_to_dict,
- activity_div,
- # imported into ckan.lib.helpers
- literal,
- link_to,
- get_available_locales,
- get_locales_dict,
- truncate,
- file,
- mail_to,
- radio,
- submit,
-)
-
-
-# these are potentially used by templates but hopefully are not
-imported_functions = [
- 'are_there_flash_messages',
- 'auto_discovery_link',
- # 'beaker_cache',
- 'checkbox',
- # 'ckan',
- # 'config',
- 'convert_boolean_attrs',
- 'css_classes',
- 'date',
- 'datetime',
- 'email',
- 'end_form',
- 'escape',
- 'form',
- 'fromstring',
- 'hidden',
- 'i18n',
- 'image',
- 'javascript_link',
- 'json',
- 'link_to_if',
- 'link_to_unless',
- 'markdown',
- 'ol',
- 'paginate',
- 'password',
- # 're',
- 'request',
- 'required_legend',
- 'select',
- 'stylesheet_link',
- 'text',
- 'textarea',
- 'th_sortable',
- 'title',
- 'ul',
- 'url_escape',
- 'urllib',
- 'xml_declaration',
-]
-
diff --git a/ckan/plugins/toolkit.py b/ckan/plugins/toolkit.py
index 3eb8983..671449e 100644
--- a/ckan/plugins/toolkit.py
+++ b/ckan/plugins/toolkit.py
@@ -40,7 +40,7 @@ class _Toolkit(object):
'literal', # stop tags in a string being escaped
'get_action', # get logic action function
'check_access', # check logic function authorisation
- 'ActionNotFound', # action not found exception (ckan.logic.NotFound)
+ 'ObjectNotFound', # action not found exception (ckan.logic.NotFound)
'NotAuthorized', # action not authorized exception
'ValidationError', # model update validation error
'CkanCommand', # class for providing cli interfaces
@@ -85,7 +85,7 @@ def _initialize(self):
t['get_action'] = logic.get_action
t['check_access'] = logic.check_access
- t['ActionNotFound'] = logic.NotFound ## Name change intentional
+ t['ObjectNotFound'] = logic.NotFound ## Name change intentional
t['NotAuthorized'] = logic.NotAuthorized
t['ValidationError'] = logic.ValidationError
diff --git a/ckan/tests/functional/test_cors.py b/ckan/tests/functional/test_cors.py
index daa4d4e..b69ff1e 100644
--- a/ckan/tests/functional/test_cors.py
+++ b/ckan/tests/functional/test_cors.py
@@ -18,6 +18,6 @@ def test_headers(self):
headers = dict(out.headers)
print headers
assert headers['Access-Control-Allow-Origin'] == '*'
- assert headers['Access-Control-Allow-Methods'] == "POST, PUT, GET, DELETE"
- assert headers['Access-Control-Allow-Headers'] == "X-CKAN-API-KEY, Content-Type"
+ assert headers['Access-Control-Allow-Methods'] == "POST, PUT, GET, DELETE, OPTIONS"
+ assert headers['Access-Control-Allow-Headers'] == "X-CKAN-API-KEY, Authorization, Content-Type"
diff --git a/requires/lucid_missing.txt b/requires/lucid_missing.txt
index 8b5789e..dccb362 100644
--- a/requires/lucid_missing.txt
+++ b/requires/lucid_missing.txt
@@ -20,3 +20,4 @@ ofs==0.4.1
apachemiddleware==0.1.1
# markupsafe is required by webhelpers==1.2 required by formalchemy with SQLAlchemy 0.6
markupsafe==0.9.2
+celery==2.5.3
================================================================
Compare: https://github.com/okfn/ckan/compare/4003dd9...f4f506c
More information about the ckan-changes
mailing list