コード例 #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
コード例 #2
0
    def handle(self, *args, **options):
        # look at the arg
        if not args:
            self.stdout.write(self.help)
            return

        # look for commands
        if "add" == args[0]:
            # adding?
            if len(args) <= 1:
                raise CommandError("You need to give a domain")
            d = Domain(
                domain=args[1]
            )
            d.save()
            # we also should add a support inbox - ticket #24
            support_inbox = Inbox(
                    inbox="support",
                    domain=d,
                    user=null_user(),
                    created=datetime.now(utc))
            support_inbox.save()            

            self.stdout.write("%s has been added" % d)
        elif "list" == args[0]:
            domains = Domain.objects.all().iterator()
            for domain in domains:
                self.stdout.write("%s" % domain)
            return
        elif args[0] in ["rm", "remove"]:
            if len(args) <= 1:
                raise CommandError("You need to give a domain to remove")
            
            try:
                d = Domain.objects.get(domain=args[1])
                d.delete()
                self.stdout.write("%s has been removed" % d)
            except Domain.DoesNotExist:
                raise CommandError("Can't find domain '%s'" % args[1])
        else:
            raise CommandError("Can't find command %s" % args[0])
コード例 #3
0
    def handle(self, *args, **options):
        # look at the arg
        if not args:
            self.stdout.write(self.help)
            return

        # look for commands
        if "add" == args[0]:
            with transaction.atomic():
                # adding?
                if len(args) <= 1:
                    raise CommandError("You need to give a domain")
                d = Domain(
                    domain=args[1]
                )
                d.save()
                # we also should add a support inbox - ticket #24
                support_inbox = Inbox(
                        inbox="support",
                        domain=d,
                        created=datetime.now(utc))
                support_inbox.save()

            self.stdout.write("%s has been added" % d)
        elif "list" == args[0]:
            domains = Domain.objects.all().iterator()
            for domain in domains:
                self.stdout.write("%s" % domain)
            return
        elif args[0] in ["rm", "remove"]:
            if len(args) <= 1:
                raise CommandError("You need to give a domain to remove")

            with transaction.atomic():
                try:
                    d = Domain.objects.filter(domain=args[1])
                    d.delete()
                    self.stdout.write("%s has been removed" % args[1])
                except Domain.DoesNotExist:
                    raise CommandError("Can't find domain '%s'" % args[1])

        else:
            raise CommandError("Can't find command %s" % args[0])