Skip to content

Commit

Permalink
stash apply
Browse files Browse the repository at this point in the history
  • Loading branch information
tobes committed Mar 26, 2012
1 parent 53991fc commit 2cdc994
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 8 deletions.
9 changes: 7 additions & 2 deletions ckan/config/environment.py
Expand Up @@ -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
Expand Down Expand Up @@ -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]]
Expand Down
22 changes: 22 additions & 0 deletions ckan/config/middleware.py
@@ -1,5 +1,6 @@
"""Pylons middleware initialization"""
import urllib
import urllib2
import logging
import json

Expand Down Expand Up @@ -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"""
Expand Down
5 changes: 5 additions & 0 deletions ckan/lib/base.py
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
15 changes: 10 additions & 5 deletions ckan/lib/helpers.py
Expand Up @@ -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()``.
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
15 changes: 14 additions & 1 deletion ckan/templates/layout_base.html
Expand Up @@ -81,7 +81,7 @@
</div>
</header>
</div>
<py:with vars="messages = list(h._flash.pop_messages())">
<py:with vars="messages = list(h.flash.pop_messages())">
<div class="flash-messages container">
<div class="alert ${m.category}" py:for="m in messages">
${h.literal(m)}
Expand Down Expand Up @@ -264,6 +264,19 @@ <h3 class="widget-title">Meta</h3>
});
</script>

<script type="text/javascript">
$(function (){
// Tracking
$.post('/_tracking', {url:location.pathname, type:'page'})
});
$('a.resource-url-analytics').click(function (e){
var url = $(e.target).closest('a').attr('href');
$.post('/_tracking', {url:url, type:'resource'},
function () {location.href = url;})
e.preventDefault();
});
</script>

<py:if test="defined('optional_footer')">
${optional_footer()}
</py:if>
Expand Down
1 change: 1 addition & 0 deletions test-core.ini
Expand Up @@ -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
Expand Down

0 comments on commit 2cdc994

Please sign in to comment.