示例#1
0
文件: views.py 项目: bscheinman/casei
def leaderboard(request, game_id):
    game = get_game(game_id)
    entry = get_entry(game, request.user)
    if not entry:
        return HttpResponseRedirect('/ncaa/')

    leaders = get_leaders(game)
    context = get_base_context(request, game_id, leaders=leaders)
    return render_with_request_context(request, 'leaderboard.html', context)
示例#2
0
文件: views.py 项目: bscheinman/casei
def game_home(request, game_id):
    context = get_base_context(request, game_id)

    game = context['game']
    if not game:
        return HttpResponseRedirect('/ncaa/')
    context['leaders'] = get_leaders(game)

    card_executions, stock_executions = [], []
    if game.supports_cards:
        card_executions = TradeOffer.objects.filter(entry__game=game, accepting_user__isnull=False).order_by('-accept_time')[:10]
    if game.supports_stocks:
        stock_executions = Execution.objects.filter(security__market__name=game.name).order_by('-time')[:50]

    context['card_executions'] = card_executions
    context['stock_executions'] = stock_executions

    return render_with_request_context(request, 'game_home.html', context)
示例#3
0
文件: views.py 项目: bscheinman/casei
def join_game(request):
    game_id = request.POST.get('game_id', '')
    entry_name = request.POST.get('entry_name', '')
    password = request.POST.get('password', '')

    game = get_game(game_id)
    if not game or request.method != 'POST':
        return HttpResponseRedirect('/ncaa/')

    error = ''

    if not entry_name:
        error = 'You must provide an entry name'
    elif entry_forbidden_regex.search(entry_name):
        error = 'Entry names can only contain letters, numbers, spaces, and underscores'
    else:
        try:
            entry = UserEntry.objects.get(game=game, entry_name=entry_name)
        except UserEntry.DoesNotExist:
            pass
        else:
            error = 'There is already an entry with the name %s in this game' % entry_name

    if game.password and game.password != password:
        error = 'Incorrect password'

    self_entry = get_entry(game, request.user)
    if self_entry:
        error = 'You already have an entry in this game'

    if error:
        context = get_base_context(request, game_id, error=error, leaders=get_leaders(game))
        return render_with_request_context(request, 'game_home.html', context)
    entry = UserEntry.objects.create(user=request.user, game=game, entry_name=entry_name)
    entry.update_score()

    return HttpResponseRedirect('/ncaa/game/%s/entry/%s/' % (game_id, entry.id))
示例#4
0
文件: views.py 项目: bscheinman/casei
def leaderboard(request, game_id):
    context = get_base_context(request, game_id)
    if 'self_entry' not in context:
        return HttpResponseRedirect('/ncaa/')
    context['leaders'] = get_leaders(context['game'])
    return render_with_request_context(request, 'leaderboard.html', context)