Пример #1
0
    def index(self, request):
        context = self._processRequest(request)
        if request.method == 'GET':
            updatePending()
            teams = request.user.teams.all()
            qs = Q()
            for n in teams:
                qs |= Q(red=n)
                qs |= Q(blu=n)
            
            games = []
            for n in Game.objects.filter(qs, Q(status=Game.Open) | Q(status=Game.Pending)):
                games.append({
                    'game': n,
                    'red_rating': n.red.laddermembership_set.filter(ladder=n.ladder)[0].rating.rating,
                    'blu_rating': n.blu.laddermembership_set.filter(ladder=n.ladder)[0].rating.rating,
                })
            context['games'] = games
            template = 'ladder/game.html'

            return render(request, template, context)
        elif request.method == 'POST':
            return self.create(request)
        else:
            pass
Пример #2
0
    def get(self, request, obj_id, requestData={}):
        updatePending()
        context = requestData
        teams = request.user.teams.all()
        qs = Q()
        for n in teams:
            qs |= Q(red=n)
            qs |= Q(blu=n)
        
        games = []
        for n in Game.objects.filter(qs, status=Game.Open):
            games.append({
                'game': n,
                'red_rating': n.red.laddermembership_set.filter(ladder=n.ladder)[0].rating.rating,
                'blu_rating': n.blu.laddermembership_set.filter(ladder=n.ladder)[0].rating.rating,
            })
        context['games'] = games
        template = 'ladder/game.html'

        return render(request, template, context)
Пример #3
0
    def update(self, request, obj_id, context):
        """
        Does the maths for the result of the game and closes it out
        """
        
        updatePending()
        res = Result()
        request.POST
        
        if context['object'].status != 0:
            res.isError = True
            res.message = "This game is not open"
            
            return JsonResponse(res)

        if context['request'].user in context['object'].red.members.all() or context['request'].user in context['object'].blu.members.all():
            result = request.POST.get('result', None)
            if not result:
                res.isError = True
                res.message = "Incorrect result type, int required"
                
                return JsonResponse(res)

            context['object'].update(Team.objects.get(pk=result))

            # Send the emails of the results
            red = [user.email for user in context['object'].red.members.all()]
            blu = [user.email for user in context['object'].blu.members.all()]
            #mail('Game has ended', 'ladder/email/game.html', {'game': context['object'], 'user': context['request'].user}, red + blu)
            res.isSuccess = True
            res.message = "Game is now closed"
            res.append(context['object'].json())
        else:
            res.isError = True
            res.message = 'You are not a member of either team for this game.'

        return JsonResponse(res)