Skip to content
Snippets Groups Projects
Commit e89b4c50 authored by Ernesto Rico Schmidt's avatar Ernesto Rico Schmidt
Browse files

added JSON export for automation.

parent 6e8c1713
No related branches found
No related tags found
No related merge requests found
......@@ -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)
......
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
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})
......
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