def custom(request):
    u               = request.user
    lock_bids       = settings.LOCK_BIDS or (not util.is_1_waiver_period())
    has_permission  = u.is_staff or u.is_superuser
    ms_left         = util.time_until_open().seconds*1000 + util.time_until_open().days*24*60*60*1000
    now             = timezone.localtime(timezone.now())
    if util.is_1_waiver_period():
        waiver_period   = 1
    else:
        waiver_period   = 2
        
    return {'lock_bids':lock_bids, 
            'has_permission':has_permission, 
            'waiver_period':waiver_period,
            'now':now,
            'DROP':Bid.DROP,
            'FUNDS':Bid.FUNDS,
            'ms_left':ms_left}    
    
Пример #2
0
def bid(request, nfl_id):
    u = request.user
    allow_bids = u.is_authenticated() and (not settings.LOCK_BIDS) and util.is_1_waiver_period()
    if allow_bids:
        p = Player.objects.get(nfl_id=nfl_id)
        team = Team.objects.get(owner=u)
        roster = Player.objects.filter(dflteam=team).order_by("position")
        if request.method == "POST":
            val = int(request.POST.get("bidvalue"))
            if val < 0:
                val = 0
            if val > team.account:
                val = team.account
            pk_to_drop = request.POST.get("Drop")
            dropee = Player.objects.get(pk=pk_to_drop)
            priority = int(request.POST.get("Priority"))
            # priority can not be the same as any other unprocessed bids with same drop
            same_drop = Bid.objects.filter(team=team).filter(processed=False).filter(drop=dropee)
            other_prios = []
            for sd in same_drop:
                other_prios.append(sd.priority)
            while priority in other_prios:
                priority += 1
            b = Bid(team=team, amount=val, player=p, drop=dropee, priority=priority)
            b.save()

            # if bid-sum is larger than account, all bids must have unique prio
            bidsum = Bid.objects.filter(team=team).filter(processed=False).aggregate(Sum("amount"))

            if bidsum["amount__sum"] > team.account:
                active_bids = Bid.objects.filter(team=team).filter(processed=False).order_by("priority", "date")
                count = 0
                for b in active_bids:
                    count += 1
                    b.priority = count
                    b.save()

            return HttpResponseRedirect("/team")
        else:
            return render(request, "bid.html", {"player": p, "roster": roster, "team": team})
    else:
        return HttpResponseRedirect("/")