summaryrefslogtreecommitdiff
path: root/nop
diff options
context:
space:
mode:
Diffstat (limited to 'nop')
-rw-r--r--nop/dbrouter.py5
-rw-r--r--nop/migrations/0001_initial.py60
-rw-r--r--nop/migrations/__init__.py0
-rw-r--r--nop/models.py1
-rw-r--r--nop/urls.py15
-rw-r--r--nop/views.py21
6 files changed, 86 insertions, 16 deletions
diff --git a/nop/dbrouter.py b/nop/dbrouter.py
new file mode 100644
index 0000000..fd8aaad
--- /dev/null
+++ b/nop/dbrouter.py
@@ -0,0 +1,5 @@
+class NopRouter(object):
+ def allow_migrate(self, db, app_label, model_name=None, **hints):
+ if app_label == 'nop':
+ return db == 'nop'
+ return None
diff --git a/nop/migrations/0001_initial.py b/nop/migrations/0001_initial.py
new file mode 100644
index 0000000..67a04e8
--- /dev/null
+++ b/nop/migrations/0001_initial.py
@@ -0,0 +1,60 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ app_label = 'nop'
+
+ dependencies = [
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name='Master',
+ fields=[
+ ('timestamp', models.BigIntegerField(serialize=False, primary_key=True)),
+ ('cart', models.IntegerField()),
+ ('len', models.IntegerField(null=True, blank=True)),
+ ('showtitle', models.CharField(max_length=765, blank=True)),
+ ('title', models.CharField(max_length=765, blank=True)),
+ ('artist', models.CharField(max_length=765, blank=True)),
+ ('album', models.CharField(max_length=765, blank=True)),
+ ('ismusic', models.IntegerField(null=True, blank=True)),
+ ],
+ options={
+ 'ordering': ['-timestamp'],
+ 'db_table': 'master',
+ },
+ ),
+ migrations.CreateModel(
+ name='Standby',
+ fields=[
+ ('timestamp', models.BigIntegerField(serialize=False, primary_key=True)),
+ ('cart', models.IntegerField()),
+ ('len', models.IntegerField(null=True, blank=True)),
+ ('showtitle', models.CharField(max_length=765, blank=True)),
+ ('title', models.CharField(max_length=765, blank=True)),
+ ('artist', models.CharField(max_length=765, blank=True)),
+ ('album', models.CharField(max_length=765, blank=True)),
+ ('ismusic', models.IntegerField(null=True, blank=True)),
+ ],
+ options={
+ 'ordering': ['-timestamp'],
+ 'db_table': 'standby',
+ },
+ ),
+ migrations.CreateModel(
+ name='State',
+ fields=[
+ ('timestamp', models.BigIntegerField(serialize=False, primary_key=True)),
+ ('state', models.CharField(max_length=96, blank=True)),
+ ],
+ options={
+ 'ordering': ['-timestamp'],
+ 'db_table': 'state',
+ },
+ ),
+ ]
diff --git a/nop/migrations/__init__.py b/nop/migrations/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/nop/migrations/__init__.py
diff --git a/nop/models.py b/nop/models.py
index 6aeb794..1b39eed 100644
--- a/nop/models.py
+++ b/nop/models.py
@@ -30,6 +30,7 @@ class Standby(models.Model):
db_table = u'standby'
ordering = ['-timestamp']
+
class State(models.Model):
timestamp = models.BigIntegerField(primary_key=True)
state = models.CharField(max_length=96, blank=True)
diff --git a/nop/urls.py b/nop/urls.py
index c4012a6..3cc97a4 100644
--- a/nop/urls.py
+++ b/nop/urls.py
@@ -1,14 +1,13 @@
-from django.conf.urls.defaults import *
+from django.conf.urls import patterns, url
from views import get, get_current, nop_form
import os
-NOP_STATIC_DIR = os.path.join(os.path.dirname(__file__), 'site_media')
+NOP_SITE_MEDIA = os.path.join(os.path.dirname(__file__), 'site_media')
-urlpatterns = patterns(
- '',
- url(r'^/get_current/?$', get_current),
- url(r'^/(?P<year>\d{4})/(?P<month>\d{1,2})/(?P<day>\d{1,2})/(?P<hour>\d{1,2})/(?P<minute>\d{1,2})/?$', get),
- url(r'^/?$', nop_form),
- url(r'^/static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': NOP_STATIC_DIR}),
+urlpatterns = patterns('',
+ url(r'^/get_current/?$', get_current),
+ url(r'^/(?P<year>\d{4})/(?P<month>\d{1,2})/(?P<day>\d{1,2})/(?P<hour>\d{1,2})/(?P<minute>\d{1,2})/?$', get),
+ url(r'^/?$', nop_form),
+ url(r'^/static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': NOP_SITE_MEDIA}),
)
diff --git a/nop/views.py b/nop/views.py
index 6bbdcf8..12e2ada 100644
--- a/nop/views.py
+++ b/nop/views.py
@@ -5,7 +5,7 @@ from django.shortcuts import render_to_response
from django.http import HttpResponse
from django import forms
from models import Master, Standby, State
-from program.models import TimeSlot, Note
+from program.models import TimeSlot
import json
import time
@@ -60,7 +60,8 @@ def _which(timestamp=None):
def _get_show(datetime=None):
try:
if datetime:
- timeslot = TimeSlot.objects.get(start__lte=datetime, end__gt=datetime)
+ timeslot = TimeSlot.objects.get(start__lte=datetime,
+ end__gt=datetime)
else:
timeslot = TimeSlot.objects.get_or_create_current()
except (ObjectDoesNotExist, MultipleObjectsReturned):
@@ -83,7 +84,8 @@ def _current():
album = None
show = _get_show()
- if show['id'] in MUSIKPROG_IDS or (show['id'] in SPECIAL_PROGRAM_IDS and not show['note']):
+ if show['id'] in MUSIKPROG_IDS \
+ or (show['id'] in SPECIAL_PROGRAM_IDS and not show['note']):
result = _which().objects.using(DB).all()[0]
artist = result.artist
title = result.title
@@ -106,7 +108,8 @@ def _bydate(year=None, month=None, day=None, hour=None, minute=None):
'title': None,
'album': None}]
else:
- ts = int(time.mktime((int(year), int(month), int(day), int(hour), int(minute), 0, 0, 0, -1))) * 1000000
+ 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)),
@@ -117,12 +120,12 @@ def _bydate(year=None, month=None, day=None, hour=None, minute=None):
def get_current(request):
response = json.dumps(_current())
- return HttpResponse(response, mimetype='application/json')
+ return HttpResponse(response, content_type='application/json')
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, content_type='application/json')
def nop_form(request):
@@ -130,14 +133,16 @@ def nop_form(request):
date = None
time = None
- if request.method == 'GET' and ('date' in request.GET or 'time' in request.GET):
+ if request.method == 'GET' \
+ and ('date' in request.GET or 'time' in request.GET):
form = NopForm(request.GET)
if form.is_valid():
date = form.cleaned_data['date']
time = form.cleaned_data['time']
else:
- form = NopForm(initial={'date': datetime.date(datetime.now()), 'time': datetime.time(datetime.now())})
+ form = NopForm(initial={'date': datetime.date(datetime.now()),
+ 'time': datetime.time(datetime.now())})
if not date:
date = datetime.date(datetime.now())