-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviews.py
47 lines (32 loc) · 1.15 KB
/
views.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
43
44
45
46
47
from django.http import HttpResponse
import urllib2
import mimetypes
from django.conf import settings
STATIC_URL = getattr(settings, 'STATIC_URL', '')
def css(request):
url = '%scms/js/wymeditor/skins/django/skin.css' % STATIC_URL
return _proxy(url)
def js(request):
url = '%scms/js/wymeditor/skins/django/skin.js' % STATIC_URL
return _proxy(url)
def icons(request):
url = '%scms/js/wymeditor/skins/django/icons.png' % STATIC_URL
return _proxy(url)
def wymiframecss(request):
url = '%scms/wymeditor/iframe/default/wymiframe.css' % STATIC_URL
return _proxy(url)
def proxy(request):
url = STATIC_URL
url += request.META.get('QUERY_STRING')
return _proxy(url)
def _proxy(url):
try:
proxied_request = urllib2.urlopen(url)
status_code = proxied_request.code
mimetype = proxied_request.headers.typeheader or mimetypes.guess_type(url)
content = proxied_request.read()
except urllib2.HTTPError as e:
msg = e.msg + ' : ' + url
return HttpResponse(msg, status=e.code, mimetype='text/plain')
else:
return HttpResponse(content, status=status_code, mimetype=mimetype)