def bidindex(request, event=None): event = viewutil.get_event(event) searchForm = BidSearchForm(request.GET) if not searchForm.is_valid(): return HttpResponse('Invalid filter form', status=400) searchParams = {} searchParams.update(request.GET) searchParams.update(searchForm.cleaned_data) if event.id: searchParams['event'] = event.id else: return HttpResponseRedirect(reverse('tracker.views.bidindex', args=(Event.objects.latest().id,))) bids = filters.run_model_query('bid', searchParams, user=request.user) bids = bids.filter(parent=None) total = bids.aggregate(Sum('total'))['total__sum'] or Decimal('0.00') choiceTotal = bids.filter(goal=None).aggregate(Sum('total'))['total__sum'] or Decimal('0.00') challengeTotal = bids.exclude(goal=None).aggregate(Sum('total'))['total__sum'] or Decimal('0.00') bids = viewutil.get_tree_queryset_descendants(Bid, bids, include_self=True).prefetch_related('options') bids = bids.filter(parent=None) if event.id: bidNameSpan = 2 else: bidNameSpan = 1 return views_common.tracker_response(request, 'tracker/bidindex.html', { 'searchForm': searchForm, 'bids': bids, 'total': total, 'event': event, 'bidNameSpan' : bidNameSpan, 'choiceTotal': choiceTotal, 'challengeTotal': challengeTotal })
def run_detail(request, pk): try: run = SpeedRun.objects.get(pk=pk) runners = run.runners.all() event = run.event bids = filters.run_model_query('bid', {'run': pk}) bids = (viewutil.get_tree_queryset_descendants( Bid, bids, include_self=True).select_related( 'speedrun', 'event', 'parent').prefetch_related('options')) topLevelBids = [bid for bid in bids if bid.parent is None] return views_common.tracker_response( request, 'tracker/run.html', { 'event': event, 'run': run, 'runners': runners, 'bids': topLevelBids }, ) except SpeedRun.DoesNotExist: return views_common.tracker_response(request, template='tracker/badobject.html', status=404)
def run(request,id): try: run = SpeedRun.objects.get(pk=id) runners = run.runners.all() event = run.event bids = filters.run_model_query('bid', {'run': id}, user=request.user) bids = viewutil.get_tree_queryset_descendants(Bid, bids, include_self=True).select_related('speedrun','event', 'parent').prefetch_related('options') topLevelBids = filter(lambda bid: bid.parent == None, bids) bids = topLevelBids return tracker_response(request, 'tracker/run.html', { 'event': event, 'run' : run, 'runners': runners, 'bids' : topLevelBids }) except SpeedRun.DoesNotExist: return tracker_response(request, template='tracker/badobject.html', status=404)
def run(request,id): try: run = SpeedRun.objects.get(pk=id) runners = run.runners.all() event = run.event bids = filters.run_model_query('bid', {'run': id}) bids = viewutil.get_tree_queryset_descendants(Bid, bids, include_self=True).select_related('speedrun','event', 'parent').prefetch_related('options') topLevelBids = filter(lambda bid: bid.parent == None, bids) return views_common.tracker_response(request, 'tracker/run.html', { 'event': event, 'run' : run, 'runners': runners, 'bids' : topLevelBids }) except SpeedRun.DoesNotExist: return views_common.tracker_response(request, template='tracker/badobject.html', status=404)
def bidindex(request, event=None): event = viewutil.get_event(event) searchForm = BidSearchForm(request.GET) if not searchForm.is_valid(): return HttpResponse('Invalid filter form', status=400) searchParams = {} searchParams.update(request.GET) searchParams.update(searchForm.cleaned_data) if event.id: searchParams['event'] = event.id else: return HttpResponseRedirect( reverse('tracker.views.bidindex', args=(Event.objects.latest().id, ))) bids = filters.run_model_query('bid', searchParams, user=request.user) bids = bids.filter(parent=None) total = bids.aggregate(Sum('total'))['total__sum'] or Decimal('0.00') choiceTotal = bids.filter(goal=None).aggregate( Sum('total'))['total__sum'] or Decimal('0.00') challengeTotal = bids.exclude(goal=None).aggregate( Sum('total'))['total__sum'] or Decimal('0.00') bids = viewutil.get_tree_queryset_descendants( Bid, bids, include_self=True).prefetch_related('options') bids = bids.filter(parent=None) if event.id: bidNameSpan = 2 else: bidNameSpan = 1 return views_common.tracker_response( request, 'tracker/bidindex.html', { 'searchForm': searchForm, 'bids': bids, 'total': total, 'event': event, 'bidNameSpan': bidNameSpan, 'choiceTotal': choiceTotal, 'challengeTotal': challengeTotal })
def show_completed_bids(request): current = viewutil.get_selected_event(request); params = {'state': 'OPENED'}; if current: params['event'] = current.id; bids = filters.run_model_query('allbids', params, user=request.user, mode='admin'); bids = viewutil.get_tree_queryset_descendants(tracker.models.Bid, bids, include_self=True).annotate(**viewutil.ModelAnnotations['bid']); bids = viewutil.FixupBidAnnotations(bids); bidList = []; for bidK in bids: bid = bids[bidK]; if bid.state == 'OPENED' and bid.goal and bid.amount > bid.goal: bidList.append(bid); if request.method == 'POST': for bid in bidList: bid.state = 'CLOSED'; bid.save(); return render(request, 'admin/completed_bids_post.html', { 'bids': bidList }); return render(request, 'admin/completed_bids.html', { 'bids': bidList });
def bidindex(request, event=None): event = viewutil.get_event(event) searchForm = BidSearchForm(request.GET) if not searchForm.is_valid(): return HttpResponse("Invalid filter form", status=400) searchParams = {} searchParams.update(request.GET) searchParams.update(searchForm.cleaned_data) if event.id: searchParams["event"] = event.id else: return HttpResponseRedirect(reverse("tracker.views.bidindex", args=(Event.objects.latest().id,))) bids = filters.run_model_query("bid", searchParams, user=request.user) bids = bids.filter(parent=None) total = bids.aggregate(Sum("total"))["total__sum"] or Decimal("0.00") choiceTotal = bids.filter(goal=None).aggregate(Sum("total"))["total__sum"] or Decimal("0.00") challengeTotal = bids.exclude(goal=None).aggregate(Sum("total"))["total__sum"] or Decimal("0.00") bids = viewutil.get_tree_queryset_descendants(Bid, bids, include_self=True).prefetch_related("options") bids = bids.filter(parent=None) if event.id: bidNameSpan = 2 else: bidNameSpan = 1 return views_common.tracker_response( request, "tracker/bidindex.html", { "searchForm": searchForm, "bids": bids, "total": total, "event": event, "bidNameSpan": bidNameSpan, "choiceTotal": choiceTotal, "challengeTotal": challengeTotal, }, )
def run(request, id): try: run = SpeedRun.objects.get(pk=id) runners = run.runners.all() event = run.event bids = filters.run_model_query("bid", {"run": id}, user=request.user) bids = ( viewutil.get_tree_queryset_descendants(Bid, bids, include_self=True) .select_related("speedrun", "event", "parent") .prefetch_related("options") ) topLevelBids = filter(lambda bid: bid.parent == None, bids) bids = topLevelBids return views_common.tracker_response( request, "tracker/run.html", {"event": event, "run": run, "runners": runners, "bids": topLevelBids} ) except SpeedRun.DoesNotExist: return views_common.tracker_response(request, template="tracker/badobject.html", status=404)
def bidindex(request, event=None): event = viewutil.get_event(event) searchForm = BidSearchForm(request.GET); if not searchForm.is_valid(): return HttpResponse('Invalid filter form', status=400); searchParams = {}; searchParams.update(request.GET); searchParams.update(searchForm.cleaned_data); if event.id: searchParams['event'] = event.id; bids = filters.run_model_query('bid', searchParams, user=request.user); bids = viewutil.get_tree_queryset_descendants(Bid, bids, include_self=True).select_related('speedrun','event', 'parent').prefetch_related('options'); agg = bids.aggregate(**viewutil.ModelAnnotations['bid']); bids = bids.annotate(**viewutil.ModelAnnotations['bid']); bidsCache = viewutil.FixupBidAnnotations(bids); topLevelBids = filter(lambda bid: bid.parent == None, bids) bids = topLevelBids; choiceTotal = sum([bidsCache[bid.id].amount for bid in topLevelBids if not bid.goal]) challengeTotal = sum([bidsCache[bid.id].amount for bid in topLevelBids if bid.goal]) if event.id: bidNameSpan = 2; else: bidNameSpan = 1; return tracker_response(request, 'tracker/bidindex.html', { 'searchForm': searchForm, 'bids': topLevelBids, 'cache': bidsCache, 'agg': agg, 'event': event, 'bidNameSpan' : bidNameSpan, 'choiceTotal': choiceTotal, 'challengeTotal': challengeTotal });