summaryrefslogtreecommitdiff
path: root/nop
diff options
context:
space:
mode:
authorJohannes Raggam <raggam-nl@adm.at>2011-05-26 12:22:29 (GMT)
committerJohannes Raggam <raggam-nl@adm.at>2011-05-26 12:22:29 (GMT)
commit519df73c5cf45f61a82fb63eafeb028d13ad4c4a (patch)
tree72816777f6543d5dfa01a9ccb53123a7896372a2 /nop
parent1ae6d14038307ff2cdd33e65154bce76690930d2 (diff)
add _which function which returns the table to use (standby or master). add constant which can be used to configure the database to be used
Diffstat (limited to 'nop')
-rw-r--r--nop/views.py20
1 files changed, 16 insertions, 4 deletions
diff --git a/nop/views.py b/nop/views.py
index 1faf7f4..411fb31 100644
--- a/nop/views.py
+++ b/nop/views.py
@@ -2,11 +2,13 @@ from django.core.context_processors import csrf
from django.shortcuts import render_to_response
from django.http import HttpResponse
from django import forms
-from models import Master
+from models import Master, Standby, State
import json
import time
from datetime import datetime
+DB = 'nop'
+
class NopForm(forms.Form):
date = forms.DateField(
required=True,
@@ -23,14 +25,24 @@ class NopForm(forms.Form):
attrs={'id':'nop_time', 'class':'date'})
)
+def _which(timestamp=None):
+ if timestamp:
+ res = State.objects.using(DB).filter(timestamp__lt=timestamp)[0]
+ else:
+ res = State.objects.using(DB).all()[0]
+ if not res or res.state == 'master':
+ return Master
+ else:
+ return Standby
+
def _current():
#current = int(time.time())*1000000
- #time.gmtime(Master.objects.using('nop').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
# reverse sorted. get the first object = last played
- result = Master.objects.using('nop').all()[0]
+ result = _which().objects.using(DB).all()[0]
return {'artist': result.artist, 'title': result.title}
def _bydate(year=None, month=None, day=None, hour=None, minute=None):
@@ -43,7 +55,7 @@ def _bydate(year=None, month=None, day=None, hour=None, minute=None):
int(hour),
int(minute),0,0,0,-1))) * 1000000
- result = Master.objects.using('nop').filter(timestamp__lt=ts)[:5]
+ result = _which(ts).objects.using(DB).filter(timestamp__lt=ts)[:5]
return [{'artist': item.artist, 'title': item.title, 'album': item.album,
'datetime': time.strftime('%Y-%m-%d %H:%M',
time.localtime(item.timestamp//1000000)),