diff options
author | Ernesto Rico-Schmidt <e.rico.schmidt@gmail.com> | 2013-04-12 17:37:47 (GMT) |
---|---|---|
committer | Ernesto Rico-Schmidt <e.rico.schmidt@gmail.com> | 2013-04-12 17:37:47 (GMT) |
commit | e89b4c50f48d5acd1b81c3825515b1a34a1d2089 (patch) | |
tree | 3a78169cf375b581cdbbdece57cfd9d441aaa159 | |
parent | 6e8c1713e0f415cca094b445bb2ea090999c4bfd (diff) |
added JSON export for automation.
-rw-r--r-- | program/models.py | 6 | ||||
-rw-r--r-- | program/utils.py | 9 | ||||
-rw-r--r-- | program/views.py | 21 | ||||
-rw-r--r-- | urls.py | 3 |
4 files changed, 37 insertions, 2 deletions
diff --git a/program/models.py b/program/models.py index 448b742..484c191 100644 --- a/program/models.py +++ b/program/models.py @@ -9,6 +9,8 @@ from datetime import date, datetime, time, timedelta from dateutil.relativedelta import relativedelta from dateutil.rrule import rrule +from utils import get_automation_id_choices + class BroadcastFormat(models.Model): format = models.CharField(_("Format"), max_length=32) slug = models.SlugField(_("Slug"), max_length=32, unique=True) @@ -227,7 +229,7 @@ class Show(models.Model): email = models.EmailField(_("E-Mail"), blank=True, null=True) website = models.URLField(_("Website"), blank=True, null=True) cba_series_id = models.IntegerField(_("CBA series ID"), blank=True, null=True) - automation_id = models.IntegerField(_("Automation ID"), blank=True, null=True) + automation_id = models.IntegerField(_("Automation ID"), blank=True, null=True, choices=get_automation_id_choices()) created = models.DateTimeField(auto_now_add=True, editable=False) last_updated = models.DateTimeField(auto_now=True, editable=False) @@ -294,7 +296,7 @@ class ProgramSlot(models.Model): tend = models.TimeField(_("End time")) until = models.DateField(_("Last date")) is_repetition = models.BooleanField(_("Is repetition"), default=False) - automation_id = models.IntegerField(_("Automation ID"), blank=True, null=True) + automation_id = models.IntegerField(_("Automation ID"), blank=True, null=True, choices=get_automation_id_choices()) created = models.DateTimeField(auto_now_add=True, editable=False) last_updated = models.DateTimeField(auto_now=True, editable=False) diff --git a/program/utils.py b/program/utils.py new file mode 100644 index 0000000..5798c11 --- /dev/null +++ b/program/utils.py @@ -0,0 +1,9 @@ +from django.conf import settings + +import json +import urllib + +def get_automation_id_choices(): + shows_list = json.load(urllib.urlopen(settings.AUTOMATION_BASE_URL))['shows'] + shows = [(s['id'], s['title']) for s in shows_list] + return shows
\ No newline at end of file diff --git a/program/views.py b/program/views.py index ec795cf..d824df8 100644 --- a/program/views.py +++ b/program/views.py @@ -1,11 +1,14 @@ from django.views.generic import list_detail, simple from django.shortcuts import get_object_or_404 from django.db.models import Q +from django.http import HttpResponse from models import BroadcastFormat, MusicFocus, Note, Show, ShowInformation, ShowTopic, TimeSlot from datetime import date, datetime, time, timedelta +import json + def show_list(request): queryset = Show.objects.filter(programslots__until__gt=date.today()).exclude(id=1).distinct() @@ -127,3 +130,21 @@ def styles(request): extra_context['showinformation'] = ShowInformation.objects.all() extra_context['showtopic'] = ShowTopic.objects.all() return simple.direct_to_template(request, template='program/styles.css', mimetype='text/css', extra_context=extra_context) + +def json_day_schedule(request, year=None, month=None, day=None): + if year is None and month is None and day is None: + today = datetime.combine(date.today(), time(6, 0)) + else: + today = datetime.strptime('%s__%s__%s__06__00' % (year, month, day), '%Y__%m__%d__%H__%M') + + timeslots = TimeSlot.objects.get_day_timeslots(today) + schedule = [] + for ts in timeslots: + if ts.programslot.automation_id: + schedule.append((ts.start.strftime('%H:%M:%S'), ts.programslot.automation_id)) + elif ts.programslot.show.automation_id: + schedule.append((ts.start.strftime('%H:%M:%S'), ts.programslot.show.automation_id)) + else: + schedule.append((ts.start.strftime('%H:%M:%S'), -1)) + + return HttpResponse(json.dumps(schedule), content_type="application/json") @@ -4,12 +4,15 @@ from django.contrib import admin admin.autodiscover() +from program.views import json_day_schedule urlpatterns = patterns('', (r'^admin/', include(admin.site.urls)), (r'^program/', include('program.urls')), (r'^nop', include('nop.urls')), (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), ) + if settings.DEBUG: urlpatterns += patterns('', (r'^site_media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}) |