From 11ff3ea58c83f82e4d9d7b58f4f57a8718a2f8a2 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Fri, 6 Jan 2017 02:07:50 +0100 Subject: added support for new noplaying db format diff --git a/nop/migrations/0001_initial.py b/nop/migrations/0001_initial.py index 67a04e8..0285517 100644 --- a/nop/migrations/0001_initial.py +++ b/nop/migrations/0001_initial.py @@ -2,6 +2,7 @@ from __future__ import unicode_literals from django.db import migrations, models +import nop.models class Migration(migrations.Migration): @@ -22,7 +23,7 @@ class Migration(migrations.Migration): ('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)), + ('carttype', nop.models.CartTypeField(max_length=64, blank=True)), ], options={ 'ordering': ['-timestamp'], @@ -39,7 +40,7 @@ class Migration(migrations.Migration): ('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)), + ('carttype', nop.models.CartTypeField(max_length=64, blank=True)), ], options={ 'ordering': ['-timestamp'], diff --git a/nop/models.py b/nop/models.py index 1b39eed..e9b23e6 100644 --- a/nop/models.py +++ b/nop/models.py @@ -1,5 +1,16 @@ from django.db import models +class CartTypeField(models.Field): + def __init__(self, *args, **kwargs): + self.types = [('show', 'Show'), + ('pool', 'Musicpool'), + ('jingle', 'Jingle'), + ] + super(CartTypeField, self).__init__(*args, **kwargs) + + def db_type(self, connection): + return "ENUM({})".format(','.join("'{}'".format(col) + for col, _ in self.types)) class Master(models.Model): timestamp = models.BigIntegerField(primary_key=True) @@ -9,7 +20,7 @@ class Master(models.Model): 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) + carttype = CartTypeField(max_length=64, blank=True) class Meta: db_table = u'master' @@ -24,7 +35,7 @@ class Standby(models.Model): 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) + carttype = CartTypeField(max_length=64, blank=True) class Meta: db_table = u'standby' -- cgit v0.10.2 From 68b36d4940dfc9c581a44e0d3689b83ef3be8d12 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Fri, 6 Jan 2017 02:34:49 +0100 Subject: only show musicpools in nowplaying diff --git a/nop/views.py b/nop/views.py index 9fd87ee..c66b66c 100644 --- a/nop/views.py +++ b/nop/views.py @@ -89,7 +89,7 @@ def _current(): if show['id'] in MUSIKPROG_IDS \ or (show['id'] in SPECIAL_PROGRAM_IDS and not show['note']): - result = _which().objects.using(DB).all()[0] + result = _which().objects.using(DB).filter(carttype__exact='pool')[0] artist = result.artist title = result.title album = result.album -- cgit v0.10.2 From e51518c2e5dbe88f320e77b455571ec350f2b6d0 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Fri, 6 Jan 2017 02:45:04 +0100 Subject: fix fixtures for program-show diff --git a/program/fixtures/shows.yaml b/program/fixtures/shows.yaml index f520b26..470fd80 100644 --- a/program/fixtures/shows.yaml +++ b/program/fixtures/shows.yaml @@ -8,3 +8,5 @@ description: Unmoderiertes Musikprogramm short_description: Unmoderiertes Musikprogramm email: musikredaktion@helsinki.at + created: 1970-01-01 00:00:00 + last_updated: 1970-01-01 00:00:00 -- cgit v0.10.2 From 1db5125c61ed8ed050b01b7d0944569727a39e48 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Fri, 6 Jan 2017 02:50:43 +0100 Subject: fix now-playing filter diff --git a/nop/views.py b/nop/views.py index c66b66c..a8697bf 100644 --- a/nop/views.py +++ b/nop/views.py @@ -113,7 +113,7 @@ def _bydate(year=None, month=None, day=None, hour=None, minute=None): else: 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] + result = _which(ts).objects.using(DB).filter(carttype__exact='pool').filter(timestamp__lt=ts)[:5] return [{'show': show['name'], 'start': _dtstring(time.localtime(item.timestamp//1000000)), 'artist': item.artist, -- cgit v0.10.2