예제 #1
0
    def _create_user_registration(self, user):
        LEVEL_CHOICES = [
                ('-','-'),
                ('C30.5', 'C30.5'),
                ('C30.4', 'C30.4'),
                ('C30.3', 'C30.3'),
                ('C30.2', 'C30.2'),
                ('C30.1', 'C30.1'),
                ('C30', 'C30'),
                ('C15.5', 'C15.5'),
                ('C15.4', 'C15.4'),
                ('C15.3', 'C15.3'),
                ('C15.2', 'C15.2'),
                ('C15.1', 'C15.1'),
                ('C15', 'C15'),
                ('B+4/6', 'B+4/6'),
                ('B+2/6', 'B+2/6'),
                ('B0', 'B0'),
                ('B-2/6', 'B-2/6'),
                ('B-4/6', 'B-4/6'),
                ('B-15', 'B-15'),
                ('B-15.1', 'B-15.1'),
                ('B-15.2', 'B-15.2'),
                ('B-15.4', 'B-15.4'),
                ('A4', 'A4'),
                ('A3', 'A3'),
                ('A2', 'A2'),
                ('A1', 'A1')
            ]

        PAYMENT_METHODS = [("Cash","Cash"), ("Visa","Visa"), \
            ("Bancontact","Bancontact"), ("MasterCard","MasterCard"), \
            ("Paypal","Paypal")]

        season = settings.CURRENT_SEASON
        bbq = random.randint(0,1) == 0
        a = 0
        b = len(LEVEL_CHOICES)-1
        level = LEVEL_CHOICES[random.randint(a, b)][0]
        b = len(PAYMENT_METHODS)-1
        payement_method = PAYMENT_METHODS[random.randint(a, b)][0]
        payement_done = random.randint(0,1) == 0

        user_registration = UserRegistration(user=user, season=season, bbq=bbq, \
                level=level, payement_method=payement_method, \
                payement_done=payement_done)
        user_registration.save()

        return user_registration
예제 #2
0
파일: views.py 프로젝트: ivanahad/sep2015E
def register(request):
    """ Method who receive requests (post/get) from register.html
        create a player on post request """
    if request.method == 'POST':  # S'il s'agit d'une requête POST
        usr1 = PlayerForm(request.POST, prefix="usr1")
        reg1 = RegistrationForm(request.POST, prefix="reg1")
        usr2 = PlayerForm(request.POST, prefix="usr2")
        reg2 = RegistrationForm(request.POST, prefix="reg2")

        if 'solo_registration' in request.POST :
            usr2 = PlayerForm(prefix="usr2")
            reg2 = RegistrationForm(prefix="reg2")

        pair = PairRegistrationForm(request.POST)

        emailForm1 = EmailOldUserForm(prefix="email1")
        #Solo registration
        if 'solo_registration' in request.POST \
                and usr1.is_valid() and reg1.is_valid():
            new_user1 = User( \
                    firstname = usr1.cleaned_data['firstname'], \
                    lastname = usr1.cleaned_data['lastname'], \
                    gender = usr1.cleaned_data['gender'], \
                    birthdate = usr1.cleaned_data['birthdate'], \
                    address_street = usr1.cleaned_data['address_street'], \
                    address_number = usr1.cleaned_data['address_number'], \
                    address_box = usr1.cleaned_data['address_box'], \
                    city = usr1.cleaned_data['city'], \
                    country = usr1.cleaned_data['country'], \
                    zipcode = usr1.cleaned_data['zipcode'], \
                    email = usr1.cleaned_data['email'], \
                    phone = usr1.cleaned_data['phone'])
            new_user1.save()

            registration1 = UserRegistration( \
                    user = new_user1, \
                    season = settings.CURRENT_SEASON, \
                    bbq = reg1.cleaned_data['bbq'], \
                    level = reg1.cleaned_data['level'])
            registration1.save()

            assign_tournament_solo(new_user1)

            return redirect('players.views.payement', id_user1=new_user1.pk, id_registration1=registration1.pk,
                    id_user2=-1, id_registration2=-1, id_pair=-1)

        #Pair registration
        elif usr1.is_valid() and usr2.is_valid() \
                and reg1.is_valid() and reg2.is_valid() \
                and pair.is_valid():
            new_user1 = User( \
                    firstname = usr1.cleaned_data['firstname'], \
                    lastname = usr1.cleaned_data['lastname'], \
                    gender = usr1.cleaned_data['gender'], \
                    birthdate = usr1.cleaned_data['birthdate'], \
                    address_street = usr1.cleaned_data['address_street'], \
                    address_number = usr1.cleaned_data['address_number'], \
                    address_box = usr1.cleaned_data['address_box'], \
                    city = usr1.cleaned_data['city'], \
                    country = usr1.cleaned_data['country'], \
                    zipcode = usr1.cleaned_data['zipcode'], \
                    email = usr1.cleaned_data['email'], \
                    phone = usr1.cleaned_data['phone'])
            new_user1.save()

            registration1 = UserRegistration( \
                    user = new_user1, \
                    season = settings.CURRENT_SEASON, \
                    bbq = reg1.cleaned_data['bbq'], \
                    level = reg1.cleaned_data['level'])
            registration1.save()

            new_user2 = User( \
                    firstname = usr2.cleaned_data['firstname'], \
                    lastname = usr2.cleaned_data['lastname'], \
                    gender = usr2.cleaned_data['gender'], \
                    birthdate = usr2.cleaned_data['birthdate'], \
                    address_street = usr2.cleaned_data['address_street'], \
                    address_number = usr2.cleaned_data['address_number'], \
                    address_box = usr2.cleaned_data['address_box'], \
                    city = usr2.cleaned_data['city'], \
                    country = usr2.cleaned_data['country'], \
                    zipcode = usr2.cleaned_data['zipcode'], \
                    email = usr2.cleaned_data['email'], \
                    phone = usr2.cleaned_data['phone'])
            new_user2.save()

            registration2 = UserRegistration( \
                    user = new_user2, \
                    season = settings.CURRENT_SEASON, \
                    bbq = reg2.cleaned_data['bbq'], \
                    level = reg2.cleaned_data['level'])
            registration2.save()

            pair = Pair(player1 = new_user1, player2 = new_user2, \
                    average = 0.0, \
                    season = settings.CURRENT_SEASON, \
                    comment = pair.cleaned_data['comment'])
            pair.save()

            assign_tournament(pair)

            return redirect('players.views.payement', id_user1=new_user1.pk, id_user2=new_user2.pk,
                id_registration1=registration1.pk, id_registration2=registration2.pk, id_pair=pair.pk)

    else:
        usr1 = PlayerForm(prefix="usr1")
        reg1 = RegistrationForm(prefix="reg1")
        usr2 = PlayerForm(prefix="usr2")
        reg2 = RegistrationForm(prefix="reg2")
        pair = PairRegistrationForm()
        emailForm1 = EmailOldUserForm(prefix="email1")

        trn_open = Tournament.objects.filter(is_open=True).count()

        if trn_open == 0  :
            return render(request, 'players/no_tournament_open.html')

    return render(request, 'players/register.html', {
        "usr1": usr1,
        "reg1": reg1,
        "usr2": usr2,
        "reg2": reg2,
        "pair": pair,
        "email1": emailForm1,
            })