Django 1.8: declare positional arguments in management commands

(imported from commit d9efca1376de92c8187d25f546c79fece8d2d8c6)
This commit is contained in:
Reid Barton
2015-08-20 17:10:41 -07:00
parent ecc07333af
commit ae0ae3dde8
28 changed files with 285 additions and 274 deletions

View File

@@ -10,11 +10,8 @@ from django_auth_ldap.backend import LDAPBackend, _LDAPUser
# Run this on a cronjob to pick up on name changes.
def query_ldap(*args):
if len(args) != 1:
print "Usage: query_ldap <email address>"
sys.exit(1)
email = args[0]
def query_ldap(**options):
email = options['email']
for backend in get_backends():
if isinstance(backend, LDAPBackend):
ldap_attrs = _LDAPUser(backend, backend.django_to_ldap_username(email)).attrs
@@ -25,5 +22,9 @@ def query_ldap(*args):
print "%s: %s" % (django_field, ldap_attrs[ldap_field])
class Command(BaseCommand):
def add_arguments(self, parser):
parser.add_argument('email', metavar='<email>', type=str,
help="email of user to query")
def handle(self, *args, **options):
query_ldap(*args)
query_ldap(**options)