--- /dev/null
+import time
+
+from django.core.management.base import BaseCommand
+from django.db.models import Q
+
+from ...models import StreamedDiffusion
+from ...utils import add_soma_diffusion, remove_soma_diffusion
+
+
+class Command(BaseCommand):
+ def handle(self, verbosity, **kwargs):
+ diffusions = StreamedDiffusion.objects.filter(
+ Q(diffusion__isnull=True) | Q(added_to_nonstop_timestamp__isnull=True))
+ if not diffusions.exists():
+ return
+
+ for diffusion in diffusions:
+ if diffusion.diffusion_id is None:
+ remove_soma_diffusion(diffusion)
+ else:
+ add_soma_diffusion(diffusion)
+ time.sleep(5) # give some time to soma (...)
import time
from django.template import loader
+from django.utils.timezone import now
import xml.etree.ElementTree as ET
from .models import Track, SomaLogLine, StreamedDiffusion, Jingle, LOCAL_BASE_PATH
return s
-def add_diffusion(diffusion, **kwargs):
+def add_soma_diffusion(diffusion):
context = {}
context['diffusion'] = diffusion
context['jingle'] = diffusion.jingle
palinsesti_template = loader.get_template('nonstop/soma_palinsesti.xml')
palinsesti = palinsesti_template.render(context)
- open('/tmp/soma.xml', 'w').write(palinsesti)
- return
palinsesti_xml = ET.fromstring(palinsesti.encode('utf-8'))
palinsesto_xml = get_palinsesto_xml()
palinsesto_xml.append(palinsesti_xml)
send_palinsesto_xml(palinsesto_xml)
+ diffusion.added_to_nonstop_timestamp = now()
+ diffusion.save()
def remove_soma_diffusion(diffusion):
'emission_slug': episode.emission.slug,
'slug': episode.slug}))
response = super(AddSomaDiffusionView, self).form_valid(form)
- try:
- utils.add_diffusion(form.instance)
- except utils.SomaException as e:
- messages.error(self.request, _('technical soma error (%s)') % e)
- else:
- messages.info(self.request, _('%s added to soma') % episode.emission.title)
+ messages.info(self.request, _('%s added to schedule') % episode.emission.title)
return response
def get_success_url(self):
diffusion = Diffusion.objects.get(id=self.kwargs['pk'])
episode = diffusion.episode
+ messages.info(self.request, _('%s removed from schedule') % episode.emission.title)
return reverse('episode-view', kwargs={
'emission_slug': episode.emission.slug,
'slug': episode.slug})