]> git.parisson.com Git - telemeta.git/commitdiff
add csv element function
authorGuillaume Pellerin <guillaume.pellerin@ircam.fr>
Fri, 13 Nov 2015 14:39:42 +0000 (15:39 +0100)
committerGuillaume Pellerin <guillaume.pellerin@ircam.fr>
Fri, 13 Nov 2015 14:39:42 +0000 (15:39 +0100)
telemeta/views/playlist.py

index 8ee10ef60aa0bee7d242107be3c07683ff383311..86797e5fb46538771481fc0ccd6ecdf095f41b69 100644 (file)
@@ -85,14 +85,8 @@ class PlaylistView(object):
         m = PlaylistResource.objects.get(public_id=public_id)
         m.delete()
 
-
-    def playlist_csv_export(self, request, public_id, resource_type):
-        playlist = Playlist.objects.get(public_id=public_id, author=request.user)
+    def get_elements(self, playlist, resource_type):
         resources = PlaylistResource.objects.filter(playlist=playlist)
-        response = HttpResponse(content_type='text/csv')
-        response['Content-Disposition'] = 'attachment; filename='+playlist.title+'_'+resource_type+'.csv'
-        writer = UnicodeWriter(response)
-
         elements = []
         for resource in resources:
             if resource_type == 'items':
@@ -113,6 +107,14 @@ class PlaylistView(object):
                 if resource.resource_type == 'collection':
                     collection = MediaCollection.objects.get(id=resource.resource_id)
                     elements.append(collection)
+        return elements
+
+    def playlist_csv_export(self, request, public_id, resource_type):
+        playlist = Playlist.objects.get(public_id=public_id, author=request.user)
+        elements = self.get_elements(playlist, resource_type)
+        response = HttpResponse(content_type='text/csv')
+        response['Content-Disposition'] = 'attachment; filename='+playlist.title+'_'+resource_type+'.csv'
+        writer = UnicodeWriter(response)
 
         if elements:
             csv = CSVExport(writer)