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