-
Notifications
You must be signed in to change notification settings - Fork 2k
/
util.py
42 lines (33 loc) · 1.35 KB
/
util.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# encoding: utf-8
import re
import ckan.lib.base as base
import ckan.lib.i18n as i18n
import ckan.lib.helpers as h
from ckan.common import _
class UtilController(base.BaseController):
''' Controller for functionality that has no real home'''
def redirect(self):
''' redirect to the url parameter. '''
url = base.request.params.get('url')
if not url:
base.abort(400, _('Missing Value') + ': url')
if h.url_is_local(url):
return base.redirect(url)
else:
base.abort(403, _('Redirecting to external site is not allowed.'))
def primer(self):
''' Render all html components out onto a single page.
This is useful for development/styling of ckan. '''
return base.render('development/primer.html')
def markup(self):
''' Render all html elements out onto a single page.
This is useful for development/styling of ckan. '''
return base.render('development/markup.html')
def i18_js_strings(self, lang):
''' This is used to produce the translations for javascript. '''
i18n.set_lang(lang)
html = base.render('js_strings.html', cache_force=True)
html = re.sub('<[^\>]*>', '', html)
header = "text/javascript; charset=utf-8"
base.response.headers['Content-type'] = header
return html