dump_emails.py 851 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
#!/usr/bin/python3

from django.core.management.base import BaseCommand

from main.models import User

class Command(BaseCommand):
    help = "Dump user emails"

    def add_arguments(self, parser):
        grp = parser.add_mutually_exclusive_group()
        grp.add_argument("--provider", action="store_true",
                help="select only the users who are allowed to create an app")
        grp.add_argument("--guest", action="store_true",
                help="select only the users who are not allowed to create an app")

    def handle(self, *, provider, guest, **kw):
        if provider:
            pred = lambda u: u.is_provider
        elif guest:
            pred = lambda u: not u.is_provider
        else:
            pred = lambda u: True

        print("\n".join(u.email for u in filter(pred, User.objects.order_by("email"))))