[ckan-changes] [okfn/ckan] 31084c: Merge branch 'master' of https://github.com/okfn/c...
GitHub
noreply at github.com
Thu Apr 19 16:04:08 UTC 2012
Branch: refs/heads/feature-2302-simple-theming
Home: https://github.com/okfn/ckan
Commit: 31084c9bf0dffc02f4b6996ea15e26860f485f4c
https://github.com/okfn/ckan/commit/31084c9bf0dffc02f4b6996ea15e26860f485f4c
Author: Ross Jones <rossdjones at gmail.com>
Date: 2012-04-19 (Thu, 19 Apr 2012)
Changed paths:
M ckan/lib/base.py
M ckan/lib/helpers.py
M ckan/plugins/__init__.py
A ckan/plugins/toolkit.py
Log Message:
-----------
Merge branch 'master' of https://github.com/okfn/ckan
diff --git a/ckan/lib/base.py b/ckan/lib/base.py
index 30914ba..da9d69f 100644
--- a/ckan/lib/base.py
+++ b/ckan/lib/base.py
@@ -47,9 +47,29 @@ def abort(status_code=None, detail='', headers=None, comment=None):
headers=headers,
comment=comment)
+
+def render_snippet(template_name, **kw):
+ ''' Helper function for rendering snippets. Rendered html has
+ comment tags added to show the template used. NOTE: unlike other
+ render functions this takes a list of keywords instead of a dict for
+ the extra template variables. '''
+ output = render(template_name, extra_vars=kw)
+ output = '\n<!-- Snippet %s start -->\n%s\n<!-- Snippet %s end -->\n' % (
+ template_name, output, template_name)
+ return literal(output)
+
+def render_text(template_name, extra_vars=None):
+ ''' Helper function to render a genshi NewTextTemplate without
+ having to pass the loader_class or method. '''
+ return render(template_name,
+ extra_vars=extra_vars,
+ method='text',
+ loader_class=NewTextTemplate)
+
def render(template_name, extra_vars=None, cache_key=None, cache_type=None,
cache_expire=None, method='xhtml', loader_class=MarkupTemplate,
cache_force = None):
+ ''' Main genshi template rendering function. '''
def render_template():
globs = extra_vars or {}
diff --git a/ckan/lib/helpers.py b/ckan/lib/helpers.py
index b0fefe1..b4dd06e 100644
--- a/ckan/lib/helpers.py
+++ b/ckan/lib/helpers.py
@@ -31,9 +31,6 @@
from pylons import session
from pylons import c
from pylons.i18n import _
-from pylons.templating import pylons_globals
-from genshi.template import MarkupTemplate
-from ckan.plugins import PluginImplementations, IGenshiStreamFilter
get_available_locales = i18n.get_available_locales
get_locales_dict = i18n.get_locales_dict
@@ -675,20 +672,8 @@ def activity_div(template, activity, actor, object=None, target=None):
def snippet(template_name, **kw):
''' This function is used to load html snippets into pages. keywords
can be used to pass parameters into the snippet rendering '''
- pylons_globs = pylons_globals()
- genshi_loader = pylons_globs['app_globals'].genshi_loader
- template = genshi_loader.load(template_name, cls=MarkupTemplate)
- globs = kw
- globs['h'] = pylons_globs['h']
- globs['c'] = pylons_globs['c']
- globs['config'] = pylons_globs['config']
- stream = template.generate(**globs)
- for item in PluginImplementations(IGenshiStreamFilter):
- stream = item.filter(stream)
- output = stream.render(method='xhtml', encoding=None, strip_whitespace=True)
- output = '\n<!-- Snippet %s start -->\n%s\n<!-- Snippet %s end -->\n' % (
- template_name, output, template_name)
- return literal(output)
+ import ckan.lib.base as base
+ return base.render_snippet(template_name, **kw)
def convert_to_dict(object_type, objs):
diff --git a/ckan/plugins/__init__.py b/ckan/plugins/__init__.py
index 3784b59..fcb6055 100644
--- a/ckan/plugins/__init__.py
+++ b/ckan/plugins/__init__.py
@@ -1,2 +1,3 @@
from ckan.plugins.core import *
from ckan.plugins.interfaces import *
+import toolkit
diff --git a/ckan/plugins/toolkit.py b/ckan/plugins/toolkit.py
new file mode 100644
index 0000000..64a80d7
--- /dev/null
+++ b/ckan/plugins/toolkit.py
@@ -0,0 +1,75 @@
+## This file is intended to make functions consistently available to
+## plugins whilst giving developers the ability move code around or
+## change underlying frameworks etc. It should not be used internaly
+## within ckan only by extensions. Functions should only be removed from
+## this file after reasonable depreciation notice has been given.
+
+import inspect
+import os
+
+import pylons
+import paste.deploy.converters as converters
+import webhelpers.html.tags
+
+import lib.base as base
+
+
+__all__ = [
+ ## Imported functions ##
+ 'c', # template context
+ 'request', # http request object
+ 'render', # template render function
+ 'render_text', # Genshi NewTextTemplate render function
+ 'render_snippet', # snippet render function
+ 'asbool', # converts an object to a boolean
+ 'asint', # converts an object to an integer
+ 'aslist', # converts an object to a list
+ 'literal', # stop tags in a string being escaped
+
+ ## Functions fully defined here ##
+ 'add_template_directory',
+ 'add_public_directory',
+]
+
+c = pylons.c
+request = pylons.request
+render = base.render
+render_text = base.render_text
+asbool = converters.asbool
+asint = converters.asint
+aslist = converters.aslist
+literal = webhelpers.html.tags.literal
+
+
+# wrappers
+def render_snippet(template, data=None):
+ data = data or {}
+ return base.render_snippet(template, **data)
+
+
+# new functions
+def add_template_directory(config, relative_path):
+ ''' Function to aid adding extra template paths to the config.
+ The path is relative to the file calling this function. '''
+ _add_served_directory(config, relative_path, 'extra_template_paths')
+
+def add_public_directory(config, relative_path):
+ ''' Function to aid adding extra public paths to the config.
+ The path is relative to the file calling this function. '''
+ _add_served_directory(config, relative_path, 'extra_public_paths')
+
+def _add_served_directory(config, relative_path, config_var):
+ ''' Add extra public/template directories to config. '''
+ assert config_var in ('extra_template_paths', 'extra_public_paths')
+ # we want the filename that of the function caller but they will
+ # have used one of the available helper functions
+ frame, filename, line_number, function_name, lines, index =\
+ inspect.getouterframes(inspect.currentframe())[2]
+
+ this_dir = os.path.dirname(filename)
+ absolute_path = os.path.join(this_dir, relative_path)
+ if absolute_path not in config.get(config_var, ''):
+ if config.get(config_var):
+ config[config_var] += ',' + absolute_path
+ else:
+ config[config_var] = absolute_path
================================================================
Commit: 312a2bdae853ebe55dd67b2771671d1fa04ae018
https://github.com/okfn/ckan/commit/312a2bdae853ebe55dd67b2771671d1fa04ae018
Author: Ross Jones <rossdjones at gmail.com>
Date: 2012-04-19 (Thu, 19 Apr 2012)
Changed paths:
M ckan/config/routing.py
A ckan/controllers/settings.py
A ckan/templates/settings/index.html
Log Message:
-----------
[2302] Initial template and controller
diff --git a/ckan/config/routing.py b/ckan/config/routing.py
index f3ae5b8..9835480 100644
--- a/ckan/config/routing.py
+++ b/ckan/config/routing.py
@@ -151,6 +151,9 @@ def make_map():
##map.connect('/package/new', controller='package_formalchemy', action='new')
##map.connect('/package/edit/{id}', controller='package_formalchemy', action='edit')
+ with SubMapper(map, controller='settings') as m:
+ m.connect('/settings', action='index')
+
with SubMapper(map, controller='package') as m:
m.connect('/dataset', action='search')
m.connect('/dataset/{action}',
diff --git a/ckan/controllers/settings.py b/ckan/controllers/settings.py
new file mode 100644
index 0000000..aecabc6
--- /dev/null
+++ b/ckan/controllers/settings.py
@@ -0,0 +1,23 @@
+import random
+
+from pylons.i18n import set_lang
+import sqlalchemy.exc
+
+import ckan.authz as authz
+
+import ckan.logic as logic
+from ckan.lib.base import *
+from ckan.lib.helpers import url_for
+
+
+class SettingsController(BaseController):
+ repo = model.repo
+
+ def __before__(self, action, **env):
+ BaseController.__before__(self, action, **env)
+ if not authz.Authorizer.is_sysadmin(c.user):
+ abort(401, _('Not authorized to see this page'))
+
+ def index(self):
+ return render('settings/index.html', cache_force=True)
+
diff --git a/ckan/templates/settings/index.html b/ckan/templates/settings/index.html
new file mode 100644
index 0000000..3981535
--- /dev/null
+++ b/ckan/templates/settings/index.html
@@ -0,0 +1,91 @@
+<html xmlns:py="http://genshi.edgewall.org/"
+ xmlns:i18n="http://genshi.edgewall.org/i18n"
+ xmlns:xi="http://www.w3.org/2001/XInclude"
+ py:strip="">
+
+ <py:def function="page_title">Settings</py:def>
+ <py:def function="page_heading">Site settings</py:def>
+
+ <py:match path="primarysidebar">
+ <li class="widget-container boxed widget_text">
+ <h3>Site settings</h3>
+ <p i18n:msg="">
+ As a system administrator you are allowed to change the site title, tagline, image and
+ some of the key presentation elements within the site.
+ </p>
+ <p i18n:msg="">
+ This form allows you to change the settings which will take effect immediately on update.
+ </p>
+ </li>
+ </py:match>
+
+ <div py:match="content">
+ <form class="form-horizontal well">
+ <fieldset>
+ <legend>Settings</legend>
+ <div class="control-group">
+ <label class="control-label" for="input01">Logo url</label>
+ <div class="controls">
+ <div class="input-prepend">
+ <span class='add-on'>http://</span><input type="text" class="input-xlarge" id="input01"/>
+ </div>
+ <p class="help-block">The image loaded from this URL should be 145x120 px</p>
+ </div>
+ </div>
+
+ <div class="control-group">
+ <label class="control-label" for="input01">Site name</label>
+ <div class="controls">
+ <input type="text" class="input-xlarge" id="input01"/>
+ </div>
+ </div>
+ <div class="control-group">
+ <label class="control-label" for="input01">Tag line</label>
+ <div class="controls">
+ <input type="text" class="input-xlarge" id="input01"/>
+ </div>
+ </div>
+
+ </fieldset>
+ <fieldset>
+ <legend>CSS</legend>
+ <div class="control-group">
+ <label class="control-label" for="input01">Header background</label>
+ <div class="controls">
+ <div class="input-prepend">
+ <span class='add-on'>#</span><input type="text" class="input-xlarge" id="input01"/>
+ </div>
+ <p class="help-block">The CSS hex value for the header</p>
+ </div>
+ </div>
+
+ <div class="control-group">
+ <label class="control-label" for="input01">Background</label>
+ <div class="controls">
+ <div class="input-prepend">
+ <span class='add-on'>#</span><input type="text" class="input-xlarge" id="input01"/>
+ </div>
+ <p class="help-block">The CSS hex value for the main background</p>
+ </div>
+ </div>
+
+ <div class="control-group">
+ <label class="control-label" for="input01">Footer background</label>
+ <div class="controls">
+ <div class="input-prepend">
+ <span class='add-on'>#</span><input type="text" class="input-xlarge" id="input01"/>
+ </div>
+ <p class="help-block">The CSS hex value for the footer</p>
+ </div>
+ </div>
+ </fieldset>
+
+ <div class="form-actions">
+ <button type="submit" class="btn btn-primary">Save changes</button>
+ <button class="btn">Cancel</button>
+ </div>
+ </form>
+ </div>
+
+ <xi:include href="../layout.html" />
+</html>
================================================================
Compare: https://github.com/okfn/ckan/compare/31084c9^...312a2bd
More information about the ckan-changes
mailing list