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')