| author | ymh <ymh.work@gmail.com> |
| Wed, 14 Nov 2012 18:47:17 +0100 | |
| changeset 44 | 0931f368cb9a |
| parent 41 | b6010b3d6ea8 |
| child 45 | 316a0101512e |
| permissions | -rw-r--r-- |
| 38 | 1 |
# -*- coding: utf-8 -*- |
2 |
''' |
|
3 |
Created on Nov 11, 2012 |
|
4 |
||
5 |
@author: ymh |
|
6 |
''' |
|
|
41
b6010b3d6ea8
add proxy, model, and correct embed_player
ymh <ymh.work@gmail.com>
parents:
38
diff
changeset
|
7 |
from django.conf import settings |
| 38 | 8 |
from django.shortcuts import render_to_response |
9 |
from django.template.context import RequestContext |
|
|
41
b6010b3d6ea8
add proxy, model, and correct embed_player
ymh <ymh.work@gmail.com>
parents:
38
diff
changeset
|
10 |
from django.http import HttpResponse |
|
b6010b3d6ea8
add proxy, model, and correct embed_player
ymh <ymh.work@gmail.com>
parents:
38
diff
changeset
|
11 |
from hp.models import VideoKCRel |
|
b6010b3d6ea8
add proxy, model, and correct embed_player
ymh <ymh.work@gmail.com>
parents:
38
diff
changeset
|
12 |
import logging |
| 38 | 13 |
import requests |
14 |
import urlparse |
|
15 |
||
16 |
logger = logging.getLogger(__name__) |
|
17 |
||
18 |
||
19 |
def all_videos(request): |
|
20 |
||
21 |
#get all videos |
|
22 |
#render |
|
23 |
url = settings.LDT_API_URL + "contents/" |
|
24 |
#limit=20&offset=20 |
|
25 |
r = requests.get(url) |
|
26 |
||
27 |
||
28 |
||
29 |
results = r.json |
|
30 |
||
31 |
for content in results.get('objects', []): |
|
32 |
url_parts = urlparse.urlparse(content.get('image','')) |
|
33 |
if not url_parts.netloc: |
|
34 |
content['image'] = settings.LDT_DOMAIN + content.get('image','') |
|
35 |
||
36 |
return render_to_response('hp/all_videos.html',{'results':results}, context_instance=RequestContext(request)) |
|
37 |
||
38 |
||
39 |
def show_video_details(request, content_id): |
|
40 |
||
41 |
url_content = settings.LDT_API_URL + "contents/%s" % content_id |
|
42 |
||
43 |
r_content = requests.get(url_content) |
|
44 |
||
45 |
logger.debug(r_content.text) |
|
|
41
b6010b3d6ea8
add proxy, model, and correct embed_player
ymh <ymh.work@gmail.com>
parents:
38
diff
changeset
|
46 |
|
|
b6010b3d6ea8
add proxy, model, and correct embed_player
ymh <ymh.work@gmail.com>
parents:
38
diff
changeset
|
47 |
content = r_content.json |
|
b6010b3d6ea8
add proxy, model, and correct embed_player
ymh <ymh.work@gmail.com>
parents:
38
diff
changeset
|
48 |
project_url = content['front_project'] |
|
b6010b3d6ea8
add proxy, model, and correct embed_player
ymh <ymh.work@gmail.com>
parents:
38
diff
changeset
|
49 |
project_path = urlparse.urlparse(project_url).path |
|
b6010b3d6ea8
add proxy, model, and correct embed_player
ymh <ymh.work@gmail.com>
parents:
38
diff
changeset
|
50 |
project_id = "" |
|
b6010b3d6ea8
add proxy, model, and correct embed_player
ymh <ymh.work@gmail.com>
parents:
38
diff
changeset
|
51 |
if project_path: |
|
b6010b3d6ea8
add proxy, model, and correct embed_player
ymh <ymh.work@gmail.com>
parents:
38
diff
changeset
|
52 |
project_path_parts = project_path.split("/") |
|
b6010b3d6ea8
add proxy, model, and correct embed_player
ymh <ymh.work@gmail.com>
parents:
38
diff
changeset
|
53 |
project_id = project_path_parts[-1] if project_path_parts[-1] else project_path_parts[-2] |
|
b6010b3d6ea8
add proxy, model, and correct embed_player
ymh <ymh.work@gmail.com>
parents:
38
diff
changeset
|
54 |
|
|
b6010b3d6ea8
add proxy, model, and correct embed_player
ymh <ymh.work@gmail.com>
parents:
38
diff
changeset
|
55 |
kc_id = None |
|
b6010b3d6ea8
add proxy, model, and correct embed_player
ymh <ymh.work@gmail.com>
parents:
38
diff
changeset
|
56 |
topic_id = None |
|
b6010b3d6ea8
add proxy, model, and correct embed_player
ymh <ymh.work@gmail.com>
parents:
38
diff
changeset
|
57 |
|
|
b6010b3d6ea8
add proxy, model, and correct embed_player
ymh <ymh.work@gmail.com>
parents:
38
diff
changeset
|
58 |
kc_relation_list = list(VideoKCRel.objects.filter(iri_id=content_id)[:1]) |
|
b6010b3d6ea8
add proxy, model, and correct embed_player
ymh <ymh.work@gmail.com>
parents:
38
diff
changeset
|
59 |
|
|
b6010b3d6ea8
add proxy, model, and correct embed_player
ymh <ymh.work@gmail.com>
parents:
38
diff
changeset
|
60 |
if len(kc_relation_list) > 0: |
|
b6010b3d6ea8
add proxy, model, and correct embed_player
ymh <ymh.work@gmail.com>
parents:
38
diff
changeset
|
61 |
kc_id = kc_relation_list[0].graph_id |
|
b6010b3d6ea8
add proxy, model, and correct embed_player
ymh <ymh.work@gmail.com>
parents:
38
diff
changeset
|
62 |
topic_id = kc_relation_list[0].topic_id |
|
b6010b3d6ea8
add proxy, model, and correct embed_player
ymh <ymh.work@gmail.com>
parents:
38
diff
changeset
|
63 |
|
|
b6010b3d6ea8
add proxy, model, and correct embed_player
ymh <ymh.work@gmail.com>
parents:
38
diff
changeset
|
64 |
return render_to_response( |
|
b6010b3d6ea8
add proxy, model, and correct embed_player
ymh <ymh.work@gmail.com>
parents:
38
diff
changeset
|
65 |
'hp/video_player.html', |
|
b6010b3d6ea8
add proxy, model, and correct embed_player
ymh <ymh.work@gmail.com>
parents:
38
diff
changeset
|
66 |
{'content':content, 'project_id': project_id, 'kc_id': kc_id, 'topic_id': topic_id}, |
|
b6010b3d6ea8
add proxy, model, and correct embed_player
ymh <ymh.work@gmail.com>
parents:
38
diff
changeset
|
67 |
context_instance=RequestContext(request)) |
| 38 | 68 |
|
|
41
b6010b3d6ea8
add proxy, model, and correct embed_player
ymh <ymh.work@gmail.com>
parents:
38
diff
changeset
|
69 |
|
|
b6010b3d6ea8
add proxy, model, and correct embed_player
ymh <ymh.work@gmail.com>
parents:
38
diff
changeset
|
70 |
def kc_proxy(request, path): |
|
b6010b3d6ea8
add proxy, model, and correct embed_player
ymh <ymh.work@gmail.com>
parents:
38
diff
changeset
|
71 |
|
| 44 | 72 |
r = requests.request(request.method, settings.KC_URL + path, data=request.POST, params=request.GET) |
|
41
b6010b3d6ea8
add proxy, model, and correct embed_player
ymh <ymh.work@gmail.com>
parents:
38
diff
changeset
|
73 |
|
| 44 | 74 |
logger.debug("Proxy r url : " + r.url) |
75 |
logger.debug("Proxy r method : " + r.method) |
|
76 |
logger.debug("Proxy r status : " + r.status) |
|
77 |
logger.debug("Proxy r text : " + r.text) |
|
78 |
||
|
41
b6010b3d6ea8
add proxy, model, and correct embed_player
ymh <ymh.work@gmail.com>
parents:
38
diff
changeset
|
79 |
return HttpResponse(content=r.text, content_type='application/json;charset=UTF-8') |
|
b6010b3d6ea8
add proxy, model, and correct embed_player
ymh <ymh.work@gmail.com>
parents:
38
diff
changeset
|
80 |