def done(self, request, form_list): """ Complete the wizard in three steps: 1. Create the new family object and set the necessary values 2. Move persoonA with any children to the new family 3. Move persoonB with any children to the new family """ # Stored data persoonA = self.storedFields["persoonA"] persoonB = self.storedFields["persoonB"] ################################ # 1. CREATE NEW FAMILY OBJECT # - Create object # - Set new family name # - Set new address ################################ # We always create a new Gezin object for the married couple, # then throw away the old Gezin objects if they are empty. gezin = Gezin() # Determine new family name if (form_list[2].cleaned_data["gezinshoofd"] == "A"): gezin.txtgezinsnaam = Gezin.create_gezins_naam(persoonA) else: gezin.txtgezinsnaam = Gezin.create_gezins_naam(persoonB) # Check what address the new family is using: A, B, or NEW code = form_list[3].cleaned_data["code"] # Retrieve the corresponding existing family (gezinB may be None) if "gezin"+code in self.storedFields: oldGezin = self.storedFields["gezin"+code] # gezinA or gezinB else: oldGezin = None # If the user chose the address of person B, but person B is new, # we have the same situation as when the address is new. if (code == "NEW" or (code == "B" and oldGezin == None)): # New address, create gezin gezin.txtstraatnaam = form_list[3].cleaned_data["txtstraatnaam"] gezin.inthuisnummer = form_list[3].cleaned_data["inthuisnummer"] gezin.txthuisnummertoevoeging = form_list[3].cleaned_data["txthuisnummertoevoeging"] gezin.txtpostcode = form_list[3].cleaned_data["txtpostcode"] gezin.txtplaats = form_list[3].cleaned_data["txtplaats"] gezin.idland = form_list[3].cleaned_data["idland"] else: # Existing address, copy data from specified address gezin.txtstraatnaam = oldGezin.txtstraatnaam gezin.inthuisnummer = oldGezin.inthuisnummer gezin.txthuisnummertoevoeging = oldGezin.txthuisnummertoevoeging gezin.txtpostcode = oldGezin.txtpostcode gezin.txtplaats = oldGezin.txtplaats gezin.idland = oldGezin.idland # Save print "CREATING NEW GEZIN %s" % (gezin) gezin.save() ####################################### # 2. UDPATE A: # - Move any children to new family # - Change family role for A # - Move A to new family # - Remove old family # - Update marriage info ####################################### # If persoonA is not a child if (persoonA.idgezinsrol_id != GezinsRol.KIND): # Move the existing children in the same family to the new family. children = persoonA.idgezin.persoon_set.filter(idgezinsrol=GezinsRol.KIND) for child in children: child.idgezin = gezin child.save() # Change family role if (form_list[2].cleaned_data["gezinshoofd"] == "A"): persoonA.idgezinsrol = GezinsRol.objects.get(pk=GezinsRol.GEZINSHOOFD) else: persoonA.idgezinsrol = GezinsRol.objects.get(pk=GezinsRol.PARTNER) # Move persoonA to new family persoonAGezinOld = persoonA.idgezin persoonA.idgezin = gezin # Remove old gezin of persoonA if empty if (len(persoonAGezinOld.persoon_set.all()) == 0): print "DELETING GEZIN " + str(persoonAGezinOld) persoonAGezinOld.delete() # Update marriage info persoonA.dtmhuwelijksdatum = form_list[1].cleaned_data["dtmhuwelijksdatum"] persoonA.dtmdatumhuwelijksbevestiging = form_list[1].cleaned_data["dtmdatumhuwelijksbevestiging"] persoonA.idhuwelijksgemeente = form_list[1].cleaned_data["idhuwelijksgemeente"] persoonA.save() ####################################### # 3. UDPATE B: # - Move any children to new family # - Change family role for B # - Move B to new family # - Remove old family (if present) ####################################### # Check if persoonB is an existing person, and not a child if (persoonB.idgezin and persoonB.idgezinsrol != GezinsRol.KIND): # If persoonB is not a child, move all children in the same family to # the new family. children = persoonB.idgezin.persoon_set.filter(idgezinsrol=GezinsRol.KIND) for child in children: child.idgezin = gezin child.save() # Update the family role if (form_list[2].cleaned_data["gezinshoofd"] == "A"): persoonB.idgezinsrol = GezinsRol.objects.get(pk=GezinsRol.PARTNER) else: persoonB.idgezinsrol = GezinsRol.objects.get(pk=GezinsRol.GEZINSHOOFD) # Move persoonB to new family persoonBGezinOld = persoonB.idgezin persoonB.idgezin = gezin # Remove old gezin of persoonB if 'empty' if (persoonBGezinOld and len(persoonB.idgezin.persoon_set.all()) == 0): print "DELETING GEZIN " + str(persoonBGezinOld) persoonBGezinOld.delete() # Update marriage info persoonB.dtmhuwelijksdatum = form_list[1].cleaned_data["dtmhuwelijksdatum"] persoonB.dtmdatumhuwelijksbevestiging = form_list[1].cleaned_data["dtmdatumhuwelijksbevestiging"] persoonB.idhuwelijksgemeente = form_list[1].cleaned_data["idhuwelijksgemeente"] # Update membership persoonB.idlidmaatschapvorm = form_list[0].cleaned_data["idlidmaatschapvorm"] persoonB.save() return HttpResponseRedirect("/leden/gezin/%d/" % (gezin.idgezin))
def done(self, request, form_list): """ Process the completed wizard. """ # Stored data persoonA = self.storedFields["persoonA"] persoonB = self.storedFields["persoonB"] # We always create a new Gezin object for the married couple, # then throw away the old Gezin objects if they are empty. gezin = Gezin() # Head of family A or B if (form_list[1].cleaned_data["gezinshoofd"] == "A"): familyHead = persoonA persoonA.idgezinsrol = GezinsRol.objects.get(pk=1) persoonB.idgezinsrol = GezinsRol.objects.get(pk=2) else: familyHead = persoonB persoonB.idgezinsrol = GezinsRol.objects.get(pk=1) persoonA.idgezinsrol = GezinsRol.objects.get(pk=2) # Create gezinsnaam gezin.txtgezinsnaam = createGezinsNaam(familyHead) # Check what address the new family is using code = form_list[2].cleaned_data["code"] if (code == "NEW"): # New address, create gezin gezin.txtstraatnaam = form_list[2].cleaned_data["txtstraatnaam"] gezin.inthuisnummer = form_list[2].cleaned_data["inthuisnummer"] gezin.txthuisnummertoevoeging = form_list[2].cleaned_data["txthuisnummertoevoeging"] gezin.txtpostcode = form_list[2].cleaned_data["txtpostcode"] gezin.txtplaats = form_list[2].cleaned_data["txtplaats"] gezin.idland = form_list[2].cleaned_data["idland"] else: # Existing address, copy data from specified address oldGezin = self.storedFields["gezin"+code] # gezinA or gezinB gezin.txtstraatnaam = oldGezin.txtstraatnaam gezin.inthuisnummer = oldGezin.inthuisnummer gezin.txthuisnummertoevoeging = oldGezin.txthuisnummertoevoeging gezin.txtpostcode = oldGezin.txtpostcode gezin.txtplaats = oldGezin.txtplaats gezin.idland = oldGezin.idland # Save print "CREATING NEW GEZIN %s" % (gezin) gezin.save() # Move persoonA to gezin persoonAGezinOld = persoonA.idgezin persoonA.idgezin = gezin persoonA.save() # Remove old gezin if 'empty' if (len(persoonAGezinOld.persoon_set.all()) == 0): print "DELETING GEZIN " + str(persoonAGezinOld) persoonAGezinOld.delete() # Move persoonB to gezin persoonBGezinOld = persoonB.idgezin persoonB.idgezin = gezin persoonB.save() # Remove old gezin if 'empty' if (persoonBGezinOld and len(persoonBGezinOld.persoon_set.all()) == 0): print "DELETING GEZIN " + str(persoonBGezinOld) persoonBGezinOld.delete() return HttpResponseRedirect("/leden/gezin/%d/" % (gezin.idgezin))