コード例 #1
0
ファイル: populate.py プロジェクト: sethgrid/email_list
    def handle(self, *args, **options):
        emails_to_create = 200
        percent_chance_to_add_to_list = 75
        percent_chance_to_unsub = 25

        # if drop is set, remove all relevant data
        if args and args[0] == 'drop':
            Sender.objects.all().delete()
            Email.objects.all().delete()
            List.objects.all().delete()

            self.stdout.write("Data dropped")

        # if sender does not exist, create
        names = ['A', 'B', 'C', 'D', 'E']
        for name in names:
            sender = Sender.objects.filter(name=name)
            if not sender:
                sender = Sender()
                sender.name = name
                sender.save()

        senders = Sender.objects.all()

        self.stdout.write("Senders created")

        # create the emails and assign to senders in List
        for i in range(emails_to_create):
            import random

            # slight chance for data collision, acceptable here
            address = ''.join(random.choice('0123456789abcdefghijklmnopqrstuvwxyz') for i in range (8))
            email = Email()
            email.email_address = address + '@example.com'
            email.save()

            # go through each sender...
            for i in range(len(senders)):
                # chance to attach this email with this sender
                if int(random.randrange(100)) > percent_chance_to_add_to_list:
                    sender_list = List()
                    sender_list.sender = senders[i]
                    sender_list.recipient = email

                    # chance to have this email unsubscribed from this sender
                    if int(random.randrange(100)) < percent_chance_to_unsub:
                        sender_list.unsubscribed = 1

                    sender_list.save()

        self.stdout.write("Email addresses created and assigned to senders")
コード例 #2
0
ファイル: views.py プロジェクト: sethgrid/email_list
def add_email(request, sender_name, email_address):
    sender = _get_sender(sender_name)
    if not sender:
        return _send_error("No Sender Found", 404)

    email = Email()
    email.email_address = email_address + "@example.com"
    email.save()

    list = List()
    list.sender = sender
    list.recipient = email
    list.save()

    data = {"message": "success"}
    return _send_response(data, 200)