From e0fe86232a5d2cead375aaf5c133ed7809a18323 Mon Sep 17 00:00:00 2001 From: nnrcschmdt Date: Mon, 12 Jun 2017 20:40:58 -0400 Subject: reverted back to callable datetime functions diff --git a/program/admin.py b/program/admin.py index eb55554..413531e 100644 --- a/program/admin.py +++ b/program/admin.py @@ -19,21 +19,21 @@ class ActivityFilter(admin.SimpleListFilter): def queryset(self, request, queryset): if self.parameter_name == 'has_timeslots': # active/inactive ProgramSlots if self.value() == 'yes': - return queryset.filter(until__gt=datetime.now).distinct() + return queryset.filter(until__gt=datetime.now()).distinct() if self.value() == 'no': - return queryset.filter(until__lt=datetime.now).distinct() + return queryset.filter(until__lt=datetime.now()).distinct() if self.parameter_name == 'has_programslots_timeslots': # active/inactive Shows if self.value() == 'yes': - return queryset.filter(programslots__until__gt=datetime.now).distinct() + return queryset.filter(programslots__until__gt=datetime.now()).distinct() if self.value() == 'no': - return queryset.filter(programslots__until__lt=datetime.now).distinct() + return queryset.filter(programslots__until__lt=datetime.now()).distinct() if self.parameter_name == 'has_shows_programslots_timeslots': # active/inactive Hosts if self.value() == 'yes': - return queryset.filter(shows__programslots__until__gt=datetime.now).distinct() + return queryset.filter(shows__programslots__until__gt=datetime.now()).distinct() if self.value() == 'no': - return queryset.filter(shows__programslots__until__lt=datetime.now).distinct() + return queryset.filter(shows__programslots__until__lt=datetime.now()).distinct() class ActiveProgramSlotsFilter(ActivityFilter): diff --git a/program/models.py b/program/models.py index d52d1bf..9945145 100644 --- a/program/models.py +++ b/program/models.py @@ -226,7 +226,7 @@ class Host(models.Model): return reverse('host-detail', args=[str(self.id)]) def active_shows(self): - return self.shows.filter(programslots__until__gt=datetime.today) + return self.shows.filter(programslots__until__gt=datetime.today()) class Show(models.Model): @@ -404,16 +404,16 @@ class TimeSlotManager(models.Manager): @staticmethod def get_or_create_current(): try: - return TimeSlot.objects.get(start__lte=datetime.now, end__gt=datetime.now) + return TimeSlot.objects.get(start__lte=datetime.now(), end__gt=datetime.now()) except MultipleObjectsReturned: - return TimeSlot.objects.filter(start__lte=datetime.now, end__gt=datetime.now)[0] + return TimeSlot.objects.filter(start__lte=datetime.now(), end__gt=datetime.now())[0] except ObjectDoesNotExist: once = RRule.objects.get(pk=1) today = date.today().weekday() default = Show.objects.get(pk=1) - previous_timeslot = TimeSlot.objects.filter(end__lte=datetime.now).order_by('-start')[0] - next_timeslot = TimeSlot.objects.filter(start__gte=datetime.now)[0] + previous_timeslot = TimeSlot.objects.filter(end__lte=datetime.now()).order_by('-start')[0] + next_timeslot = TimeSlot.objects.filter(start__gte=datetime.now())[0] dstart, tstart = previous_timeslot.end.date(), previous_timeslot.end.time() until, tend = next_timeslot.start.date(), next_timeslot.start.time() diff --git a/program/views.py b/program/views.py index a9c83e4..ddc38cb 100644 --- a/program/views.py +++ b/program/views.py @@ -15,7 +15,7 @@ from program.utils import tofirstdayinisoweek, get_cached_shows class HostListView(ListView): context_object_name = 'host_list' - queryset = Host.objects.filter(Q(is_always_visible=True) | Q(shows__programslots__until__gt=datetime.now)).distinct() + queryset = Host.objects.filter(Q(is_always_visible=True) | Q(shows__programslots__until__gt=datetime.now())).distinct() template_name = 'host_list.html' @@ -212,6 +212,7 @@ 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'] @@ -220,7 +221,8 @@ def json_timeslots_specials(request): if show['type'] == 's': specials[show['id']] = show - for ts in TimeSlot.objects.filter(end__gt=datetime.now, programslot__automation_id__in=specials.iterkeys()).select_related('show'): + for ts in TimeSlot.objects.filter(end__gt=datetime.now(), + programslot__automation_id__in=specials.iterkeys()).select_related('show'): automation_id = ts.programslot.automation_id specials[automation_id]['pv_id'] = int(ts.show.id) specials[automation_id]['pv_name'] = ts.show.name -- cgit v0.10.2