window.setInterval(update_clock, 500);
});
</script>
+
+<div id="tracks">
+ <button>{% trans "Get tracks" %}</button>
+ <ul>
+ </ul>
+</div>
+
+<script>
+$(function() {
+ const track_language_labels = {
+ 'na': 'instru',
+ 'fr': 'french',
+ 'en': 'english',
+ 'nl': 'dutch',
+ 'other': 'other',
+ };
+ $('#tracks button').on('click', function() {
+ $.ajax('/regie/tracks').success(function(data) {
+ for (const track of data.data) {
+ var $line = $('<li></li>')
+ var $remove_button = $('<button>×</button>');
+ $remove_button.on('click', function() {
+ $(this).parent().remove();
+ });
+ $line.append($remove_button);
+ $line.append('<audio preload controls src="/nonstop/tracks/' + track.id + '/sound/"></audio>')
+ $line.append($('<span></span>', {'class': 'title', 'text': track.title}));
+ if (track.artist) {
+ $line.append($('<span class="sep"> - </span>'));
+ $line.append($('<span></span>', {'class': 'artist', 'text': track.artist}));
+ }
+ if (track.language) {
+ $line.append(' ');
+ $line.append($('<span></span>', {'class': 'type', 'text': '(' + track_language_labels[track.language] + ')'}));
+ }
+ $('#tracks').find('ul').append($line);
+ }
+ });
+ });
+});
+</script>
+
{% endblock %}
{% block sidebar %}
urlpatterns = [
url(r'^$', views.home, name='home'),
url(r'^regie/$', views.regie_home, name='regie-home'),
+ url(r'^regie/tracks/$', views.regie_tracks, name='regie-tracks'),
url(r'^ckeditor/upload/', login_required(ckeditor_upload)),
url(r'^ckeditor/browse/', login_required(ckeditor_browse)),
from django.contrib.auth.forms import AuthenticationForm
from django.core.exceptions import PermissionDenied
from django.core.urlresolvers import reverse
+from django.http import JsonResponse
from django.template import loader
from django.views.generic.base import TemplateView, RedirectView
from django.views.generic.list import ListView
regie_home = RegieHome.as_view()
+def regie_tracks(request):
+ from emissions.models import Nonstop
+ from nonstop.models import Track
+
+ now = datetime.datetime.now()
+ current_zone = None
+ for nonstop in Nonstop.objects.all():
+ if (nonstop.start < nonstop.end and (
+ now.time() >= nonstop.start and now.time() < nonstop.end)) or \
+ (nonstop.start > nonstop.end and (
+ now.time() >= nonstop.start or now.time() < nonstop.end)):
+ current_zone = nonstop
+ break
+
+ tracks = Track.objects.filter(duration__isnull=False)
+ tracks = tracks.filter(duration__gte=datetime.timedelta(minutes=2, seconds=30))
+ tracks = tracks.filter(duration__lt=datetime.timedelta(minutes=4, seconds=30))
+ if current_zone:
+ tracks = tracks.filter(nonstop_zones__in=[current_zone.id])
+ tracks = tracks.exclude(language__isnull=True).exclude(language='')
+ tracks = tracks.order_by('?')
+
+ return JsonResponse({'data': [
+ {
+ 'id': track.id,
+ 'title': track.title,
+ 'artist': track.artist.name if track.artist_id else None,
+ 'instru': track.instru,
+ 'language': track.language,
+ } for track in tracks[:5]]})
+
+
class EmissionListView(emissions.views.EmissionListView):
pass