Skip to content
Snippets Groups Projects
Commit 6eabfdd6 authored by Christian Pointner's avatar Christian Pointner
Browse files

added sepcial show timeslot export

parent f1c2a398
No related branches found
No related tags found
No related merge requests found
......@@ -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')
......
......@@ -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:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment