Commit 30f15f25 authored by fred's avatar fred

add logging to nonstop actions

parent 00d3e76f
......@@ -2,6 +2,7 @@ import collections
import copy
import csv
import datetime
import logging
import os
import subprocess
import tempfile
......@@ -44,6 +45,9 @@ from . import utils
from .app_settings import app_settings
logger = logging.getLogger('panikdb')
class SomaDayArchiveView(DayArchiveView):
queryset = SomaLogLine.objects.all()
date_field = "play_timestamp"
......@@ -94,13 +98,34 @@ class TrackDetailView(DetailView):
def post(self, request, *args, **kwargs):
assert self.request.user.has_perm('nonstop.add_track')
instance = self.get_object()
had_zones = instance.nonstop_zones.all().exists()
previous_zones = set([x.title for x in instance.nonstop_zones.all()])
form = TrackMetaForm(request.POST, instance=instance)
form.save()
if instance.nonstop_zones.all().exists():
if not had_zones:
new_zones = set([x.title for x in instance.nonstop_zones.all()])
if new_zones:
if previous_zones == new_zones:
pass
elif previous_zones:
logger.info(
'changed nonstop zones for track "%s" (%s) (from %s to %s)',
instance.title,
instance.id,
', '.join(previous_zones),
', '.join(new_zones),
)
else:
logger.info(
'added track "%s" (%s) to nonstop (%s)', instance.title, instance.id, ', '.join(new_zones)
)
instance.added_to_nonstop_timestamp = now()
else:
if previous_zones:
logger.info(
'removed track "%s" (%s) from nonstop (%s)',
instance.title,
instance.id,
', '.join(previous_zones),
)
instance.added_to_nonstop_timestamp = None
instance.save()
return HttpResponseRedirect('.')
......@@ -382,6 +407,7 @@ class UploadTracksView(FormView):
title=track_title, artist=artist, defaults={'uploader': self.request.user}
)
if created or not track.file_exists():
logger.info('uploaded track "%s" (%s)', track.title, track.id)
default_storage.save(os.path.join('nonstop', 'tracks', filepath), content=f)
nonstop_file = NonstopFile()
nonstop_file.set_track_filepath(filepath)
......@@ -391,7 +417,9 @@ class UploadTracksView(FormView):
# don't keep duplicated file and do not create a duplicated nonstop file object
pass
if request.POST.get('nonstop_zone'):
track.nonstop_zones.add(Nonstop.objects.get(id=request.POST.get('nonstop_zone')))
nonstop_zone = Nonstop.objects.get(id=request.POST.get('nonstop_zone'))
track.nonstop_zones.add(nonstop_zone)
logger.info('added track "%s" (%s) to nonstop (%s)', track.title, track.id, nonstop_zone)
if not track.added_to_nonstop_timestamp:
track.added_to_nonstop_timestamp = now()
track.save()
......@@ -564,6 +592,7 @@ class CleanupView(TemplateView):
if request.POST.get('remove-%s' % track_id):
track = Track.objects.get(id=track_id)
track.nonstop_zones.clear()
logger.info('cleaned up track "%s" (%s) from nonstop', track.title, track.id)
count += 1
if count:
messages.info(self.request, 'Removed %d new track(s)' % count)
......@@ -607,6 +636,7 @@ class AddSomaDiffusionView(CreateView):
reverse('episode-view', kwargs={'emission_slug': episode.emission.slug, 'slug': episode.slug})
)
response = super(AddSomaDiffusionView, self).form_valid(form)
logger.info('registered diffusion (%s)', form.instance.diffusion)
messages.info(self.request, _('%s added to schedule') % episode.emission.title)
return response
......@@ -619,6 +649,7 @@ class AddSomaDiffusionView(CreateView):
class DelSomaDiffusionView(RedirectView):
def get_redirect_url(self, pk):
soma_diffusion = ScheduledDiffusion.objects.filter(diffusion_id=pk).first()
logger.info('removed diffusion (%s)', soma_diffusion.diffusion)
episode = soma_diffusion.episode
ScheduledDiffusion.objects.filter(diffusion_id=pk).update(diffusion_id=None)
messages.info(self.request, _('%s removed from schedule') % episode.emission.title)
......@@ -751,6 +782,7 @@ class ZoneSettings(FormView):
zone_settings.weights = weights
zone.save()
zone_settings.save()
logger.info('updated nonstop settings for %s', zone)
return super().form_valid(form)
......@@ -814,6 +846,7 @@ class ZoneTracklistPercents(DetailView):
def force_switch_view(request, *args, **kwargs):
logger.info('forced switch back to nonstop')
messages.info(request, 'Forced back switch to nonstop')
requests.post(app_settings.ON_AIR_SWITCH_URL, data={'s': '0'})
return HttpResponseRedirect(reverse('nonstop-quick-links'))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment