def get_initial(self): initial = super(UserDetailView, self).get_initial() contact = self._get_bind_contact() if contact: # Guess some sort of usable username username = flatten(contact, ".") if len(username) < 3: username = getattr(contact, "email", "").split("@")[0] if len(username) < 3: username = "******" % random.randint(0, 99999999) initial.update( username=username, email=getattr(contact, "email", ""), first_name=getattr(contact, "first_name", ""), last_name=getattr(contact, "last_name", ""), ) return initial
def test_flatten(): text = "Whät is Löve? Bäby Don't Hurt Me" assert flatten(text) == "what-is-love?-baby-don't-hurt-me" assert flatten(text, "/") == "what/is/love?/baby/don't/hurt/me"
def save(self, *args, **kwargs): if not self.identifier: raise ValueError(u"Attribute with null identifier not allowed") self.identifier = flatten(("%s" % self.identifier).lower()) return super(Attribute, self).save(*args, **kwargs)