From a1e6deb0bf70944a70111c41438456abe2f867e3 Mon Sep 17 00:00:00 2001 From: Ernesto Rico-Schmidt Date: Fri, 7 Mar 2014 20:09:16 +0100 Subject: fixed day_schedule to export 00:00 - 23:59:59 and not between 06:00 and 05:59 also added show name to json export diff --git a/program/models.py b/program/models.py index 89e2fa7..7cdc345 100644 --- a/program/models.py +++ b/program/models.py @@ -419,6 +419,12 @@ class TimeSlotManager(models.Manager): return TimeSlot.objects.filter(models.Q(start__lte=today, end__gte=today) | models.Q(start__gt=today, start__lt=tomorrow)).exclude(end=today) + def get_24h_timeslots(self, start): + end = start + timedelta(hours=24) + + return TimeSlot.objects.filter(models.Q(start__lte=start, end__gte=start) | + models.Q(start__gt=start, start__lt=end)).exclude(end=start) + class TimeSlot(models.Model): programslot = models.ForeignKey(ProgramSlot, related_name='timeslots', verbose_name=_("Program slot")) start = models.DateTimeField(_("Start time"), unique=True) diff --git a/program/views.py b/program/views.py index 200d641..49bcd57 100644 --- a/program/views.py +++ b/program/views.py @@ -132,21 +132,21 @@ def styles(request): 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)) + today = datetime.combine(date.today(), time(0, 0)) else: - today = datetime.strptime('%s__%s__%s__06__00' % (year, month, day), '%Y__%m__%d__%H__%M') + today = datetime.strptime('%s__%s__%s__00__00' % (year, month, day), '%Y__%m__%d__%H__%M') - timeslots = TimeSlot.objects.get_day_timeslots(today) + timeslots = TimeSlot.objects.get_24h_timeslots(today) schedule = [] for ts in timeslots: if ts.programslot.automation_id: - schedule.append((ts.start.strftime('%H:%M:%S'), ts.programslot.automation_id)) + schedule.append((ts.start.strftime('%H:%M:%S'), ts.programslot.show.name, ts.programslot.automation_id)) elif ts.programslot.show.automation_id: - schedule.append((ts.start.strftime('%H:%M:%S'), ts.programslot.show.automation_id)) + schedule.append((ts.start.strftime('%H:%M:%S'), ts.programslot.show.name, ts.programslot.show.automation_id)) else: - schedule.append((ts.start.strftime('%H:%M:%S'), -1)) + schedule.append((ts.start.strftime('%H:%M:%S'), ts.programslot.show.name, -1)) - return HttpResponse(json.dumps(schedule), content_type="application/json") + return HttpResponse(json.dumps(schedule), content_type="application/json; charset=utf-8") def tofirstdayinisoweek(year, week): # http://stackoverflow.com/questions/5882405/get-date-from-iso-week-number-in-python -- cgit v0.10.2