padmaAPI/lists/views.py

50 lines
1.2 KiB
Python
Raw Normal View History

import urllib
from django.utils import simplejson
from django.http import HttpResponse
from django.shortcuts import render_to_response
from settings import PADMA_URL
def getHtmlFromUrl(url):
try:
u = urllib.urlopen(url)
t = u.read()
u.close
except:
return False
return t
def fetchJson(request):
if request.GET['url']:
u = request.GET['url']
json = getHtmlFromUrl(u)
return HttpResponse(json, mimetype="application/javascript")
else:
return HttpResponse("{'error': True}", mimetype="application/javascript")
def fetchSrt(request):
if request.GET['id']:
padmaId = request.GET['id']
track = request.GET['track'] or 'transcript'
2010-07-13 12:08:50 +00:00
url = "%s/%s/export/%s.srt" % (PADMA_URL, padmaId, track,)
srt = getHtmlFromUrl(url)
return HttpResponse(srt)
else:
return HttpResponse("{'error': True}", mimetype="application/javascript")
def index(request):
2010-07-15 00:02:35 +00:00
return render_to_response("index.html", {
'padma_url': PADMA_URL
})
def listDetail(request):
if request.GET:
2010-07-13 12:08:50 +00:00
rDict = {
2010-07-15 00:02:35 +00:00
'listId': request.GET['id'],
2010-07-13 12:08:50 +00:00
'padma_url': PADMA_URL,
}
return render_to_response("list.html", rDict)
else:
return HttpResponse("Please pass me a list id")