Skip to content

Commit

Permalink
[#3229] Migrate the snippet endpoint
Browse files Browse the repository at this point in the history
As it is used on the frontend tests.

Pass the extra_vars to templates when rendering on Flask
  • Loading branch information
amercader committed Sep 12, 2016
1 parent 6d6a430 commit fd02687
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ckan/lib/base.py
Expand Up @@ -185,7 +185,7 @@ def set_pylons_response_headers(allow_cache):
try:
# TODO: investigate and test this properly
if is_flask_request():
return flask_render_template(template_name)
return flask_render_template(template_name, **extra_vars)
else:
return cached_template(template_name, render_template)

Expand Down
11 changes: 11 additions & 0 deletions ckan/views/api.py
Expand Up @@ -10,6 +10,7 @@
import ckan.model as model
from ckan.common import json, _, g, request
from ckan.lib.helpers import url_for
from ckan.lib.base import render

from ckan.lib.navl.dictization_functions import DataError
from ckan.logic import get_action, ValidationError, NotFound, NotAuthorized
Expand Down Expand Up @@ -656,6 +657,15 @@ def organization_autocomplete(ver=API_REST_DEFAULT_VERSION):
return _finish_ok(organization_list)


def snippet(snippet_path, ver=API_REST_DEFAULT_VERSION):
u'''Renders and returns a snippet used by ajax calls
We only allow snippets in templates/ajax_snippets and its subdirs
'''
snippet_path = u'ajax_snippets/' + snippet_path
return render(snippet_path, extra_vars=dict(request.args))


def i18n_js_translations(lang, ver=API_REST_DEFAULT_VERSION):
ckan_path = os.path.join(os.path.dirname(__file__), u'..')
source = os.path.abspath(os.path.join(ckan_path, u'public',
Expand Down Expand Up @@ -738,6 +748,7 @@ def i18n_js_translations(lang, ver=API_REST_DEFAULT_VERSION):
(u'/util/group/autocomplete', group_autocomplete),
(u'/util/organization/autocomplete', organization_autocomplete),
(u'/util/resource/format_autocomplete', format_autocomplete),
(u'/util/snippet/<snippet_path>', snippet),
(u'/i18n/<lang>', i18n_js_translations),
]

Expand Down

0 comments on commit fd02687

Please sign in to comment.