summaryrefslogtreecommitdiff
path: root/program
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2017-04-07 00:40:57 (GMT)
committerChristian Pointner <equinox@helsinki.at>2017-04-07 00:40:57 (GMT)
commit8ee4333919acd638d2f1a011c287fc4bad88f166 (patch)
treef72619bedd7d4cf553a0bd2a2cd0db6ea8cfd04a /program
parent9f9c557d6c2f741025b44d12669772a9194c25ca (diff)
parent6eabfdd69ecf3b7615e9522ae3839554afc72864 (diff)
Merge branch 'master' into stable
Diffstat (limited to 'program')
-rw-r--r--program/utils.py10
-rw-r--r--program/views.py20
2 files changed, 29 insertions, 1 deletions
diff --git a/program/utils.py b/program/utils.py
index 3befeaf..1a81766 100644
--- a/program/utils.py
+++ b/program/utils.py
@@ -40,6 +40,16 @@ def get_automation_id_choices():
return shows
+def get_cached_shows():
+ cache_dir = getattr(settings, 'AUTOMATION_CACHE_DIR', 'cache')
+ cached_shows = join(cache_dir, 'shows.json')
+ shows = {}
+ with open(cached_shows) as shows_json:
+ shows = json.loads(shows_json.read())
+
+ return shows
+
+
def tofirstdayinisoweek(year, week):
# http://stackoverflow.com/questions/5882405/get-date-from-iso-week-number-in-python
ret = datetime.strptime('%04d-%02d-1' % (year, week), '%Y-%W-%w')
diff --git a/program/views.py b/program/views.py
index 53467cd..9886d08 100644
--- a/program/views.py
+++ b/program/views.py
@@ -10,7 +10,7 @@ from django.views.generic.list import ListView
from models import BroadcastFormat, MusicFocus, Note, Show, ShowInformation, ShowTopic, TimeSlot, Host
-from program.utils import tofirstdayinisoweek
+from program.utils import tofirstdayinisoweek, get_cached_shows
class HostListView(ListView):
@@ -211,3 +211,21 @@ def json_day_schedule(request, year=None, month=None, day=None):
return HttpResponse(json.dumps(schedule, ensure_ascii=False, encoding='utf8').encode('utf8'),
content_type="application/json; charset=utf-8")
+
+def json_timeslots_specials(request):
+ specials = {}
+ shows = get_cached_shows()['shows']
+ for show in shows:
+ show['pv_id'] = -1
+ if show['type'] == 's':
+ specials[show['id']] = show
+
+ for ts in TimeSlot.objects.filter(end__gt=datetime.now).filter(programslot__automation_id__in=specials.iterkeys()):
+ automation_id = ts.programslot.automation_id
+ specials[automation_id]['pv_id'] = int(ts.programslot.show.id)
+ specials[automation_id]['pv_name'] = ts.programslot.show.name
+ specials[automation_id]['pv_start'] = ts.start.strftime('%Y-%m-%d_%H:%M:%S')
+ specials[automation_id]['pv_end'] = ts.end.strftime('%Y-%m-%d_%H:%M:%S')
+
+ return HttpResponse(json.dumps(specials, ensure_ascii=False, encoding='utf8').encode('utf8'),
+ content_type="application/json; charset=utf-8")