def createTerrains(self): ''' Crée des terrains à partir d'un participant ''' nbr = 0 while (nbr < NBR_TERRAINS): participant = random.choice(self.participants) c = Court(rue=u'' + participant.rue, numero= participant.numero, boite=participant.boite, codepostal=participant.codepostal, localite=u''+participant.localite, matiere=random.choice(self.surfaces), type=random.choice(self.types), dispoSamedi=random.choice([True, False]), dispoDimanche=random.choice([True, False]), etat=random.choice(self.etats), valide=random.choice([True, False]), user=participant.user, latitude=participant.latitude, longitude=participant.longitude) c.save() nbr += 1
def view(request): allCourtSurface = CourtSurface.objects.all() allCourtType = CourtType.objects.all() allCourtState = CourtState.objects.all() if request.method == "POST": rue = request.POST['street'] numero = request.POST['number'] boite = request.POST['boite'] postalcode = request.POST['postalcode'] locality = request.POST['locality'] lat = request.POST['lat'] lng = request.POST['lng'] acces = request.POST['acces'] matiere = (u'' + request.POST['matiere']).encode('utf-8') type = (u'' + request.POST['type']).encode('utf-8') etat = (u'' + request.POST['etat']).encode('utf-8') commentaire = request.POST['comment'] if request.POST.__contains__("dispoSamedi"): dispoSamedi = True else: dispoSamedi = False if request.POST.__contains__("dispoDimanche"): dispoDimanche = True else: dispoDimanche = False if rue == "" or numero == "" or postalcode == "" or locality == "" or matiere == "" or type == "" or etat == "": errorAdd = "Veuillez remplir tous les champs obligatoires !" return render(request, 'registerTerrain.html', locals()) # Create court object court = Court(rue=rue, numero=numero, boite=boite, codepostal=postalcode, localite=locality, acces=acces, matiere=CourtSurface.objects.get(nom=matiere), type=CourtType.objects.get( nom=type), dispoDimanche=dispoDimanche, dispoSamedi=dispoSamedi, etat=CourtState.objects.get(nom=etat), commentaire=commentaire, user=request.user, latitude=lat, longitude=lng) # Send confirmation mail send_confirmation_email_court_registered( Participant.objects.get(user=request.user), court) court.save() return redirect(reverse(terrain)) if request.user.is_authenticated(): return render(request, 'registerTerrain.html', locals()) return redirect(reverse(home))