Exemplo n.º 1
0
    def _create_tournament(self, category_id, mixte_id):
        CATEGORIES_LIST=[
            ('preminimes', 'pré-minimes'),
            ('minimes', 'minimes'),
            ('cadets', 'cadets'),
            ('scolaires', 'scolaires'),
            ('juniors', 'juniors'),
            ('seniors', 'seniors'),
            ('elites', 'elites'),
            ('familles', 'tournoi des familles')
        ]
        MIXTE_CHOICES=[
            ('M', 'masculin'),
            ('F', 'féminin'),
            ('Mixte', 'mixte')
        ]
        category = CATEGORIES_LIST[category_id][0]
        pool_size = 5
        mixte = MIXTE_CHOICES[mixte_id][0]
        season = settings.CURRENT_SEASON
        name = "Tournoi " + category + " " + mixte
        tournament = Tournament(name=name, category=category, pool_size=pool_size, \
            mixte=mixte, season=season)
        tournament.save()

        return tournament
Exemplo n.º 2
0
 def setUp(self):
     name = "Tournament test"
     category = "cadets"
     pool_size = 5
     mixte = 'M'
     season = settings.CURRENT_SEASON
     tournament = Tournament(name=name, category=category, \
     pool_size=pool_size, mixte=mixte, season=season)
     tournament.save()
Exemplo n.º 3
0
    def setUpClass(cls):
        super(TournamentTestCase, cls).setUpClass()

        Account.objects.create(id=37, battle_tag='ADMIN', account_id='99999')
        for i in range(0, cls.players):
            Account.objects.create_user(id_generator(),
                                        random.randint(100000, 999999))
        cls.new_tour = Tournament.create('All',
                                         'Semi',
                                         'Finals',
                                         fare=10,
                                         name='Name',
                                         maxplayers=12,
                                         rules='Rules',
                                         date='2015-01-01',
                                         format='SE',
                                         time='15:00',
                                         account=Account.objects.last(),
                                         background='',
                                         region='Europe')
        cls.client = APIClient()

        accounts = Account.objects.all()
        for acc in accounts:
            new_attendant = Attendant(account=acc,
                                      tournament=cls.new_tour,
                                      gameClass='rus.png')
            new_attendant.save()
Exemplo n.º 4
0
def tournamentManager(request, id=None):
    if id:
        tournament = get_object_or_404(Tournament, pk=id)
        date_start = datetime.datetime.strftime(tournament.date_start,
                                                '%Y-%m-%d %H:%M')
        date_end = datetime.datetime.strftime(tournament.date_end,
                                              '%Y-%m-%d %H:%M')
    else:
        tournament = Tournament()
        date_start = datetime.datetime.strftime(datetime.datetime.now(),
                                                '%Y-%m-%d %H:%M')
        date_end = datetime.datetime.strftime(
            datetime.datetime.now() + datetime.timedelta(days=7),
            '%Y-%m-%d %H:%M')

    if request.method == 'POST':
        form = TournamentForm(request.POST, instance=tournament)
        if form.is_valid():
            dates = request.POST.get('datetime').split(' - ')
            tournament.date_start = dates[0]
            tournament.date_end = dates[1]
            tournament.slug = slugify(tournament.name)
            tournament.save()
            form.save()

            return redirect(tournamentManager)
    form = TournamentForm(instance=tournament)
    tournaments = Tournament.objects.all()
    context = {
        'tournaments': tournaments,
        'form': form,
        'date_start': date_start,
        'date_end': date_end,
    }
    return render(request, 'manager/manage_tournaments.html', context)
Exemplo n.º 5
0
def tournamentManager(request, id=None):
    if id:
        tournament = get_object_or_404(Tournament, pk=id)
        date_start = datetime.datetime.strftime(tournament.date_start, '%Y-%m-%d %H:%M')
        date_end = datetime.datetime.strftime(tournament.date_end, '%Y-%m-%d %H:%M')
    else:
        tournament = Tournament()
        date_start = datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d %H:%M')
        date_end = datetime.datetime.strftime(datetime.datetime.now() + datetime.timedelta(days=7), '%Y-%m-%d %H:%M')

    if request.method == 'POST':
        form = TournamentForm(request.POST, instance=tournament)
        if form.is_valid():
            dates = request.POST.get('datetime').split(' - ')
            tournament.date_start = dates[0]
            tournament.date_end = dates[1]
            tournament.slug = slugify(tournament.name)
            tournament.save()
            form.save()

            return redirect(tournamentManager)
    form = TournamentForm(instance=tournament)
    tournaments = Tournament.objects.all()
    context = {
            'tournaments': tournaments,
            'form': form,
            'date_start': date_start,
            'date_end': date_end,
    }
    return render(request, 'manager/manage_tournaments.html', context)
Exemplo n.º 6
0
    def setUpClass(cls):
        super(TournamentTestCase, cls).setUpClass()

        Account.objects.create(id=37, battle_tag='ADMIN', account_id='99999')
        for i in range(0, cls.players):
            Account.objects.create_user(id_generator(), random.randint(100000, 999999))
        cls.new_tour = Tournament.create('All', 'Semi', 'Finals', fare=10, name='Name', maxplayers=12, rules='Rules',
                                         date='2015-01-01', format='SE',
                                         time='15:00', account=Account.objects.last(), background='', region='Europe')
        cls.client = APIClient()

        accounts = Account.objects.all()
        for acc in accounts:
            new_attendant = Attendant(account=acc, tournament=cls.new_tour, gameClass='rus.png')
            new_attendant.save()
Exemplo n.º 7
0
 def create(self, validated_data):
     new_tournament = Tournament.create(name=validated_data['name'],
                                        allmatches=validated_data['allmatches'],
                                        semi=validated_data['semi'],
                                        finals=validated_data['finals'],
                                        maxplayers=validated_data['maxplayers'],
                                        rules=validated_data['rules'],
                                        date=validated_data['date'],
                                        time=validated_data['time'],
                                        fare=validated_data['fare'],
                                        account=self.context['request'].user,
                                        # account=28,
                                        format=validated_data['format'],
                                        background=validated_data['background'],
                                        region=validated_data['region'])
     return new_tournament
Exemplo n.º 8
0
    def post(self, request, *args, **kwargs):
        result = Result()
        if kwargs.get('obj_id', None):
            self._processRequest(request, kwargs['obj_id'])

            if self.POST.get('start'):
                self.object.state = Tournament.Started
                self.object.save()

                result.isSuccess = True

                return JsonResponse(result)
        else:
            self.object = Tournament()
        
        for k,v in request.POST.iteritems():
            if hasattr(self.object, k):
                try:
                    v = int(v)
                except ValueError:
                    pass
                if v.lower() == 'true':
                    v = True
                elif v.lower() == 'false':
                    v = False
                setattr(self.object, k, v)
            else:
                result.isError = True
                result.message = "Invalid property: %s" % k
                break
        
        if not result.isError:
            self.object.save()
            result.isSuccess = True
        
        return JsonResponse(result)
Exemplo n.º 9
0
 def test__calculate_number_of_rounds(self):
     tournament = Tournament()
     self.assertEqual(tournament._calculate_number_of_rounds(), 0)
Exemplo n.º 10
0
 def test_validate_current_round(self):
     tournament = Tournament()
     self.assertTrue(tournament.validate_current_round())
Exemplo n.º 11
0
    def test_pages_open_tournament(self):
        name = "Tournament test"
        category = "cadets"
        pool_size = 5
        mixte = 'M'
        season = settings.CURRENT_SEASON
        tournament = Tournament(name=name, category=category, \
        pool_size=pool_size, mixte=mixte, season=season)
        tournament.save()

        print("\n\n--Tournament open")
        c = Client()
        #Test home page
        url = '/'
        response = c.get(url)
        self.assertEqual(response.status_code, 200, \
            "Error: Test home page return " + str(response.status_code))
        print("\nTemplates for " + url)
        templates = response.templates
        for template in templates:
            print(template.name)
        #Test players register page
        url = '/players/register'
        response = c.get(url)
        self.assertEqual(response.status_code, 200, \
            "Error: Test players register page return " + \
             str(response.status_code))
        print("\nTemplates for " + url)
        templates = response.templates
        for template in templates:
            print(template.name)
        #Test courts register page
        url = '/courts/register'
        response = c.get(url)
        self.assertEqual(response.status_code, 200, \
            "Error: Test courts register page return " + \
            str(response.status_code))
        print("\nTemplates for " + url)
        templates = response.templates
        for template in templates:
            print(template.name)
        #Test sponsors page
        url = '/sponsors'
        response = c.get(url)
        self.assertEqual(response.status_code, 200, \
            "Error: Test sponsors page return " + \
            str(response.status_code))
        print("\nTemplates for " + url)
        templates = response.templates
        for template in templates:
            print(template.name)
        #Test contact page
        url = '/contact'
        response = c.get(url)
        self.assertEqual(response.status_code, 200, \
            "Error: Test contact page return " + \
            str(response.status_code))
        print("\nTemplates for " + url)
        templates = response.templates
        for template in templates:
            print(template.name)
Exemplo n.º 12
0
 def test__calculate_number_of_rounds(self):
     tournament = Tournament()
     self.assertEqual(tournament._calculate_number_of_rounds(), 0)
Exemplo n.º 13
0
 def test_validate_current_round(self):
     tournament = Tournament()
     self.assertTrue(tournament.validate_current_round())
Exemplo n.º 14
0
class TournamentView(MainView):
    def __init__(self):
        super(TournamentView, self).__init__(Tournament)
    
    def index(self, request):
        self._processRequest(request)

        tournaments = [t.json('match') for t in Tournament.objects.filter(state=Tournament.Open, public=True)]
        self._getContext(tournaments=tournaments)

        if self.GET.get('json', False):
            result = Result()
            result.isSuccess = True
            result.values = tournaments
            result.value = result.values[0] if len(result.values) > 0 else None
            return JsonResponse(result)

        return self.render()
    
    def init(self, request, obj_id):
        t = Tournament.objects.get(pk=obj_id)
        t.init()

        result = Result()
        result.isSuccess = True
        result.message = "All matches have been generated"

        return JsonResponse(result)
    
    def post(self, request, *args, **kwargs):
        result = Result()
        if kwargs.get('obj_id', None):
            self._processRequest(request, kwargs['obj_id'])

            if self.POST.get('start'):
                self.object.state = Tournament.Started
                self.object.save()

                result.isSuccess = True

                return JsonResponse(result)
        else:
            self.object = Tournament()
        
        for k,v in request.POST.iteritems():
            if hasattr(self.object, k):
                try:
                    v = int(v)
                except ValueError:
                    pass
                if v.lower() == 'true':
                    v = True
                elif v.lower() == 'false':
                    v = False
                setattr(self.object, k, v)
            else:
                result.isError = True
                result.message = "Invalid property: %s" % k
                break
        
        if not result.isError:
            self.object.save()
            result.isSuccess = True
        
        return JsonResponse(result)
    
    def put(self, request, obj_id):
        result = Result()
        tourn = Tournament.objects.get(pk=obj_id)

        if tourn.state != Tournament.Open:
            result.isError = True
            result.message = "This tournament is not open"
            return JsonResponse(result)
        
        teamID = self.PUT.get('team', None)
        if teamID:
            team = Team.objects.get(pk=teamID)

            if team.members.all().count() != tourn.team_size:
                result.isError = True
                result.message = "%s does not have the correct number of players (%i) to join this tournament" % (team.name, tourn.team_size)
                return JsonResponse(result)

            hasJoined = tourn.matches.filter(Q(red=team) | Q(blu=team), round=1)
            if len(hasJoined):
                result.message = '%s has already joined this tournament' % team.name
                result.isError = True
                return JsonResponse(result)

            matches = tourn.matches.filter(red__isnull=True, round=1)
            if not matches:
                matches = tourn.matches.filter(blu__isnull=True, round=1)
            match = random.choice(matches)

            if match.red:
                match.blu = team
            else:
                match.red = team
            
            tourn.teams.add(team)
            match.save()
            
            result.isSuccess = True
        else:
            result.isError = True
            result.message = "No team provided"

        return JsonResponse(result)