# HG changeset patch # User ymh # Date 1352906941 -3600 # Node ID b6010b3d6ea836bbc397cff7db311ea042a4f3db # Parent 342f180b09ec0bc67f2b96653731c6fba9e0aee4 add proxy, model, and correct embed_player diff -r 342f180b09ec -r b6010b3d6ea8 src/hp/admin.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/hp/admin.py Wed Nov 14 16:29:01 2012 +0100 @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +''' +Created on Nov 13, 2012 + +@author: ymh +''' + +from django.contrib import admin +from .models import VideoKCRel +from .forms import VideoKCRelForm + +class VideoKCRelAdmin(admin.ModelAdmin): + form = VideoKCRelForm + +admin.site.register(VideoKCRel, VideoKCRelAdmin) diff -r 342f180b09ec -r b6010b3d6ea8 src/hp/context_processors.py --- a/src/hp/context_processors.py Tue Nov 13 16:37:47 2012 +0100 +++ b/src/hp/context_processors.py Wed Nov 14 16:29:01 2012 +0100 @@ -5,6 +5,7 @@ @author: ymh ''' from . import get_version +from . import settings def hp_context(request): - return {'VERSION' : get_version()} \ No newline at end of file + return {'VERSION' : get_version(), 'LDT_URL' : settings.LDT_URL, 'LDT_STATIC_URL' : settings.LDT_STATIC_URL} \ No newline at end of file diff -r 342f180b09ec -r b6010b3d6ea8 src/hp/forms.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/hp/forms.py Wed Nov 14 16:29:01 2012 +0100 @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +''' +Created on Nov 14, 2012 + +@author: ymh +''' + +from django import forms +from .models import VideoKCRel +import requests +from . import settings + +class VideoKCRelForm(forms.ModelForm): + + iri_id = forms.CharField(max_length=255, widget=forms.widgets.Select()) + + def __init__(self, *args, **kwargs): + super(VideoKCRelForm, self).__init__(*args, **kwargs) + + url = settings.LDT_API_URL + "contents/" + #limit=20&offset=20 + r = requests.get(url) + self.fields['iri_id'].widget.choices = [(content['iri_id'], content['title']) for content in r.json['objects']] + + class Meta: + model = VideoKCRel + \ No newline at end of file diff -r 342f180b09ec -r b6010b3d6ea8 src/hp/migrations/0001_initial.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/hp/migrations/0001_initial.py Wed Nov 14 16:29:01 2012 +0100 @@ -0,0 +1,36 @@ +# -*- coding: utf-8 -*- +import datetime +from south.db import db +from south.v2 import SchemaMigration +from django.db import models + + +class Migration(SchemaMigration): + + def forwards(self, orm): + # Adding model 'VideoKCRel' + db.create_table('hp_videokcrel', ( + ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)), + ('iri_id', self.gf('django.db.models.fields.CharField')(unique=True, max_length=255)), + ('graph_id', self.gf('django.db.models.fields.CharField')(max_length=1024)), + ('topic_id', self.gf('django.db.models.fields.CharField')(max_length=1024)), + )) + db.send_create_signal('hp', ['VideoKCRel']) + + + def backwards(self, orm): + # Deleting model 'VideoKCRel' + db.delete_table('hp_videokcrel') + + + models = { + 'hp.videokcrel': { + 'Meta': {'object_name': 'VideoKCRel'}, + 'graph_id': ('django.db.models.fields.CharField', [], {'max_length': '1024'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'iri_id': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'}), + 'topic_id': ('django.db.models.fields.CharField', [], {'max_length': '1024'}) + } + } + + complete_apps = ['hp'] \ No newline at end of file diff -r 342f180b09ec -r b6010b3d6ea8 src/hp/migrations/__init__.py diff -r 342f180b09ec -r b6010b3d6ea8 src/hp/models.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/hp/models.py Wed Nov 14 16:29:01 2012 +0100 @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +''' +Created on Nov 13, 2012 + +@author: ymh +''' + +from django.db import models +from django.utils.translation import ugettext_lazy as _ + +class VideoKCRel(models.Model): + + iri_id = models.CharField(max_length=255, unique=True, verbose_name=_('content.iri_id')) + graph_id = models.CharField(max_length=1024, verbose_name=_('graph_id')) + topic_id = models.CharField(max_length=1024, verbose_name=_('topic_id')) + + def __unicode__(self): + return u"%s->%s|%s" %(self.iri_id,self.graph_id, self.topic_id) + + diff -r 342f180b09ec -r b6010b3d6ea8 src/hp/settings.py --- a/src/hp/settings.py Tue Nov 13 16:37:47 2012 +0100 +++ b/src/hp/settings.py Wed Nov 14 16:29:01 2012 +0100 @@ -164,7 +164,16 @@ } LDT_DOMAIN = 'http://localhost' -LDT_API_URL = LDT_DOMAIN + '/~ymh/hp_ldt/ldtplatform/api/ldt/1.0/' +LDT_BASE_URL = LDT_DOMAIN + '/~ymh/hp_ldt/' +LDT_URL = LDT_BASE_URL + "ldtplatform/" +LDT_API_URL = LDT_URL + 'api/ldt/1.0/' +LDT_STATIC_URL = LDT_BASE_URL + "static/site/" + +KC_URL = 'http://176.32.94.234/kn-concierge/' + from .config import * #@UnusedWildImport + + + diff -r 342f180b09ec -r b6010b3d6ea8 src/hp/templates/hp/partial/embed_player.html --- a/src/hp/templates/hp/partial/embed_player.html Tue Nov 13 16:37:47 2012 +0100 +++ b/src/hp/templates/hp/partial/embed_player.html Wed Nov 14 16:29:01 2012 +0100 @@ -5,104 +5,63 @@
- +
{% endspaceless %} + diff -r 342f180b09ec -r b6010b3d6ea8 src/hp/urls.py --- a/src/hp/urls.py Tue Nov 13 16:37:47 2012 +0100 +++ b/src/hp/urls.py Wed Nov 14 16:29:01 2012 +0100 @@ -10,6 +10,7 @@ # url(r'^hp/', include('hp.foo.urls')), url(r'^$', 'hp.views.all_videos', name='home'), url(r'^video/(?P.*)$', 'hp.views.show_video_details', name='video_details'), + url(r'^kc_proxy/(?P.*)$', 'hp.views.kc_proxy', name='kc_proxy'), url(r'^api/1.0/', include('hp.api.urls')), diff -r 342f180b09ec -r b6010b3d6ea8 src/hp/views.py --- a/src/hp/views.py Tue Nov 13 16:37:47 2012 +0100 +++ b/src/hp/views.py Wed Nov 14 16:29:01 2012 +0100 @@ -4,11 +4,13 @@ @author: ymh ''' +from django.conf import settings from django.shortcuts import render_to_response from django.template.context import RequestContext +from django.http import HttpResponse +from hp.models import VideoKCRel +import logging import requests -from django.conf import settings -import logging import urlparse logger = logging.getLogger(__name__) @@ -41,5 +43,37 @@ r_content = requests.get(url_content) logger.debug(r_content.text) + + content = r_content.json + project_url = content['front_project'] + project_path = urlparse.urlparse(project_url).path + project_id = "" + if project_path: + project_path_parts = project_path.split("/") + project_id = project_path_parts[-1] if project_path_parts[-1] else project_path_parts[-2] + + kc_id = None + topic_id = None + + kc_relation_list = list(VideoKCRel.objects.filter(iri_id=content_id)[:1]) + + if len(kc_relation_list) > 0: + kc_id = kc_relation_list[0].graph_id + topic_id = kc_relation_list[0].topic_id + + return render_to_response( + 'hp/video_player.html', + {'content':content, 'project_id': project_id, 'kc_id': kc_id, 'topic_id': topic_id}, + context_instance=RequestContext(request)) - return render_to_response('hp/video_player.html',{'content':r_content.json}, context_instance=RequestContext(request)) \ No newline at end of file + +def kc_proxy(request, path): + + url = settings.KC_URL + path + + data = request.POST if request.method=="POST" else {} + + r = requests.request(request.method, url, data=data) + + return HttpResponse(content=r.text, content_type='application/json;charset=UTF-8') + \ No newline at end of file diff -r 342f180b09ec -r b6010b3d6ea8 virtualenv/res/src/ldt-1.30.tar.gz Binary file virtualenv/res/src/ldt-1.30.tar.gz has changed