diff options
-rw-r--r-- | program/utils.py | 10 | ||||
-rw-r--r-- | program/views.py | 20 | ||||
-rw-r--r-- | pv/urls.py | 5 |
3 files changed, 32 insertions, 3 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") @@ -2,7 +2,7 @@ from django.conf import settings from django.conf.urls import patterns, url, include from django.contrib import admin -from program.views import json_day_schedule +from program.views import json_day_schedule, json_timeslots_specials admin.autodiscover() @@ -11,7 +11,8 @@ urlpatterns = patterns('', url(r'^program/', include('program.urls')), url(r'^nop', include('nop.urls')), url(r'^tinymce/', include('tinymce.urls')), - url(r'^export/day_schedule/(?P<year>\d{4})/(?P<month>\d{1,2})/(?P<day>\d{1,2})/$', json_day_schedule) + url(r'^export/day_schedule/(?P<year>\d{4})/(?P<month>\d{1,2})/(?P<day>\d{1,2})/$', json_day_schedule), + url(r'^export/timeslots_specials/$', json_timeslots_specials) ) if settings.DEBUG: |