Ejemplo n.º 1
0
def acta_cd(request,acta_id):
    enc = Encontre.objects.filter(id=acta_id)[0]
    comp_nom = enc.jornada.competicio.nom
    
    if request.method == 'POST':
        myform = ActaFormCD(enc,request.POST)
        if myform.is_valid():
            fcd = myform.cleaned_data

            # Validate user
            valid = True
            f_username = fcd["username"]
            f_password = fcd["password"]
            lusers = User.objects.filter(username=f_username)
            if len(lusers) < 1:
                valid = False
                myform.errors['username'] = ErrorList(['Usuari no existent'])
            elif not(lusers[0].check_password(f_password)):
                valid = False
                myform.errors['password'] = ErrorList(['Contrassenya incorrecta'])
            elif not lusers[0].is_staff:
                luec = UserEquipCompeticio.objects.filter(user__username=f_username)
                if len(luec) < 1:
                    valid = False
                else:
                    uec = luec[0]
                    if not (uec.equipcompeticio == enc.local or uec.equipcompeticio == enc.visitant):
                        valid = False
                        myform.errors['username'] = ErrorList(['No pots modificar aquest partit'])
            if not valid:
                response = render_to_response('programa/acta_cd.html',
                        {'myform':myform,'local':enc.local,'visitant':enc.visitant}, 
                        context_instance=RequestContext(request))
                response["P3P"] = 'CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"'
                return response    
            # End user validation

            lresabc = ["abcr1","abcr2","abcr3","abcrd","abcr4","abcr5","abcr6"]
            lresxyz = ["xyzr1","xyzr2","xyzr3","xyzrd","xyzr4","xyzr5","xyzr6"]
            ljugabc = ["abc1","abc2","abc3","abcd1","abcd2","abc4","abc5","abc6"]
            ljugxyz = ["xyz1","xyz2","xyz3","xyzd1","xyzd2","xyz4","xyz5","xyz6"]

            err = False
            # Check that players belong to its teams
            for i in range(0,len(ljugabc)):
                if (fcd[ljugabc[i]].equipcompeticio != fcd["equipabc"]):
                    myform.errors[ljugabc[i]] = ErrorList(["Aquest jugador no pertany a l'equip."])
                    err = True
                if (fcd[ljugxyz[i]].equipcompeticio == fcd["equipabc"]):
                    myform.errors[ljugxyz[i]] = ErrorList(["Aquest jugador no pertany a l'equip."])
                    err = True 
            # Check that one and only one result is 3 in each match
            for i in range(0,len(lresabc)):
                if ((fcd[lresabc[i]] < 3 and fcd[lresxyz[i]] < 3)
                        or (fcd[lresabc[i]] == 3 and fcd[lresxyz[i]] == 3)):
                    myform.errors[lresabc[i]] = ErrorList(["Resultat incorrecte."])
                    err = True
                    
            # Check that there is no repeated match - TBD
            
            if err:
                response = render_to_response('programa/acta_cd.html',
                    {'myform':myform,'local':enc.local,'visitant':enc.visitant}, 
                    context_instance=RequestContext(request))
                response["P3P"] = 'CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"'
                return response
            
            # All ok
            # - Update abc
            enc.abc = fcd["equipabc"]
            # - Update resultats
            [res_abc,jocs_abc] = [0,0]
            for r in lresabc:
                jocs_abc = jocs_abc + fcd[r]
                if fcd[r] == 3:
                    res_abc = res_abc + 1
            [res_xyz,jocs_xyz] = [0,0]
            for r in lresxyz:
                jocs_xyz = jocs_xyz + fcd[r]
                if fcd[r] == 3:
                    res_xyz = res_xyz + 1
            if enc.abc == enc.local:
                [enc.jocs_local,enc.resultat_local] = [jocs_abc,res_abc]
                [enc.jocs_visitant,enc.resultat_visitant] = [jocs_xyz,res_xyz]
            else:
                [enc.jocs_local,enc.resultat_local] = [jocs_xyz,res_xyz]
                [enc.jocs_visitant,enc.resultat_visitant] = [jocs_abc,res_abc]
            enc.save()
            
            # - Create Individuals and Dobles
            for i in range(1,7):
                lind = Individuals.objects.filter(encontre = enc,numero = i)
                if len(lind) > 0:
                    ind = lind[0]
                else:
                    ind = Individuals()
                ind.encontre = enc
                ind.numero = i
                ind.jugador_abc = fcd["abc" + str(i)]
                ind.jugador_xyz = fcd["xyz" + str(i)]
                ind.jocs_abc = fcd["abcr" + str(i)]
                ind.jocs_xyz = fcd["xyzr" + str(i)]
                ind.save()    
            ldob = Dobles.objects.filter(encontre = enc)
            if len(ldob) > 0:
                dob = ldob[0]
            else:
                dob = Dobles()
            dob.encontre = enc
            dob.jugador_abc_1 = fcd["abcd1"]
            dob.jugador_abc_2 = fcd["abcd2"]
            dob.jugador_xyz_1 = fcd["xyzd1"]
            dob.jugador_xyz_2 = fcd["xyzd2"]
            dob.jocs_abc = fcd["abcrd"]
            dob.jocs_xyz = fcd["xyzrd"]
            dob.save()                

            #return HttpResponseRedirect('/programa/calendari/' + str(comp_nom) + '/')
            
            if comp_nom == '2013g1':
                return HttpResponseRedirect('http://ttintercomarcal.blogspot.com/p/calendari-i-resultats-lliga_7545.html')
            elif comp_nom == '2013g2':
                return HttpResponseRedirect('http://ttintercomarcal.blogspot.com/p/calendari-i-resultats-lliga_7311.html')
                

            if comp_nom == '20121f':
                return HttpResponseRedirect('http://ttintercomarcal.blogspot.com/p/calendari-i-resultats-lliga_23.html')
            elif comp_nom == '20122f1':
                ranquing_precalcula()
                return HttpResponseRedirect('http://ttintercomarcal.blogspot.com/p/calendari-i-resultats-lliga_24.html')
            elif comp_nom == '20122f2':
                ranquing_precalcula()
                return HttpResponseRedirect('http://ttintercomarcal.blogspot.com/p/calendari-i-resultats-lliga_7268.html')
            elif comp_nom == '20122f3':
                ranquing_precalcula()
                return HttpResponseRedirect('http://ttintercomarcal.blogspot.com/p/calendari-i-resultats-lliga_3782.html')


            if comp_nom == '20111f':
                return HttpResponseRedirect('http://ttintercomarcal.blogspot.com/p/calendari-i-resultats-lliga.html')
            elif comp_nom == '20112f1':
                return HttpResponseRedirect('http://ttintercomarcal.blogspot.com/p/calendari-i-resultats-lliga-2011-2012.html')
            elif comp_nom == '20112f2':
                return HttpResponseRedirect('http://ttintercomarcal.blogspot.com/p/calendari-i-resultats-lliga-2011-2012_17.html')

                
            if comp_nom == '20101fA':
                return HttpResponseRedirect('http://ttintercomarcal.blogspot.com/p/calendari-i-resultats-grup-1.html')            
            elif comp_nom == '20101fB':
                return HttpResponseRedirect('http://ttintercomarcal.blogspot.com/p/calendari-i-resultats-grup-2.html')            
            if comp_nom == '20102f1':
                return HttpResponseRedirect('http://ttintercomarcal.blogspot.com/p/calendari-i-resultats-grup-1_05.html')            
            elif comp_nom == '20102f2':
                return HttpResponseRedirect('http://ttintercomarcal.blogspot.com/p/calendari-i-resultats-grup-2_05.html')            


            return HttpResponseRedirect('http://ttintercomarcal.blogspot.com')

        else:
            response = render_to_response('programa/acta_cd.html',
                {'myform':myform,'local':enc.local,'visitant':enc.visitant}, 
                context_instance=RequestContext(request))
            response["P3P"] = 'CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"'
            return response
    else:
        myform = ActaFormCD(enc)
        response = render_to_response('programa/acta_cd.html',
                {'myform':myform,'local':enc.local,'visitant':enc.visitant}, 
                context_instance=RequestContext(request))
        response["P3P"] = 'CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"'
        return response   
Ejemplo n.º 2
0
def acta(request,acta_id):
    enc = Encontre.objects.filter(id=acta_id)[0]
    comp_nom = enc.jornada.competicio.nom

    valid = True
    if not request.user.is_authenticated():
        valid = False
    else:
        if not request.user.is_staff:
            luec = UserEquipCompeticio.objects.filter(user=request.user)
            if luec < 0:
                valid = False
            else:
                uec = luec[0]
                if not (uec.equipcompeticio == enc.local or uec.equipcompeticio == enc.visitant):
                    valid = False
                            
    if not valid:
        return HttpResponseRedirect('/programa/veure_acta/' + str(acta_id) + '/')

    # User is valid
    if request.method == 'POST':
        myform = ActaForm(enc,request.POST)
        if myform.is_valid():
            fcd = myform.cleaned_data
            lresabc = ["abcr1","abcr2","abcr3","abcrd","abcr4","abcr5","abcr6"]
            lresxyz = ["xyzr1","xyzr2","xyzr3","xyzrd","xyzr4","xyzr5","xyzr6"]
            ljugabc = ["abc1","abc2","abc3","abcd1","abcd2","abc4","abc5","abc6"]
            ljugxyz = ["xyz1","xyz2","xyz3","xyzd1","xyzd2","xyz4","xyz5","xyz6"]

            err = False
            # Check that players belong to its teams
            for i in range(0,len(ljugabc)):
                if (fcd[ljugabc[i]].equipcompeticio != fcd["equipabc"]):
                    myform.errors[ljugabc[i]] = ErrorList(["Aquest jugador no pertany a l'equip."])
                    err = True
                if (fcd[ljugxyz[i]].equipcompeticio == fcd["equipabc"]):
                    myform.errors[ljugxyz[i]] = ErrorList(["Aquest jugador no pertany a l'equip."])
                    err = True 
            # Check that one and only one result is 3 in each match
            for i in range(0,len(lresabc)):
                if ((fcd[lresabc[i]] < 3 and fcd[lresxyz[i]] < 3)
                        or (fcd[lresabc[i]] == 3 and fcd[lresxyz[i]] == 3)):
                    myform.errors[lresabc[i]] = ErrorList(["Resultat incorrecte."])
                    err = True
                    
            # Check that there is no repeated match - TBD
            
            if err:
                return render_to_response('programa/acta.html',
                    {'myform':myform,'local':enc.local,'visitant':enc.visitant}, 
                    context_instance=RequestContext(request))
            
            
            # All ok
            # - Update abc
            enc.abc = fcd["equipabc"]
            # - Update resultats
            [res_abc,jocs_abc] = [0,0]
            for r in lresabc:
                jocs_abc = jocs_abc + fcd[r]
                if fcd[r] == 3:
                    res_abc = res_abc + 1
            [res_xyz,jocs_xyz] = [0,0]
            for r in lresxyz:
                jocs_xyz = jocs_xyz + fcd[r]
                if fcd[r] == 3:
                    res_xyz = res_xyz + 1
            if enc.abc == enc.local:
                [enc.jocs_local,enc.resultat_local] = [jocs_abc,res_abc]
                [enc.jocs_visitant,enc.resultat_visitant] = [jocs_xyz,res_xyz]
            else:
                [enc.jocs_local,enc.resultat_local] = [jocs_xyz,res_xyz]
                [enc.jocs_visitant,enc.resultat_visitant] = [jocs_abc,res_abc]
            enc.save()
            
            # - Create Individuals and Dobles
            for i in range(1,7):
                lind = Individuals.objects.filter(encontre = enc,numero = i)
                if len(lind) > 0:
                    ind = lind[0]
                else:
                    ind = Individuals()
                ind.encontre = enc
                ind.numero = i
                ind.jugador_abc = fcd["abc" + str(i)]
                ind.jugador_xyz = fcd["xyz" + str(i)]
                ind.jocs_abc = fcd["abcr" + str(i)]
                ind.jocs_xyz = fcd["xyzr" + str(i)]
                ind.save()    
            ldob = Dobles.objects.filter(encontre = enc)
            if len(ldob) > 0:
                dob = ldob[0]
            else:
                dob = Dobles()
            dob.encontre = enc
            dob.jugador_abc_1 = fcd["abcd1"]
            dob.jugador_abc_2 = fcd["abcd2"]
            dob.jugador_xyz_1 = fcd["xyzd1"]
            dob.jugador_xyz_2 = fcd["xyzd2"]
            dob.jocs_abc = fcd["abcrd"]
            dob.jocs_xyz = fcd["xyzrd"]
            dob.save()                

            logout(request)
            return HttpResponseRedirect('/programa/calendari/' + str(comp_nom) + '/')
            
        else:
            return render_to_response('programa/acta.html',
                {'myform':myform,'local':enc.local,'visitant':enc.visitant}, 
                context_instance=RequestContext(request))
    else:
        myform = ActaForm(enc)
        response = render_to_response('programa/acta.html',
                {'myform':myform,'local':enc.local,'visitant':enc.visitant}, 
                context_instance=RequestContext(request))
        response["P3P"] = 'CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"'
        return response