def create(self, length=None, domain=None, **kwargs): """Create a new Inbox, with a local part of `length`""" from inboxen.models import Domain length = length or settings.INBOX_LENGTH assert length > 0, "Length must be greater than 0 (zero)" if not isinstance(domain, Domain): raise Domain.DoesNotExist( _("You need to provide a Domain object for an Inbox")) # loop around until we get soemthing unique while True: inbox = get_random_string(length, settings.INBOX_CHOICES) if is_reserved(inbox): # inbox is reserved, try again continue try: with transaction.atomic(): return super(InboxQuerySet, self).create(inbox=inbox, created=timezone.now(), domain=domain, **kwargs) except IntegrityError: pass
def create(self, length=None, domain=None, **kwargs): """Create a new Inbox, with a local part of `length`""" from inboxen.models import Domain length = length or settings.INBOX_LENGTH assert length > 0, "Length must be greater than 0 (zero)" if not isinstance(domain, Domain): raise Domain.DoesNotExist(_("You need to provide a Domain object for an Inbox")) # loop around until we get soemthing unique while True: inbox = get_random_string(length, settings.INBOX_CHOICES) if is_reserved(inbox): # inbox is reserved, try again continue try: with transaction.atomic(): return super(InboxQuerySet, self).create( inbox=inbox, created=timezone.now(), domain=domain, **kwargs ) except IntegrityError: pass
def test_reserved(self): self.assertTrue(is_reserved("root")) self.assertFalse(is_reserved("root1"))