def test_at(self): now = Transmission.at( utc.localize(datetime.datetime(2015, 1, 6, 11, 59, 59))) self.assertListEqual( [(t.slug, t.start) for t in list(now)], [('the-best-wine', utc.localize(datetime.datetime(2015, 1, 6, 11, 0, 0)))]) now = Transmission.at( utc.localize(datetime.datetime(2015, 1, 6, 12, 0, 0))) self.assertListEqual( [(t.slug, t.start) for t in list(now)], [('local-gossips', utc.localize(datetime.datetime(2015, 1, 6, 12, 0, 0)))]) now = Transmission.at( utc.localize(datetime.datetime(2015, 1, 6, 12, 59, 59))) self.assertListEqual( [(t.slug, t.start) for t in list(now)], [('local-gossips', utc.localize(datetime.datetime(2015, 1, 6, 12, 0, 0)))]) now = Transmission.at( utc.localize(datetime.datetime(2015, 1, 6, 13, 0, 0))) self.assertListEqual(list(now), [])
def now(self, request): tz = None or pytz.utc # TODO check for a tz? now = utils.timezone.now() transmissions = Transmission.at(now) serializer = self.serializer_class(transmissions, many=True) with override(timezone=tz): return Response(serializer.data)
def test_at(self): now = Transmission.at(utc.localize(datetime.datetime(2015, 1, 6, 11, 59, 59))) self.assertListEqual( [(t.slug, t.start) for t in list(now)], [('the-best-wine', utc.localize(datetime.datetime(2015, 1, 6, 11, 0, 0)))]) now = Transmission.at(utc.localize(datetime.datetime(2015, 1, 6, 12, 0, 0))) self.assertListEqual( [(t.slug, t.start) for t in list(now)], [('local-gossips', utc.localize(datetime.datetime(2015, 1, 6, 12, 0, 0)))]) now = Transmission.at(utc.localize(datetime.datetime(2015, 1, 6, 12, 59, 59))) self.assertListEqual( [(t.slug, t.start) for t in list(now)], [('local-gossips', utc.localize(datetime.datetime(2015, 1, 6, 12, 0, 0)))]) now = Transmission.at(utc.localize(datetime.datetime(2015, 1, 6, 13, 0, 0))) self.assertListEqual(list(now), [])
def now(self, request): data = TimezoneForm(request.query_params) if not data.is_valid(): raise DRFValidationError(data.errors) requested_timezone = data.cleaned_data.get('timezone') tz = requested_timezone or pytz.utc now = utils.timezone.now() transmissions = Transmission.at(now) try: transmission = transmissions.next() except StopIteration: return Response(None) else: serializer = self.get_serializer(transmission, many=False) with override(timezone=tz): return Response(serializer.data)
def now(self, request): data = TimezoneForm(request.query_params) if not data.is_valid(): raise DRFValidationError(data.errors) requested_timezone = data.cleaned_data.get('timezone') tz = requested_timezone or pytz.utc now = utils.timezone.now() transmissions = Transmission.at(now) try: transmission = next(transmissions) except StopIteration: return Response(None) else: serializer = self.get_serializer(transmission, many=False) with override(timezone=tz): return Response(serializer.data)