示例#1
0
文件: views.py 项目: artnez/faceoff
def history(nickname, year, month, day):
    league_id = g.current_league['id']
    user_id = find_user_id(nickname) if nickname is not None else None
    today = date.today()
    refresh = False
    if year is None:
        year = today.year
        refresh = True
    if month is None:
        month = today.strftime('%b').lower()
        refresh = True
    if day is None:
        day = today.day if month == today.strftime('%b').lower() else 1
        refresh = True
    if refresh:
        kwargs = {
            'nickname': nickname, 'year': year, 'month': month, 'day': day}
        return redirect(url_for('history', **kwargs))
    try:
        date_start = datetime.strptime(
            '%s-%s-%s' % (year, month, day), '%Y-%b-%d')
        date_end = date_start.replace(hour=23, minute=59, second=59)
        time_start = mktime(date_start.timetuple())
        time_end = mktime(date_end.timetuple())
    except ValueError:
        abort(404)
    matches = search_matches(league_id, user_id, time_start, time_end)
    newer = find_newer_match(league_id, user_id, time_end)
    older = find_older_match(league_id, user_id, time_start)
    return dict(matches=matches, time_start=time_start, time_end=time_end,
                newer_match=newer, older_match=older, nickname=nickname)
示例#2
0
文件: views.py 项目: artnez/faceoff
def dashboard():
    user = g.current_user
    league = g.current_league
    return dict(
        report_form=ReportForm(get_active_users()),
        current_ranking=get_user_standing(league['id'], user['id']),
        ranking=get_league_ranking(league['id']),
        history=search_matches(league['id'], user_id=user['id']))