summaryrefslogtreecommitdiff
path: root/nop
diff options
context:
space:
mode:
Diffstat (limited to 'nop')
-rw-r--r--nop/views.py67
1 files changed, 30 insertions, 37 deletions
diff --git a/nop/views.py b/nop/views.py
index 9308c72..9e76d2f 100644
--- a/nop/views.py
+++ b/nop/views.py
@@ -12,10 +12,10 @@ import time
from datetime import datetime
DB = 'nop'
-MUSIKPROG_IDS = (1,5,12,17,34,60,81,89)
+MUSIKPROG_IDS = (1,5,17,34,60,81,89)
# 1 - unmodieriertes musikprogramm
# 5 - Abunda Lingva
- # 12 - aus den freien radios
+ ## 12 - aus den freien radios
# 17 - bumbumtschak
# 34 - fruehstück A
# 60 - musikprogramm bunt gemischt
@@ -25,14 +25,16 @@ MUSIKPROG_IDS = (1,5,12,17,34,60,81,89)
class NopForm(forms.Form):
date = forms.DateField(
required=True,
- initial=datetime.date(datetime.now()),
+ #initial=datetime.date(datetime.now()), ## static initial specifies
+ ## any time but not the
+ ## current one
widget=forms.DateInput(
format='%Y-%m-%d',
attrs={'id':'nop_date', 'class':'date'})
)
time = forms.TimeField(
required=True,
- initial=datetime.time(datetime.now()),
+ #initial=datetime.time(datetime.now()),
widget=forms.TimeInput(
format='%H:%M',
attrs={'id':'nop_time', 'class':'date'})
@@ -86,49 +88,39 @@ def _current():
'album': album}
def _bydate(year=None, month=None, day=None, hour=None, minute=None):
- #try:
- #import pdb;pdb.set_trace()
- show = _get_show(datetime(year, month, day, hour, minute))
- if show['id'] and show['id'] not in MUSIKPROG_IDS:
- return [{'show': show['name'],
- 'start': show['start'],
- 'artist': None,
- 'title': None,
- 'album': None}]
- else:
- # tm_year,tm_mon,tm_mday,tm_hour,tm_min,tm_sec,tm_wday,tm_yday,tm_isdst
- ts = int(time.mktime((
- int(year),
- int(month),
- int(day),
- 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
-
+ show = _get_show(datetime(year, month, day, hour, minute))
+ if show['id'] and show['id'] not in MUSIKPROG_IDS:
+ return [{'show': show['name'],
+ 'start': show['start'],
+ 'artist': None,
+ 'title': None,
+ 'album': None}]
+ else:
+ # tm_year,tm_mon,tm_mday,tm_hour,tm_min,tm_sec,tm_wday,tm_yday,tm_isdst
+ ts = int(time.mktime((
+ int(year),
+ int(month),
+ int(day),
+ 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]
def get_current(request):
response = json.dumps(_current())
-
return HttpResponse(response, mimetype='application/json')
- #return HttpResponse(response, mimetype='text/plain')
def get(request, year=None, month=None, day=None, hour=None, minute=None):
response = json.dumps(_bydate(year, month, day, hour, minute))
-
return HttpResponse(response, mimetype='application/json')
- #return HttpResponse(response, mimetype='text/plain')
-
def nop_form(request):
context = {}
- # currently no csrf security for nicier forms
+ ## currently no csrf security for nicier forms
#context.update(csrf(request)) # in django template: {% csrf_token %}
date = None
time = None
@@ -139,7 +131,8 @@ def nop_form(request):
date = form.cleaned_data['date']
time = form.cleaned_data['time']
else:
- form = NopForm()
+ form = NopForm(initial={'date':datetime.date(datetime.now()),
+ 'time':datetime.time(datetime.now())})
if not date: date = datetime.date(datetime.now())
if not time: time = datetime.time(datetime.now())
result = _bydate(date.year, date.month, date.day, time.hour, time.minute)