programs/urls.py: update views

This commit is contained in:
bkfox
2016-09-10 20:12:00 +02:00
parent edd4c7ec87
commit 2e4c97b846
7 changed files with 478 additions and 314 deletions

View File

@ -190,6 +190,8 @@ class Source:
"""
Related source
"""
name = 'dealer'
path = ''
"""
Path to the Source's playlist file. Optional.
@ -226,6 +228,8 @@ class Source:
self.connector = self.station.streamer.connector
self.__dict__.update(kwargs)
self.__init_playlist()
if self.program:
self.name = self.program.name
#
# Playlist

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-08-11 17:07+0200\n"
"POT-Creation-Date: 2016-09-10 17:54+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -18,244 +18,300 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
#: programs/admin.py:89 programs/models.py:461
#: programs/admin.py:82 programs/models.py:648
msgid "Schedule"
msgstr ""
#: programs/admin.py:119 programs/models.py:632
#: programs/admin.py:112 programs/models.py:451
msgid "end"
msgstr ""
#: programs/admin.py:160
#: programs/admin.py:153
msgid "Program"
msgstr ""
#: programs/admin.py:164
#: programs/admin.py:157
msgid "Day"
msgstr ""
#: programs/admin.py:168
#: programs/admin.py:161
msgid "Rerun"
msgstr ""
#: programs/models.py:95
#: programs/models.py:98
msgid "name"
msgstr ""
#: programs/models.py:128
msgid "diffusion"
#: programs/models.py:131
msgid "path"
msgstr ""
#: programs/models.py:130
msgid "this is set for scheduled programs"
#: programs/models.py:132
msgid "path to the working directory"
msgstr ""
#: programs/models.py:133 programs/models.py:671
msgid "type"
#: programs/models.py:295 programs/models.py:995 programs/models.py:1050
msgid "station"
msgstr ""
#: programs/models.py:138
msgid "file"
msgstr ""
#: programs/models.py:147
msgid "embed HTML code"
msgstr ""
#: programs/models.py:149
msgid "HTML code used to embed a sound from external plateform"
msgstr ""
#: programs/models.py:152 programs/models.py:298
msgid "duration"
msgstr ""
#: programs/models.py:154
msgid "duration of the sound"
msgstr ""
#: programs/models.py:157
msgid "modification time"
msgstr ""
#: programs/models.py:159
msgid "last modification date and time"
msgstr ""
#: programs/models.py:162
msgid "good quality"
msgstr ""
#: programs/models.py:164
msgid "sound's quality is okay"
msgstr ""
#: programs/models.py:167
msgid "public"
msgstr ""
#: programs/models.py:169
msgid "the sound is accessible to the public"
msgstr ""
#: programs/models.py:267
msgid "Sound"
msgstr ""
#: programs/models.py:268
msgid "Sounds"
msgstr ""
#: programs/models.py:294 programs/models.py:618
msgid "related program"
msgstr ""
#: programs/models.py:296
msgid "date"
msgstr ""
#: programs/models.py:299
msgid "regular duration"
msgstr ""
#: programs/models.py:302
msgid "frequency"
msgstr ""
#: programs/models.py:305
msgid "first week of the month"
msgstr ""
#: programs/models.py:306
msgid "second week of the month"
msgstr ""
#: programs/models.py:307
msgid "third week of the month"
msgstr ""
#: programs/models.py:308
msgid "fourth week of the month"
msgstr ""
#: programs/models.py:309
msgid "last week of the month"
msgstr ""
#: programs/models.py:310
msgid "first and third weeks of the month"
msgstr ""
#: programs/models.py:311
msgid "second and fourth weeks of the month"
msgstr ""
#: programs/models.py:312
msgid "every week"
msgstr ""
#: programs/models.py:313
msgid "one week on two"
msgstr ""
#: programs/models.py:319 programs/models.py:676
msgid "initial"
msgstr ""
#: programs/models.py:462
msgid "Schedules"
msgstr ""
#: programs/models.py:479
#: programs/models.py:298 programs/models.py:1003
msgid "active"
msgstr ""
#: programs/models.py:481
#: programs/models.py:300
msgid "if not set this program is no longer active"
msgstr ""
#: programs/models.py:621
#: programs/models.py:437 programs/models.py:481
msgid "related program"
msgstr ""
#: programs/models.py:440
msgid "delay"
msgstr ""
#: programs/models.py:623
#: programs/models.py:442
msgid "delay between two sound plays"
msgstr ""
#: programs/models.py:626
#: programs/models.py:445
msgid "begin"
msgstr ""
#: programs/models.py:628 programs/models.py:634
#: programs/models.py:447 programs/models.py:453
msgid "used to define a time range this stream isplayed"
msgstr ""
#: programs/models.py:667
#: programs/models.py:483 programs/models.py:1062
msgid "date"
msgstr ""
#: programs/models.py:485 programs/models.py:812
msgid "duration"
msgstr ""
#: programs/models.py:486
msgid "regular duration"
msgstr ""
#: programs/models.py:489
msgid "frequency"
msgstr ""
#: programs/models.py:492
msgid "first week of the month"
msgstr ""
#: programs/models.py:493
msgid "second week of the month"
msgstr ""
#: programs/models.py:494
msgid "third week of the month"
msgstr ""
#: programs/models.py:495
msgid "fourth week of the month"
msgstr ""
#: programs/models.py:496
msgid "last week of the month"
msgstr ""
#: programs/models.py:497
msgid "first and third weeks of the month"
msgstr ""
#: programs/models.py:498
msgid "second and fourth weeks of the month"
msgstr ""
#: programs/models.py:499
msgid "every week"
msgstr ""
#: programs/models.py:500
msgid "one week on two"
msgstr ""
#: programs/models.py:506 programs/models.py:689
msgid "initial"
msgstr ""
#: programs/models.py:649
msgid "Schedules"
msgstr ""
#: programs/models.py:680 programs/models.py:782
msgid "program"
msgstr ""
#: programs/models.py:678
#: programs/models.py:684 programs/models.py:793 programs/models.py:998
#: programs/models.py:1044
msgid "type"
msgstr ""
#: programs/models.py:691
msgid "the diffusion is a rerun of this one"
msgstr ""
#: programs/models.py:680
#: programs/models.py:693
msgid "start of the diffusion"
msgstr ""
#: programs/models.py:681
#: programs/models.py:694
msgid "end of the diffusion"
msgstr ""
#: programs/models.py:748
#: programs/models.py:761
msgid "Diffusion"
msgstr ""
#: programs/models.py:749
#: programs/models.py:762
msgid "Diffusions"
msgstr ""
#: programs/models.py:752
#: programs/models.py:765
msgid "edit the diffusion's planification"
msgstr ""
#: programs/models.py:765
#: programs/models.py:784
msgid "program related to it"
msgstr ""
#: programs/models.py:788
msgid "diffusion"
msgstr ""
#: programs/models.py:790
msgid "initial diffusion related it"
msgstr ""
#: programs/models.py:798
msgid "file"
msgstr ""
#: programs/models.py:807
msgid "embed HTML code"
msgstr ""
#: programs/models.py:809
msgid "HTML code used to embed a sound from external plateform"
msgstr ""
#: programs/models.py:814
msgid "duration of the sound"
msgstr ""
#: programs/models.py:817
msgid "modification time"
msgstr ""
#: programs/models.py:819
msgid "last modification date and time"
msgstr ""
#: programs/models.py:822
msgid "good quality"
msgstr ""
#: programs/models.py:824
msgid "sound's quality is okay"
msgstr ""
#: programs/models.py:827
msgid "public"
msgstr ""
#: programs/models.py:829
msgid "the sound is accessible to the public"
msgstr ""
#: programs/models.py:927
msgid "Sound"
msgstr ""
#: programs/models.py:928
msgid "Sounds"
msgstr ""
#: programs/models.py:940
msgid "title"
msgstr ""
#: programs/models.py:769
#: programs/models.py:944
msgid "artist"
msgstr ""
#: programs/models.py:773
#: programs/models.py:948
msgid "tags"
msgstr ""
#: programs/models.py:777
#: programs/models.py:952
msgid "information"
msgstr ""
#: programs/models.py:780
#: programs/models.py:955
msgid ""
"additional informations about this track, such as the version, if is it a "
"remix, features, etc."
msgstr ""
#: programs/models.py:785
#: programs/models.py:960
msgid "position in the playlist"
msgstr ""
#: programs/models.py:788
#: programs/models.py:963
msgid "in seconds"
msgstr ""
#: programs/models.py:790
#: programs/models.py:965
msgid "position in the playlist is expressed in seconds"
msgstr ""
#: programs/models.py:797
#: programs/models.py:972
msgid "Track"
msgstr ""
#: programs/models.py:798
#: programs/models.py:973
msgid "Tracks"
msgstr ""
#: programs/models.py:1005
msgid "this output is active"
msgstr ""
#: programs/models.py:1008
msgid "output settings"
msgstr ""
#: programs/models.py:1009
msgid ""
"list of comma separated params available; this is put in the output config "
"as raw code; plugin related"
msgstr ""
#: programs/models.py:1051
msgid "station on which the event occured"
msgstr ""
#: programs/models.py:1056
msgid "source"
msgstr ""
#: programs/models.py:1058
msgid "source id that make it happen on the station"
msgstr ""
#: programs/models.py:1066
msgid "comment"
msgstr ""
#: programs/templates/aircox/controllers/monitor.html:107
#: programs/templates/aircox/controllers/monitor.html:117
msgid "skip"
msgstr ""
#: programs/templates/aircox/controllers/monitor.html:108
msgid "update"
msgstr ""

View File

@ -141,30 +141,27 @@ class Station(Nameable):
__dealer = None
__streamer = None
def __prepare(self):
import aircox.programs.controllers as controllers
if not self.__streamer:
self.__streamer = controllers.Streamer(station = self)
self.__dealer = controllers.Source(station = self)
self.__sources = [
controllers.Source(station = self, program = program)
for program in Program.objects.filter(stream__isnull = False)
] + [ self.__dealer ]
@property
def sources(self):
"""
Audio sources, dealer included
"""
# force streamer creation
streamer = self.streamer
if not self.__sources:
import aircox.programs.controllers as controllers
self.__sources = [
controllers.Source(station = self, program = program)
for program in Program.objects.filter(stream__isnull = False)
] + [ self.dealer ]
self.__prepare()
return self.__sources
@property
def dealer(self):
# force streamer creation
streamer = self.streamer
if not self.__dealer:
import aircox.programs.controllers as controllers
self.__dealer = controllers.Source(station = self)
self.__prepare()
return self.__dealer
@property
@ -172,9 +169,7 @@ class Station(Nameable):
"""
Audio controller for the station
"""
if not self.__streamer:
import aircox.programs.controllers as controllers
self.__streamer = controllers.Streamer(station = self)
self.__prepare()
return self.__streamer
def get_played(self, models, archives = True):
@ -262,7 +257,7 @@ class Station(Nameable):
else:
diffs = Diffusion.objects
diffs = diffs.filter(station = self) \
diffs = diffs.filter(program__station = self) \
.filter(type = Diffusion.Type.normal) \
.filter(start__lte = tz.now())
return self.__mix_logs_and_diff(diffs, logs, count)

View File

@ -60,7 +60,7 @@ var Monitor = {
params += '&&source=' + source;
var req = new XMLHttpRequest()
req.open('POST', '{% url 'controllers.monitor' %}', false);
req.open('POST', '{% url 'aircox.monitor' %}', false);
req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
req.setRequestHeader("Content-length", params.length);
req.setRequestHeader("Connection", "close");
@ -75,7 +75,7 @@ var Monitor = {
update: function(timeout) {
var req = new XMLHttpRequest()
req.open('GET', '{% url 'controllers.monitor' %}', true);
req.open('GET', '{% url 'aircox.monitor' %}', true);
req.onreadystatechange = function() {
if(req.readyState != 4 || (req.status != 200 && req.status != 0))
return;

View File

@ -1,15 +1,124 @@
from django.db import models
from django.shortcuts import render
from django.core.serializers.json import DjangoJSONEncoder
from django.utils import timezone, dateformat
import json
from django.views.generic import ListView
from django.views.generic import DetailView
from django.utils.translation import ugettext as _, ugettext_lazy
from django.views.generic.base import View, TemplateResponseMixin
from django.contrib.auth.mixins import LoginRequiredMixin
from django.http import HttpResponse, Http404
from django.shortcuts import render
from django.utils.translation import ugettext as _, ugettext_lazy
from django.utils import timezone as tz
from aircox.programs.models import *
import aircox.programs.settings
import aircox.programs.utils
import aircox.programs.models as models
class Stations:
stations = models.Station.objects.all()
update_timeout = None
fetch_timeout = None
def fetch(self):
if self.fetch_timeout and self.fetch_timeout > tz.now():
return
self.fetch_timeout = tz.now() + tz.timedelta(seconds = 5)
for station in self.stations:
station.streamer.fetch()
stations = Stations()
def on_air(request):
try:
import aircox.cms.models as cms
except:
cms = None
station = request.GET.get('station');
if station:
station = stations.stations.filter(name = station)
else:
station = stations.stations.first()
last = station.on_air(count = 1)
if not last:
return HttpResponse('')
last = last[0]
if type(last) == models.Log:
last = {
'type': 'track',
'artist': last.related.artist,
'title': last.related.title,
'date': last.date,
}
else:
try:
publication = None
if cms:
publication = \
cms.DiffusionPage.objects.filter(
diffusion = last.initial or last).first() or \
cms.ProgramPage.objects.filter(
program = last.program).first()
except:
pass
last = {
'type': 'diffusion',
'title': last.program.name,
'date': last.start,
'url': publication.specific.url if publication else None,
}
last['date'] = str(last['date'])
return HttpResponse(json.dumps(last))
# TODO:
# - login url
class Monitor(View,TemplateResponseMixin,LoginRequiredMixin):
template_name = 'aircox/controllers/monitor.html'
def get_context_data(self, **kwargs):
stations.fetch()
return { 'stations': stations.stations }
def get (self, request = None, **kwargs):
if not request.user.is_active:
return Http404()
self.request = request
context = self.get_context_data(**kwargs)
return render(request, self.template_name, context)
def post (self, request = None, **kwargs):
if not request.user.is_active:
return Http404()
if not ('action' or 'station') in request.POST:
return HttpResponse('')
POST = request.POST
controller = POST.get('controller')
action = POST.get('action')
station = stations.stations.filter(name = POST.get('station')) \
.first()
if not station:
return HttpResponse('')
station.prepare(fetch=True)
source = None
if 'source' in POST:
source = next([ s for s in station.sources
if s.name == POST['source']], None)
if station and action == 'skip':
if source:
source.skip()
else:
station.streamer.skip()
return HttpResponse('')