Skip to content
Snippets Groups Projects
Commit d04d0ad1 authored by Johannes Raggam's avatar Johannes Raggam
Browse files

show show title instead of tracks if show is not musikprogram

parent 519df73c
No related branches found
No related tags found
No related merge requests found
...@@ -36,11 +36,21 @@ ...@@ -36,11 +36,21 @@
<ul> <ul>
{% for track in nowplaying %} {% for track in nowplaying %}
<li> <li>
<small>{{track.datetime}}:</small> {% if track.start or track.show %}
<strong>{{track.artist}}</strong> - <small>
{{track.title}} - {% if track.start %}{{track.start}}{% endif %}
{{track.album}} {% if track.start and track.show %},{% endif %}
in der Sendung <em>{{track.showtitle}}</em> {% if track.show %}Sendung {{track.show}}{% endif %}
{% if track.artist or track.title or track.album %}:{% endif %}
</small>
{% endif %}
{% if track.artist %}
<strong>{{track.artist}}</strong>
{% endif %}
{% if track.artist and track.title or track.artist and track.album %}|{% endif %}
{% if track.title %}{{track.title}}{% endif %}
{% if track.title and track.album %}|{% endif %}
{% if track.album %}{{track.album}}{% endif %}
</li> </li>
{% endfor %} {% endfor %}
</ul> </ul>
......
...@@ -3,11 +3,14 @@ from django.shortcuts import render_to_response ...@@ -3,11 +3,14 @@ from django.shortcuts import render_to_response
from django.http import HttpResponse from django.http import HttpResponse
from django import forms from django import forms
from models import Master, Standby, State from models import Master, Standby, State
from program.models import TimeSlot
import json import json
import time import time
from datetime import datetime from datetime import datetime
DB = 'nop' DB = 'nop'
MUSIKPROG_ID = 1 # unmodieriertes musikprogramm
class NopForm(forms.Form): class NopForm(forms.Form):
date = forms.DateField( date = forms.DateField(
...@@ -25,6 +28,9 @@ class NopForm(forms.Form): ...@@ -25,6 +28,9 @@ class NopForm(forms.Form):
attrs={'id':'nop_time', 'class':'date'}) attrs={'id':'nop_time', 'class':'date'})
) )
def _dtstring(dt):
return time.strftime('%Y-%m-%d %H:%M', dt)
def _which(timestamp=None): def _which(timestamp=None):
if timestamp: if timestamp:
res = State.objects.using(DB).filter(timestamp__lt=timestamp)[0] res = State.objects.using(DB).filter(timestamp__lt=timestamp)[0]
...@@ -35,33 +41,66 @@ def _which(timestamp=None): ...@@ -35,33 +41,66 @@ def _which(timestamp=None):
else: else:
return Standby return Standby
def _get_show(datetime = None):
try:
if datetime:
timeslot = TimeSlot.objects.get(start__lte=datetime, end__gt=datetime)
else:
timeslot = TimeSlot.objects.get_or_create_current()
return {'start': _dtstring(timeslot.start.timetuple()),
'id': timeslot.show.id,
'name': timeslot.show.name}
except: # e.g. DoesNotExist
return {'start': None, 'id': None, 'name': None}
def _current(): def _current():
#current = int(time.time())*1000000 #current = int(time.time())*1000000
#time.gmtime(_which().objects.using(DB).all()[6000].timestamp//1000000) #time.gmtime(_which().objects.using(DB).all()[6000].timestamp//1000000)
# select all where timestamp < givenTS, get most recent one -> order DESC # select all where timestamp < givenTS, get most recent one -> order DESC
# reverse sorted. get the first object = last played artist = None
result = _which().objects.using(DB).all()[0] title = None
return {'artist': result.artist, 'title': result.title} album = None
show = _get_show()
if show['id'] == MUSIKPROG_ID:
# reverse sorted. get the first object = last played
result = _which().objects.using(DB).all()[0]
artist = result.artist
title = result.title
album = result.album
return {'show': show['name'],
'start': show['start'],
'artist': artist,
'title': title,
'album': album}
def _bydate(year=None, month=None, day=None, hour=None, minute=None): def _bydate(year=None, month=None, day=None, hour=None, minute=None):
try: #try:
# tm_year,tm_mon,tm_mday,tm_hour,tm_min,tm_sec,tm_wday,tm_yday,tm_isdst #import pdb;pdb.set_trace()
ts = int(time.mktime(( show = _get_show(datetime(year, month, day, hour, minute))
int(year), if show['id'] and show['id'] != MUSIKPROG_ID:
int(month), return [{'show': show['name'],
int(day), 'start': show['start'],
int(hour), 'artist': None,
int(minute),0,0,0,-1))) * 1000000 'title': None,
'album': None}]
result = _which(ts).objects.using(DB).filter(timestamp__lt=ts)[:5] else:
return [{'artist': item.artist, 'title': item.title, 'album': item.album, # tm_year,tm_mon,tm_mday,tm_hour,tm_min,tm_sec,tm_wday,tm_yday,tm_isdst
'datetime': time.strftime('%Y-%m-%d %H:%M', ts = int(time.mktime((
time.localtime(item.timestamp//1000000)), int(year),
'showtitle': item.showtitle} for item in result] int(month),
except: # all errors int(day),
return None int(hour),
int(minute),0,0,0,-1))) * 1000000
result = _which(ts).objects.using(DB).filter(timestamp__lt=ts)[:5]
return [{'show': show['name'],
'start': _dtstring(time.localtime(item.timestamp//1000000)),
'artist': item.artist,
'title': item.title,
'album': item.album} for item in result]
#except: # all errors
# return None
def get_current(request): def get_current(request):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment