def remove_email(self, email, unsubscribe=False): """ Removes the email from the user's account. If unsubscribe is True, we also remove the email from any groups and mailman mailing lists that it's associated with. The email object is deleted. If unsubscribe is false, we'll create a new, incomplete account where the removed email will reside. """ try: email_obj = Email.objects.get(email=email) except Email.DoesNotExist: raise assert email_obj.user.id == self.id """ If we're removing the primary email, we need to change the primary email and the username. We purposefully do this *before* attempting to create_fresh_user(), since otherwise we may have username conflicts. """ EmailUtils.change_owner_info(email_obj) if unsubscribe: email_obj.unsubscribe_all() email_obj.delete() else: CustomUser.objects.create_fresh_user(email=email)
def populate(self, email=None, first_name=None, last_name=None, phone_number=None): """ Populates the user's account with the parameter values. If the email already exists with a different account, the email will be removed from the other account and added to this one. """ if email: try: email_obj = Email.objects.get(email=email) if email_obj not in self.email_set.all(): EmailUtils.add_existent_email(self.email_set, email_obj) except Email.DoesNotExist: Email.objects.create(email=email, user=self) if first_name and not self.first_name: self.first_name = first_name if last_name and not self.last_name: self.last_name = last_name if phone_number and not self.phone_number: self.phone_number = phone_number self.save()