]> git.parisson.com Git - telemeta.git/commitdiff
add csv export methods for playlists (to finish)
authoryomguy <yomguy@parisson.com>
Wed, 16 Mar 2011 01:12:22 +0000 (02:12 +0100)
committeryomguy <yomguy@parisson.com>
Wed, 16 Mar 2011 01:12:22 +0000 (02:12 +0100)
telemeta/htdocs/images/ok.png [new file with mode: 0644]
telemeta/templates/telemeta_default/home.html
telemeta/urls.py
telemeta/web/base.py

diff --git a/telemeta/htdocs/images/ok.png b/telemeta/htdocs/images/ok.png
new file mode 100644 (file)
index 0000000..543710f
Binary files /dev/null and b/telemeta/htdocs/images/ok.png differ
index d4a78ca88dae7f7233830b1996d3c37004d7ef38..dec645956e38fb19700b04f1e6c8146322ed917a 100644 (file)
@@ -49,7 +49,8 @@
 <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 }}
index fe02de71c5c8362688dd02f08f21b38d45046246..165aa3f2413c69ee7577d83ad68294591fe232a2 100644 (file)
@@ -199,4 +199,8 @@ urlpatterns = patterns('',
     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"),
+    
 )
index fb0a6bce7cb91372a462ca9e91661ebed6a82d4a..4b41e872e38776c9343c9b8185c9c2b6f6242cd0 100644 (file)
@@ -35,6 +35,7 @@
 import re
 import os
 import sys
+import csv
 import datetime
 import timeside
 
@@ -820,8 +821,7 @@ class WebView(object):
                 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')
@@ -852,3 +852,34 @@ class WebView(object):
         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