mirror of
https://github.com/zulip/zulip.git
synced 2025-10-31 20:13:46 +00:00
Django 1.8: declare positional arguments in management commands
(imported from commit d9efca1376de92c8187d25f546c79fece8d2d8c6)
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user