Skip to content

Commit

Permalink
Provide a fake pylons environment so logic layer works..
Browse files Browse the repository at this point in the history
  • Loading branch information
rossjones committed Sep 4, 2015
1 parent 54a9382 commit 44edc4f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
27 changes: 22 additions & 5 deletions ckan/ckan_app.py
Expand Up @@ -6,18 +6,32 @@
registry = None
translator_obj = None

def register_translator():
# Register a translator in this thread so that
# the _() functions in logic layer can work
def fake_pylons():
import pylons
from pylons.util import ContextObj, PylonsContext

from paste.registry import Registry
from pylons import translator
from ckan.lib.cli import MockTranslator

global registry
global translator_obj

c = pylons.util.AttribSafeContextObj()

registry=Registry()
registry.prepare()
global translator_obj

translator_obj=MockTranslator()

registry.register(translator, translator_obj)
registry.register(pylons.c, c)


def unfake_pylons(response):
import pylons
pylons.tmpl_context._pop_object()
return response


def create_app():
Expand All @@ -26,7 +40,10 @@ def create_app():
app.debug = True

app.before_request_funcs = {
None: [register_translator]
None: [fake_pylons]
}
app.after_request_funcs = {
None: [unfake_pylons]
}

##############################################################################
Expand Down
6 changes: 3 additions & 3 deletions ckan/controllers/flapi.py
@@ -1,8 +1,8 @@
import logging
import json

import ckan.model as model
import ckan.logic as logic
from ckan.common import json, _, ungettext, c

from flask import abort, jsonify, request, Response
from flask.views import MethodView
Expand All @@ -21,11 +21,11 @@ def get(self, func_name):
except Exception, e:
abort(404)

params = request.args
params = request.args.copy()

# TODO: Check and pop callback

context = {'model':model, 'session': model.Session, 'user': ''}
context = {'model':model, 'session': model.Session, 'user': c.user}
try:
response = fn(context, params)
except logic.ValidationError, e:
Expand Down

0 comments on commit 44edc4f

Please sign in to comment.