Beispiel #1
0
 def _create_tournament_partipant(self, pair):
     tournament = self.assign_tournament_pair(pair)
     if tournament != None:
         participant = TournamentParticipant(tournament=tournament, \
             participant=pair)
         participant.save()
         return participant
     return None
Beispiel #2
0
def assign_tournament(pair):
    """ Assign a tournament to a pair based on their genders (if same or different)
        and their birthdate. The category is based on the older player.
        It may happen that some players are not assigned tournaments (don'f fit)."""
    player1 = pair.player1
    player2 = pair.player2

    #Check if mixte
    if player1.gender != player2.gender:
        mixte = "Mixte"
    elif player1.gender == "M":
        mixte = "M"
    else:
        mixte = "F"

    #Assign the category based on birthdate
    current_year = datetime.now().year
    player1_birth_year = player1.birthdate.year
    player2_birth_year = player2.birthdate.year
    smaller_difference = current_year - player1_birth_year
    if current_year - player2_birth_year < current_year - player1_birth_year:
        smaller_difference = current_year - player2_birth_year

    category = "none"
    if smaller_difference <= 10 and smaller_difference >=9:
        category = "preminimes"
    elif smaller_difference <= 12 and smaller_difference >=11:
        category = "minimes"
    elif smaller_difference <= 14 and smaller_difference >=13:
        category = "cadets"
    elif smaller_difference <= 16 and smaller_difference >=15:
        category = "scolaires"
    elif smaller_difference <= 19 and smaller_difference >=17:
        category = "juniors"
    elif smaller_difference <= 40 and smaller_difference >=20:
        category = "seniors"
    elif smaller_difference > 40:
        category = 'elites'

    if current_year - player1_birth_year <= 15:
        if current_year - player2_birth_year >= 25:
            category = "familles"
            mixte = True
    elif current_year - player2_birth_year <= 15:
        if current_year - player1_birth_year >= 25:
            category = "familles"
            mixte = True

    #Assign a tournament if possible
    exist = (Tournament.objects.filter(category=category, mixte=mixte, season=settings.CURRENT_SEASON).count() != 0)
    if exist:
        tournament= Tournament.objects.get(category=category, mixte=mixte, season=settings.CURRENT_SEASON)
        tp = TournamentParticipant(participant=pair, tournament=tournament)
        tp.save()
Beispiel #3
0
def particular_pair(request, id_pair):
    """Page showing information for a particular pair."""
    pair = Pair.objects.get(pk=id_pair)
    tournament = None
    all_tournaments = Tournament.objects.all()
    if TournamentParticipant.objects.filter(participant=pair).count() != 0:
        tournament = TournamentParticipant.objects.filter(participant=pair).get().tournament
    if request.method == 'POST':
        new_tournament = request.POST['tournament'].strip()
        new_tournament = Tournament.objects.get(pk=int(new_tournament))
        if tournament != None:
            tournament_participant = TournamentParticipant.objects.get(participant=pair, tournament=tournament)
            tournament_participant.delete()
        tournament_participant = TournamentParticipant(tournament=new_tournament, participant=pair)
        tournament_participant.save()
        tournament = new_tournament

    return render(request, 'staff/particular_pair.html', { \
        'pair':pair,
        'tournament':tournament,
        'all_tournaments': all_tournaments,
        })