def booking_view(request, date=None): if date is None: date = datetime.date.today() else: date = timezones.parse_iso_date_to_naive(date) def get_bookings(date): today_str = timezones.as_iso_date(date) tomorrow_str = timezones.as_iso_date(date + datetime.timedelta(days=1)) url = settings.BOOKING_SYSTEM_URL + "/api/entries.php?start_date={today_str}&end_date={tomorrow_str}&with_tokens=1".format(**locals()) h = httplib2.Http() (resp_headers, content) = h.request(url, "GET") if resp_headers.status != httplib.OK: raise Exception("unable to fetch bookings data, status = " + str(resp_headers.status) + ", response: " + content) return content bookings = get_bookings(date) context = { "date": date, "bookings": bookings, "booking_system_url": settings.BOOKING_SYSTEM_URL, "starts": range(420, 1380, 15), "durations": [30, 45, 60, 75, 90, 120, 180, 240] } if request.user.is_authenticated(): player = Player.get_player_for_user(request.user) if player is not None: booking_user_id = player.booking_system_id context["booking_user_id"] = booking_user_id context["booking_user_auth_token"] = BookingSystemEvent.generate_hmac_token_raw("id:{booking_user_id}".format(**locals())) context["booking_user_name"] = player.user.get_full_name() return render(request, 'court_booking.html', context)
def times(court, start): m = {} while (start.time().hour < 23): m[start.time().strftime("%H:%M")] = BookingSystemEvent.generate_hmac_token(start, court) start += court_length return m