add permalink + correct urls + encoding + maj config
authorymh <ymh.work@gmail.com>
Wed, 18 May 2011 19:16:36 +0200
changeset 107 4ab1136e388d
parent 106 d7c952a46c7e
child 108 ea2c971ff7e7
add permalink + correct urls + encoding + maj config
web/blinkster/config.py.tmpl
web/blinkster/urls.py
web/blinkster/views.py
--- a/web/blinkster/config.py.tmpl	Tue May 17 12:22:34 2011 +0200
+++ b/web/blinkster/config.py.tmpl	Wed May 18 19:16:36 2011 +0200
@@ -5,28 +5,29 @@
 BASE_DIR = os.path.dirname(os.path.abspath(__file__)).rstrip("/")+"/"
 BASE_URL = '/~ymh/platform/'
 WEB_URL = 'http://localhost/'
-MEDIA_BASE_URL = BASE_URL + 'static/'
+BASE_STATIC_URL = BASE_URL + 'static/'
 STATIC_URL = BASE_URL + 'static/site/'
-STREAM_URL = MEDIA_BASE_URL + "/content/"
+STREAM_URL = BASE_STATIC_URL + "/content/"
 
 STREAM_SRC_PREFIX = ""
  
+BASE_STATIC_ROOT = os.path.abspath(BASE_DIR + "../static/").rstrip("/")+"/"
 
 # Absolute path to the directory that holds media.
 # Example: "/home/media/media.lawrence.com/"
-MEDIA_ROOT = os.path.abspath(BASE_DIR + "../static/").rstrip("/")+"/"
+MEDIA_ROOT = BASE_STATIC_ROOT + "media/"
 
 
 # Absolute path to the directory that static files (js, css, swf...)
 # DO NOT forget to do command line ./manage.py collectstatic to gather static media into the web/static folder
-STATIC_ROOT = MEDIA_ROOT + "site/"
+STATIC_ROOT = BASE_STATIC_ROOT + "site/"
 
 # URL that handles the media served from MEDIA_ROOT. Make sure to use a
 # trailing slash if there is a path component (optional in other cases).
 # Examples: "http://media.lawrence.com", "http://example.com/media/"
-MEDIA_URL = MEDIA_BASE_URL
+MEDIA_URL = BASE_STATIC_URL + "media/"
 
-CONTENT_ROOT = MEDIA_ROOT + "media/content/"
+CONTENT_ROOT = MEDIA_ROOT + "content/"
 
 STREAM_PATH = CONTENT_ROOT
 
--- a/web/blinkster/urls.py	Tue May 17 12:22:34 2011 +0200
+++ b/web/blinkster/urls.py	Wed May 18 19:16:36 2011 +0200
@@ -36,8 +36,8 @@
     #(r'^.*(?P<content>flvplayer|mp3player|ClearExternalAllBlue)\.swf$','django.views.generic.simple.redirect_to', {'url':blinkster.settings.BASE_URL+'/static/swf/ldt/pkg/%(content)s.swf'}),
     (r'^roi/list/$', 'blinkster.views.roi_list'),
     (r'^poi/list/(?P<roi_sid>.*)/$', 'blinkster.views.poi_list'),
-    (r'^blinkster/segment/detail/(?P<iri_id>.*)/(?P<ensemble_id>.*)/(?P<cutting_id>.*)/(?P<element_id>.*)/$', 'blinkster.views.segment_detail'),
-    (r'^blinkster/segment/playlist/(?P<iri_id>.*)/(?P<ensemble_id>.*)/(?P<cutting_id>.*)/(?P<element_id>.*)/$', 'blinkster.views.segment_ts_playlist'),
+    (r'^blinkster/segment/detail/(?P<project_id>.*)/(?P<iri_id>.*)/(?P<ensemble_id>.*)/(?P<cutting_id>.*)/(?P<element_id>.*)/$', 'blinkster.views.segment_detail'),
+    (r'^blinkster/segment/playlist/(?P<project_id>.*)/(?P<iri_id>.*)/(?P<ensemble_id>.*)/(?P<cutting_id>.*)/(?P<element_id>.*)/$', 'blinkster.views.segment_ts_playlist'),
     (r'^blinkster/segment/search/$', 'blinkster.views.segment_search_post'),
     (r'^blinkster/segment/search/(?P<field>tags|title|abstract|all)/(?P<operator>or|and)/(?P<query>.*)/$', 'blinkster.views.segment_search_get'),
     (r'^photologue/', include('photologue.urls')),
--- a/web/blinkster/views.py	Tue May 17 12:22:34 2011 +0200
+++ b/web/blinkster/views.py	Wed May 18 19:16:36 2011 +0200
@@ -11,6 +11,7 @@
 from ldt.ldt_utils.models import Segment, Content
 from ldt.ldt_utils.utils import LdtSearch
 import blinkster
+import django.utils.encoding
 import math
 import re
 import urllib2
@@ -62,13 +63,16 @@
     roi = get_object_or_404(Roi, sid=roi_sid)
     results = []
     for poi_dict in [poi.serialize_to_dict() for poi in Poi.objects.filter(roi=roi)]: #@UndefinedVariable
-        poi_dict["segment_search_url"] = unicode(settings.WEB_URL.rstrip('/') + reverse('blinkster.views.segment_search_get', args=[u"tags", u"or", urllib2.quote(poi_dict["tags"].encode("utf-8"))]) + content_type_req)
+        poi_dict["segment_search_url"] = django.utils.encoding.iri_to_uri(unicode(settings.WEB_URL.rstrip('/') + reverse('blinkster.views.segment_search_get', args=[u"tags", u"or", urllib2.quote(poi_dict["tags"].encode("utf-8"))]) + content_type_req))
         results.append(poi_dict)
     return serialize_queryset_to_json(response, results)
 
 # Display segment detail.
 # This will have to be moved to ldt module
-def segment_detail(request, iri_id, ensemble_id, cutting_id, element_id, project_id=None):
+def segment_detail(request, project_id, iri_id, ensemble_id, cutting_id, element_id):
+    
+    if project_id is None or project_id == "_":
+        project_id = ""
         
     segment = get_list_or_404(Segment, project_id=project_id, iri_id=iri_id, ensemble_id=ensemble_id, cutting_id=cutting_id, element_id=element_id)[0]
     tags = segment.tags
@@ -91,6 +95,7 @@
     return render_to_response("segment_detail.html",
                               {'segment':segment,
                                'segment_tags_list':segment_tags_list,
+                               'ldt_id': project_id,
                                'iri_id':iri_id,
                                'ensemble_id':ensemble_id,
                                'cutting_id':cutting_id,
@@ -140,16 +145,20 @@
             res = dict(res, **seg)
             del res["project_obj_id"]
             del res["content_id"]
-            del res["id"]            
-        res["segment_detail_url"] = unicode(settings.WEB_URL.rstrip('/') + reverse('blinkster.views.segment_detail', args=[res["iri_id"], res["ensemble_id"], res["cutting_id"], res["element_id"]]) + content_type_req)
-        res["segment_video_url"] = unicode(settings.WEB_URL.rstrip('/') + reverse('blinkster.views.segment_ts_playlist', args=[res["iri_id"], res["ensemble_id"], res["cutting_id"], res["element_id"]]) + content_type_req)
+            del res["id"]
+            res["project_id"] = res["project_id"] if res["project_id"] else "_"            
+        res["segment_detail_url"] = unicode(settings.WEB_URL.rstrip('/') + reverse('blinkster.views.segment_detail', args=[res["project_id"], res["iri_id"], res["ensemble_id"], res["cutting_id"], res["element_id"]]) + content_type_req)
+        res["segment_video_url"] = unicode(settings.WEB_URL.rstrip('/') + reverse('blinkster.views.segment_ts_playlist', args=[res["project_id"], res["iri_id"], res["ensemble_id"], res["cutting_id"], res["element_id"]]) + content_type_req)
+        res["segment_ldt_url"] = unicode(settings.WEB_URL.rstrip('/') + reverse('ldt.ldt_utils.views.index_segment', args=[res["project_id"], res["iri_id"], res["ensemble_id"], res["cutting_id"], res["element_id"]]) + content_type_req)
         results.append(res)
     
     return serialize_queryset_to_json(response, results, {u"query" : query, u"field": field, u"operator":operator, u"final_query": query_str})
 
 
-def segment_ts_playlist(request, iri_id, ensemble_id, cutting_id, element_id, project_id=""):
+def segment_ts_playlist(request, project_id, iri_id, ensemble_id, cutting_id, element_id):
 
+    if project_id is None or project_id == "_":
+        project_id = ""
     content_type = "application/x-mpegURL; charset=utf-8"
     segment = get_list_or_404(Segment, project_id=project_id, iri_id=iri_id, ensemble_id=ensemble_id, cutting_id=cutting_id, element_id=element_id)[0]
     start_ts = int(math.floor(segment.start_ts / 1000.0))
@@ -175,7 +184,7 @@
     
     for i in range(start_ts, end_ts + 1):
         respstr += u"#EXTINF:1,\n"
-        respstr += u"%s%s/media/videos/%s/fileSequence%s%s\n" % (settings.WEB_URL, settings.MEDIA_BASE_URL, iri_id, i, ext)
+        respstr += u"%s%s/videos/%s/fileSequence%s%s\n" % (settings.WEB_URL, settings.MEDIA_URL, iri_id, i, ext)
 
     respstr += u"#EXT-X-ENDLIST\n"