From a2e58a936c5822ce16cf1752d47cab84a577e351 Mon Sep 17 00:00:00 2001 From: olivier <> Date: Tue, 26 Jan 2010 11:23:39 +0000 Subject: [PATCH] add generic public_id property to media item and collection for use in urls, etc.. --- telemeta/models/crem.py | 14 +++++++++-- telemeta/models/cremquery.py | 10 ++++---- .../templates/telemeta_default/collection.m3u | 2 +- .../telemeta_default/collection_detail.html | 12 +++++----- .../collection_detail_dc.html | 2 +- .../telemeta_default/collection_xspf.xml | 6 ++--- .../telemeta_default/inc/collection_list.html | 2 +- .../telemeta_default/inc/dublincore.html | 4 ++-- .../telemeta_default/inc/mediaitem_list.html | 2 +- .../telemeta_default/mediaitem_detail.html | 14 +++++------ .../telemeta_default/mediaitem_xspf.xml | 4 ++-- telemeta/urls.py | 20 ++++++++-------- telemeta/web/base.py | 24 +++++++++---------- 13 files changed, 63 insertions(+), 53 deletions(-) diff --git a/telemeta/models/crem.py b/telemeta/models/crem.py index 156bea5c..3236977d 100755 --- a/telemeta/models/crem.py +++ b/telemeta/models/crem.py @@ -179,6 +179,10 @@ class MediaCollection(MediaResource): def __unicode__(self): return self.code + @property + def public_id(self): + return self.code + def has_mediafile(self): "Tell wether this collection has any media files attached to its items" items = self.items.all() @@ -280,9 +284,15 @@ class MediaItem(MediaResource): objects = query.MediaItemManager() - def _keywords(self): + @property + def keywords(self): return ContextKeyword.objects.filter(mediaitemkeyword__item = self) - keywords = property(_keywords) + + @property + def public_id(self): + if self.code: + return self.code + return self.id class Meta(MetaCore): db_table = 'media_items' diff --git a/telemeta/models/cremquery.py b/telemeta/models/cremquery.py index 1c72195f..4526bcdb 100644 --- a/telemeta/models/cremquery.py +++ b/telemeta/models/cremquery.py @@ -76,16 +76,16 @@ class CoreManager(EnhancedManager): return self.get_query_set().none(*args, **kwargs) def get(self, **kwargs): - if kwargs.has_key('code_or_id'): + if kwargs.has_key('public_id'): try: args = kwargs.copy() - args['code'] = kwargs['code_or_id'] - args.pop('code_or_id') + args['code'] = kwargs['public_id'] + args.pop('public_id') return super(CoreManager, self).get(**args) except ObjectDoesNotExist: args = kwargs.copy() - args['id'] = kwargs['code_or_id'] - args.pop('code_or_id') + args['id'] = kwargs['public_id'] + args.pop('public_id') return super(CoreManager, self).get(**args) return super(CoreManager, self).get(**kwargs) diff --git a/telemeta/templates/telemeta_default/collection.m3u b/telemeta/templates/telemeta_default/collection.m3u index 259dc4ba..6412a8f4 100644 --- a/telemeta/templates/telemeta_default/collection.m3u +++ b/telemeta/templates/telemeta_default/collection.m3u @@ -1,3 +1,3 @@ #EXTM3U{% load telemeta_utils %}{% for item in collection.items.all %} #EXTINF:{{ item.get_duration }},{{ item.title }} -http://{{ host }}{% url telemeta-item-export item|code_or_id,"mp3" %}{% endfor %} +http://{{ host }}{% url telemeta-item-export item.public_id,"mp3" %}{% endfor %} diff --git a/telemeta/templates/telemeta_default/collection_detail.html b/telemeta/templates/telemeta_default/collection_detail.html index 62399bef..04171651 100644 --- a/telemeta/templates/telemeta_default/collection_detail.html +++ b/telemeta/templates/telemeta_default/collection_detail.html @@ -11,7 +11,7 @@ {% block submenu %}
Listen to this collection - (M3U, - XSPF)
+ (M3U, + XSPF) {% if 0 %} {# Use 1/0 for alternate player #} {% else %} @@ -117,7 +117,7 @@ load_player({{ item.get_duration }});Download: {% for format in export_formats %} - {{ format.name }} + {{ format.name }} {% endfor %}
[A-Z0-9_]+)/$', web_view.collection_detail,
+ url(r'^collections/(?P[A-Z0-9_]+)/$', web_view.collection_detail,
dict(template="telemeta/collection_detail.html"), name="telemeta-collection-detail"),
- url(r'^collections/(?P[A-Z0-9_]+)/dc/$', web_view.collection_detail,
+ url(r'^collections/(?P[A-Z0-9_]+)/dc/$', web_view.collection_detail,
dict(template="telemeta/collection_detail_dc.html"), name="telemeta-collection-dublincore"),
- url(r'^collections/(?P[A-Z0-9_]+)/collection_xspf.xml$',
+ url(r'^collections/(?P[A-Z0-9_]+)/collection_xspf.xml$',
web_view.collection_playlist,
dict(template="telemeta/collection_xspf.xml", mimetype="application/xspf+xml"),
name="telemeta-collection-xspf"),
- url(r'^collections/(?P[A-Z0-9_]+)/collection.m3u$',
+ url(r'^collections/(?P[A-Z0-9_]+)/collection.m3u$',
web_view.collection_playlist,
dict(template="telemeta/collection.m3u", mimetype="audio/mpegurl"),
name="telemeta-collection-m3u"),
diff --git a/telemeta/web/base.py b/telemeta/web/base.py
index ef7e4fa3..57d34314 100644
--- a/telemeta/web/base.py
+++ b/telemeta/web/base.py
@@ -70,14 +70,14 @@ class WebView(Component):
context = Context({})
return HttpResponse(template.render(context))
- def collection_detail(self, request, code, template=''):
- collection = MediaCollection.objects.get(code=code)
+ def collection_detail(self, request, public_id, template=''):
+ collection = MediaCollection.objects.get(public_id=public_id)
return render_to_response(template, {'collection': collection})
- def item_detail(self, request, item_key, template='telemeta/mediaitem_detail.html'):
+ def item_detail(self, request, public_id, template='telemeta/mediaitem_detail.html'):
"""Show the details of a given item"""
- item = MediaItem.objects.get(code_or_id=item_key)
+ item = MediaItem.objects.get(public_id=public_id)
formats = []
for exporter in self.exporters:
@@ -115,7 +115,7 @@ class WebView(Component):
'visualizers': visualizers, 'visualizer_id': visualizer_id,
'analysers': analyzers, 'vamp_plugins': vamp_plugin_list})
- def item_visualize(self, request, item_key, visualizer_id, width, height):
+ def item_visualize(self, request, public_id, visualizer_id, width, height):
for visualizer in self.visualizers:
if visualizer.get_id() == visualizer_id:
break
@@ -123,7 +123,7 @@ class WebView(Component):
if visualizer.get_id() != visualizer_id:
raise Http404
- item = MediaItem.objects.get(code_or_id=item_key)
+ item = MediaItem.objects.get(public_id=public_id)
visualizer.set_colors((255,255,255), 'purple')
stream = visualizer.render(item, width=int(width), height=int(height))
@@ -137,7 +137,7 @@ class WebView(Component):
list.append(exporter.get_file_extension())
return list
- def item_export(self, request, item_key, extension):
+ def item_export(self, request, public_id, extension):
"""Export a given media item in the specified format (OGG, FLAC, ...)"""
for exporter in self.exporters:
if exporter.get_file_extension() == extension:
@@ -150,7 +150,7 @@ class WebView(Component):
exporter.set_cache_dir(settings.TELEMETA_EXPORT_CACHE_DIR)
- item = MediaItem.objects.get(code_or_id=item_key)
+ item = MediaItem.objects.get(public_id=public_id)
infile = item.file.path
metadata = item.to_dublincore().flatten()
@@ -316,9 +316,9 @@ class WebView(Component):
return self.edit_enumeration(request, enumeration_id)
- def collection_playlist(self, request, code, template, mimetype):
+ def collection_playlist(self, request, public_id, template, mimetype):
try:
- collection = MediaCollection.objects.get(code=code)
+ collection = MediaCollection.objects.get(public_id=public_id)
except ObjectDoesNotExist:
raise Http404
@@ -326,9 +326,9 @@ class WebView(Component):
context = Context({'collection': collection, 'host': request.META['HTTP_HOST']})
return HttpResponse(template.render(context), mimetype=mimetype)
- def item_playlist(self, request, item_key, template, mimetype):
+ def item_playlist(self, request, public_id, template, mimetype):
try:
- item = MediaItem.objects.get(code_or_id=item_key)
+ item = MediaItem.objects.get(public_id=public_id)
except ObjectDoesNotExist:
raise Http404
--
2.39.5