Esempio n. 1
0
    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
Esempio n. 2
0
    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
Esempio n. 3
0
 def test_reserved(self):
     self.assertTrue(is_reserved("root"))
     self.assertFalse(is_reserved("root1"))
Esempio n. 4
0
 def test_reserved(self):
     self.assertTrue(is_reserved("root"))
     self.assertFalse(is_reserved("root1"))