]> git.0d.be Git - django-panik-nonstop.git/commitdiff
update csv export format to match latest fwb request
authorFrédéric Péters <fpeters@0d.be>
Thu, 26 Aug 2021 06:53:46 +0000 (08:53 +0200)
committerFrédéric Péters <fpeters@0d.be>
Thu, 26 Aug 2021 06:53:46 +0000 (08:53 +0200)
nonstop/views.py

index ce0e29aeb7d31fd57d2a75c5d8ef59e59583430f..c2c2badabf9a54af1e7b73edabc94a134c7ca6d0 100644 (file)
@@ -57,27 +57,45 @@ class SomaDayArchiveView(DayArchiveView):
 
 
 class SomaDayArchiveCsvView(SomaDayArchiveView):
+    queryset = SomaLogLine.objects.all()
+    ordering = 'play_timestamp'
+
     def render_to_response(self, context, **response_kwargs):
         out = StringIO()
         writer = csv.writer(out)
+        writer.writerow(
+            [
+                _('date'),
+                _('time'),
+                _('title'),
+                _('artist'),
+                _('duration'),
+                _('music'),
+                _('lyrics'),
+                _('French'),
+                'FWB',
+            ]
+        )
         for line in context['object_list']:
-            if line.filepath.track:
+            if line.track:
                 writer.writerow(
                     [
-                        line.play_timestamp.strftime('%Y-%m-%d %H:%M'),
-                        line.filepath.short,
-                        line.filepath.track.title,
-                        line.filepath.track.artist.name,
-                        line.filepath.track.language,
-                        line.filepath.track.instru and 'instru' or '',
-                        line.filepath.track.cfwb and 'cfwb' or '',
-                        line.filepath.track.added_to_nonstop_timestamp.strftime('%Y-%m-%d %H:%M')
-                        if line.filepath.track.added_to_nonstop_timestamp
-                        else '',
+                        line.play_timestamp.strftime('%Y-%m-%d'),
+                        line.play_timestamp.strftime('%H:%M'),
+                        line.track.title,
+                        line.track.artist.name if line.track.artist else '-',
+                        '%d:%d'
+                        % (
+                            int(line.track.duration.total_seconds() // 60),
+                            int(line.track.duration.total_seconds() % 60),
+                        ),
+                        '1',  # we only export music
+                        '0' if line.track.instru else '1',
+                        '1' if line.track.language == 'fr' else '0',
+                        '1' if line.track.cfwb else '0',
                     ]
                 )
-            else:
-                writer.writerow([line.play_timestamp.strftime('%Y-%m-%d %H:%M'), line.filepath.short])
+
         return HttpResponse(out.getvalue(), content_type='text/csv; charset=utf-8')