<div class="home-description">
<h3>{% trans "Playlists" %}</h3>
{% for playlist in playlists %}
- <h2>{{ playlist.name }} {% if playlist.is_current %}(current){% endif %}</h2>
+ <h2>{{ playlist.playlist.name }} {% if playlist.playlist.is_current %}(current){% endif %}
+ <a href="{% url telemeta-playlist-csv-export playlist.playlist.public_id %}">CSV</a></h2>
<table class="listing" width="90%">
<tr>
<th class="highlight">{% trans "Title" %}</th>
<tr {% if not forloop.counter0|divisibleby:"2" %}class="odd"{% endif %}>
<td>
{% if resource.type == "item" %}
- <a href="{% url telemeta-item-detail resource.element.public_id %}">{{ resource.element }}</a>
+ <a href="{% url telemeta-item-detail resource.element.public_id %}">{{ resource.element }}</a>
{% endif %}
{% if resource.type == "collection" %}
- <a href="{% url telemeta-collection-detail resource.element.public_id %}">{{ resource.element }}</a>
+ <a href="{% url telemeta-collection-detail resource.element.public_id %}">{{ resource.element }}</a>
{% endif %}
{% if resource.type == "marker" %}
{{ resource.element }}
url(r'^json/browse/', 'jsonrpc.views.browse', name="jsonrpc_browser"), # for the graphical browser/web console only, omissible
url(r'^json/$', jsonrpc_site.dispatch, name='jsonrpc_mountpoint'),
url(r'^json/(?P<method>[a-zA-Z0-9.]+)$', jsonrpc_site.dispatch), # for HTTP GET only, also omissible
+
+ # Playlists
+ url(r'^playlists/(?P<public_id>[a-zA-Z0-9]+)/$', web_view.playlist_csv_export, name="telemeta-playlist-csv-export"),
+
)
import re
import os
import sys
+import csv
import datetime
import timeside
if resource.resource_type == 'marker':
element = MediaItemMarker.objects.get(pk=resource.resource_id)
resources.append({'element': element, 'type': resource.resource_type})
- playlists.append({'name': playlist.name, 'description': playlist.description,
- 'is_current': playlist.is_current, 'resources': resources})
+ playlists.append({'playlist': playlist, 'resources': resources})
return playlists
@jsonrpc_method('telemeta.update_playlist')
m = PlaylistResource.objects.get(public_id=public_id)
m.delete()
+ def playlist_csv_export(self, request, public_id):
+ playlist = Playlist.objects.get(public_id=public_id)
+ resources = PlaylistResource.objects.filter(playlist=playlist)
+ response = HttpResponse(mimetype='text/csv')
+ response['Content-Disposition'] = 'attachment; filename='+playlist.name+'.csv'
+ writer = csv.writer(response)
+ items = []
+ for resource in resources:
+ if resource.resource_type == 'collection':
+ collection = MediaCollection.objects.get(pk=resource.resource_id)
+ collection_items = MediaItem.objects.filter(collection=collection)
+ for item in collection_items:
+ items.append(item)
+ elif resource.resource_type == 'item':
+ item = MediaItem.objects.get(pk=resource.resource_id)
+ items.append(item)
+ else:
+ pass
+
+ item = item.to_dict()
+ tags = item.keys()
+ writer.writerow(tags)
+
+ for item in items:
+ data = []
+ item = item.to_dict()
+ for tag in tags:
+ data.append(item[tag])
+ writer.writerow(data)
+
+ return response