예제 #1
0
파일: views.py 프로젝트: perrys/WSRC
 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
예제 #2
0
파일: views.py 프로젝트: perrys/WSRC
def index_view(request):

    ctx = get_pagecontent_ctx('home')
    levels = SquashLevels.objects.all().order_by('-level')
    if len(levels) > 0:
        ctx["squashlevels"] = levels

    leaguemasterfixtures = LeagueMasterFixtures.objects.all().order_by('date')
    rich_fixtures = []
    found_empty = False
    for idx,f in enumerate(leaguemasterfixtures):
        opponents = f.opponents
        for k,v in AWAY_TEAM_SHORT_NAMES.iteritems():
            opponents = opponents.replace(k,v)
        d = {
            "date": f.date,
            "team": HOME_TEAM_SHORT_NAMES[f.team],
            "opponents": opponents,
            "home_or_away": f.home_or_away,
            "scores": None,
            "points": None,
            "url": f.url,
            }
        if f.team1_score is not None:
            found_empty = False
            d["scores"] = "%d‑%d" % (f.team1_score, f.team2_score)
            d["points"] = "%d‑%d" % (f.team1_points, f.team2_points)
            if f.team1_points > f.team2_points:
                d["class"] = "won"
            elif f.team1_points < f.team2_points:
                d["class"] = "lost"
        elif not found_empty:
            found_empty = True
            ctx["leaguemaster_last_result_idx"] = idx
            ctx["leaguemaster_recent_min_idx"] = idx-5
            ctx["leaguemaster_recent_max_idx"] = idx+4
        rich_fixtures.append(d)
    ctx["leaguemaster"] = rich_fixtures
    if not found_empty:
        last = len(leaguemasterfixtures)-1
        ctx["leaguemaster_last_result_idx"] = last
        ctx["leaguemaster_recent_min_idx"] = last-9
        ctx["leaguemaster_recent_max_idx"] = last
        

    now = timezone.now()
    today_str = timezones.as_iso_date(now)
    midnight_today = now - datetime.timedelta(hours=now.hour, minutes=now.minute, seconds=now.second, microseconds = now.microsecond)
    cutoff_today = midnight_today + datetime.timedelta(hours=7)
    midnight_tomorrow = midnight_today + datetime.timedelta(days=1)
    bookings = BookingSystemEvent.objects.filter(start_time__gte=cutoff_today, start_time__lt=midnight_tomorrow).order_by('start_time')

    fake_context = {"request": LW_REQUEST({"date": today_str})}
    bookings_data = BookingSerializer(bookings, many=True, context=fake_context).data
    
    ctx["bookings"] = JSON_RENDERER.render(bookings_data)
    ctx["today"] = today_str
    return TemplateResponse(request, 'index.html', ctx)