def save(self): """Create a new user and parent. Returns the new user.""" data = self.cleaned_data password = data["password"] email = data["email"] first_name = data["first_name"] last_name = data["last_name"] phone_number = data["phone_number"] address = data["address"] address2 = data["address2"] city = data["city"] state = data["state"] zip_code = data["zip_code"] username = generate_id(first_name, last_name) # new_user = RegistrationProfile.objects.create_inactive_user(username, password, email, send_email=True) new_user = User.objects.create_user(username, email, password) new_user.first_name = first_name new_user.last_name = last_name new_user.save() # new_user.groups.add(2) if Parent.objects.filter(email=email).count() < 1: new_parent = Parent() new_household = Household() new_household.creation_date = date.today() new_household.save() new_parent.household = new_household new_parent.first_name = first_name new_parent.last_name = last_name new_parent.email = email new_parent.phone_number = phone_number new_parent.address = address new_parent.address2 = address2 new_parent.city = city new_parent.state = state new_parent.zip_code = zip_code new_parent.user = new_user new_parent.save() else: new_parent = Parent.objects.get(email=email) new_parent.user = new_user new_parent.save() subject = "Seaturtle Swim School Online Registration" message = render_to_string("registration/new_account_confirmation.txt", {"email": email, "password": password}) send_mail(subject, message, "*****@*****.**", [new_user.email]) return new_user
def save(self): """Create a new parent, household and a new user if email address is provided. Returns the new parent.""" data = self.cleaned_data email = data["email"] first_name = data["first_name"] last_name = data["last_name"] phone_number = data["phone_number"] address = data["address"] address2 = data["address2"] city = data["city"] state = data["state"] zip_code = data["zip_code"] has_registrationform = data["has_registrationform"] if email: username = email password = random_string(7, variable=False, charset="ALLCHAR") new_user = User.objects.create_user(username, email, password) new_user.first_name = first_name new_user.last_name = last_name new_user.save() # check if we are providing an existing household, if not create a new one, if so then attach new parent to that household. if not self.household_id: household = Household() household.creation_date = date.today() household.save() else: household = Household.objects.get(id=self.household_id) new_parent = Parent() if email: new_parent.user_id = new_user.id new_parent.household = household new_parent.first_name = first_name new_parent.last_name = last_name new_parent.email = email new_parent.phone_number = phone_number new_parent.address = address new_parent.address2 = address2 new_parent.city = city new_parent.state = state new_parent.zip_code = zip_code new_parent.has_registrationform = has_registrationform new_parent.save() return new_parent