def make_reservation(request):
    start = request.POST.get('start', None)
    end = request.POST.get('end', None)
    resource_id = request.POST.get('resource_id', None)

    if None in [start, end, resource_id]:
        return http_badrequest('')

    start = from_timestamp(int(start))
    end = from_timestamp(int(end))
    resource_id = int(resource_id)

    return do_make_reservation(start, end, resource_id, request.user)
    def test_utc_sv_conversions(self):
        now = common.utc_now()
        local_now = common.as_local_time(now)

        self.assertEqual(now, local_now)
        self.assertNotEquals(now.tzname(), local_now.tzname())

        ts_sv = common.to_timestamp(local_now)
        ts_utc = common.to_timestamp(now)

        self.assertEqual(ts_sv, ts_utc)

        self.assert_approx_equal(common.from_timestamp(ts_sv), common.from_timestamp(ts_utc))
def make_reservation(request):
    start = request.POST.get('start', None)
    end = request.POST.get('end', None)
    resource_id = request.POST.get('resource_id', None)

    if None in [start, end, resource_id]:
        return http_badrequest('')

    start = from_timestamp(int(start))
    end = from_timestamp(int(end))
    resource_id = int(resource_id)

    return do_make_reservation(start, end, resource_id, request.user)
    def test_utc_sv_conversions(self):
        now = common.utc_now()
        local_now = common.as_local_time(now)

        self.assertEqual(now, local_now)
        self.assertNotEquals(now.tzname(), local_now.tzname())

        ts_sv = common.to_timestamp(local_now)
        ts_utc = common.to_timestamp(now)

        self.assertEqual(ts_sv, ts_utc)

        self.assert_approx_equal(common.from_timestamp(ts_sv),
                                 common.from_timestamp(ts_utc))
def get_reservations(request, resource_id):
    start_time = int(request.GET.get('start'))
    end_time = int(request.GET.get('end'))
    resource_id = int(resource_id)
    if not resource_id or not start_time or not end_time:
        return http_badrequest('')

    start_datetime = from_timestamp(start_time)
    # We need to add a day to endtime because of djangoisms
    # see https://docs.djangoproject.com/en/dev/ref/models/querysets/#range
    end_datetime = from_timestamp(end_time) + timedelta(days=1)
    reservations = Reservation.objects.filter(
        deleted=False,
        resource=resource_id,
        start__range=(start_datetime, end_datetime))
    reservations = filter(lambda r: r.valid_user(), reservations)
    add_reservation_annotations(request.user, reservations)

    return http_json_response(reservations_to_json_struct(reservations))
def get_reservations(request, resource_id):
    start_time = int(request.GET.get('start'))
    end_time = int(request.GET.get('end'))
    resource_id = int(resource_id)
    if not resource_id or not start_time or not end_time:
        return http_badrequest('')

    start_datetime = from_timestamp(start_time)
    # We need to add a day to endtime because of djangoisms
    # see https://docs.djangoproject.com/en/dev/ref/models/querysets/#range
    end_datetime = from_timestamp(end_time) + timedelta(days=1)
    reservations = Reservation.objects.filter(deleted=False,
                                              resource=resource_id,
                                              start__range=(start_datetime,
                                                            end_datetime))
    reservations = filter(lambda r: r.valid_user(), reservations)
    add_reservation_annotations(request.user, reservations)

    return http_json_response(reservations_to_json_struct(reservations))
def single_click_reservation(request):
    ts = request.POST.get('timestamp', None)
    resource_id = request.POST.get('resource_id', None)
    if None in [ts, resource_id]:
        return http_badrequest('')

    start = from_timestamp(int(ts))
    start = start.replace(minute=0)
    end = start + timedelta(hours=1)

    return do_make_reservation(start, end, resource_id, request.user)
def single_click_reservation(request):
    ts = request.POST.get('timestamp', None)
    resource_id = request.POST.get('resource_id', None)
    if None in [ts, resource_id]:
        return http_badrequest('')

    start = from_timestamp(int(ts))
    start = start.replace(minute=0)
    end = start + timedelta(hours=1)

    return do_make_reservation(start, end, resource_id, request.user)
    def test_sv_ts_sv(self):
        utc_now = common.utc_now()
        local_now = common.as_local_time(utc_now)

        ts = common.to_timestamp(local_now)

        utc_from_ts = common.from_timestamp(ts)
        local_from_ts = common.as_local_time(utc_from_ts)

        self.assert_approx_equal(utc_now, utc_from_ts)
        self.assert_approx_equal(local_now, local_from_ts)
        self.assertEqual(utc_now, local_now)
        self.assertEqual(utc_from_ts, local_from_ts)
    def test_sv_ts_sv(self):
        utc_now = common.utc_now()
        local_now = common.as_local_time(utc_now)

        ts = common.to_timestamp(local_now)

        utc_from_ts = common.from_timestamp(ts)
        local_from_ts = common.as_local_time(utc_from_ts)

        self.assert_approx_equal(utc_now, utc_from_ts)
        self.assert_approx_equal(local_now, local_from_ts)
        self.assertEqual(utc_now, local_now)
        self.assertEqual(utc_from_ts, local_from_ts)
Beispiel #11
0
 def test_utc_conversions(self):
     now = common.utc_now()
     now_ts = common.to_timestamp(now)
     now_from_ts = common.from_timestamp(now_ts)
     self.assert_approx_equal(now, now_from_ts)
 def test_utc_conversions(self):
     now = common.utc_now()
     now_ts = common.to_timestamp(now)
     now_from_ts = common.from_timestamp(now_ts)
     self.assert_approx_equal(now, now_from_ts)