From 0357bd074eeee6df420e8b5e8e09c4436cc09f54 Mon Sep 17 00:00:00 2001 From: Luke Sneeringer Date: Thu, 11 Dec 2014 12:04:09 -0600 Subject: [PATCH] Change user_exists to user_info. --- awx/main/management/commands/user_exists.py | 22 -------------- awx/main/management/commands/user_info.py | 32 +++++++++++++++++++++ 2 files changed, 32 insertions(+), 22 deletions(-) delete mode 100644 awx/main/management/commands/user_exists.py create mode 100644 awx/main/management/commands/user_info.py diff --git a/awx/main/management/commands/user_exists.py b/awx/main/management/commands/user_exists.py deleted file mode 100644 index 7003f542e7..0000000000 --- a/awx/main/management/commands/user_exists.py +++ /dev/null @@ -1,22 +0,0 @@ -# Copyright (c) 2014 Ansible, Inc. -# All Rights Reserved - -import sys - -from django.contrib.auth.models import User -from django.core.management.base import BaseCommand, CommandError - - -class Command(BaseCommand): - """A command that reports whether a username exists within the - system or not. - """ - def handle(self, *args, **options): - any_not_found = False - - for username in args: - if User.objects.filter(username=username).count(): - print('User %s exists.' % username) - else: - print('User %s does not exist.' % username) - any_not_found = True diff --git a/awx/main/management/commands/user_info.py b/awx/main/management/commands/user_info.py new file mode 100644 index 0000000000..7c35719ad6 --- /dev/null +++ b/awx/main/management/commands/user_info.py @@ -0,0 +1,32 @@ +# Copyright (c) 2014 Ansible, Inc. +# All Rights Reserved + +import sys + +from django.contrib.auth.models import User +from django.core.management.base import BaseCommand, CommandError + + +class Command(BaseCommand): + """A command that reports whether a username exists within the + system or not. + """ + def handle(self, username, **options): + """Print out information about the user to the console.""" + + try: + user = User.objects.get(username=username) + + # Print a cute header. + header = 'Information for user: %s' % username + print('%s\n%s' % (header, '=' * len(header))) + + # Print the email and real name of the user. + print('Email: %s' % user.email) + if user.first_name or user.last_name: + print('Name: %s %s' % (user.first_name, user.last_name)) + else: + print('No name provided.') + except User.DoesNotExist: + raise CommandError('User %s does not exist.' % username) +