Example #1
0
    def final_challenge(self, request, queryset):
        profiles = UserProfile.objects.filter(user__is_superuser=False, 
            user__is_active=True, current_bot__isnull=False).all()
        if not queryset:
            return HttpResponseRedirect('/admin')

        final_challenge = queryset[0]
        for up_player1, up_player2 in itertools.product(profiles, repeat=2):
            if up_player1 == up_player2:
                continue
                
            challenge = Challenge()
            challenge.requested_by = up_player1
            challenge.challenger_bot = up_player1.current_bot
            challenge.challenged_bot = up_player2.current_bot
            challenge.final_challenge = final_challenge
            challenge.save()
            final_challenge.challenge_set.add(challenge)
            # dispatch the new task
            players = {up_player1.user.username: up_player1.current_bot.code,
                       up_player2.user.username: up_player2.current_bot.code,
            }
            run_match.delay(challenge.id, players)

        final_challenge.save()
        return HttpResponseRedirect('/admin')
Example #2
0
def dispatch_challengue(sender, instance, created, **kwargs):
    if created:
        players = {instance.challenger_bot.owner.user.username: instance.challenger_bot.code,
                   instance.challenged_bot.owner.user.username: instance.challenged_bot.code}
        run_match.delay(instance.id, players)