diff options
author | Ernesto Rico-Schmidt <e.rico.schmidt@gmail.com> | 2011-06-02 20:23:36 (GMT) |
---|---|---|
committer | Ernesto Rico-Schmidt <e.rico.schmidt@gmail.com> | 2011-06-02 20:23:36 (GMT) |
commit | e090ab896c0443f5967301a034ad53735efe83d6 (patch) | |
tree | cae8201c0e3baf94a27f79611c9d8bfd922186b0 | |
parent | 7ab5b62bb78747451505d2eb11bc80222c65d89b (diff) |
added createuser command.
-rw-r--r-- | program/management/commands/createuser.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/program/management/commands/createuser.py b/program/management/commands/createuser.py new file mode 100644 index 0000000..a356bb3 --- /dev/null +++ b/program/management/commands/createuser.py @@ -0,0 +1,25 @@ +from django.contrib.auth.models import User +from django.core.management.base import BaseCommand, CommandError + +from optparse import make_option + +class Command(BaseCommand): + help = 'creates an user' + option_list = BaseCommand.option_list + ( + make_option('--username', dest='username', default=None, help='Specifies the username.'), + make_option('--email', dest='email', default=None, help='Specifies the email address.'), + ) + + def handle(self, *args, **options): + username = options.get('username', None) + email = options.get('email', None) + + if not username or not email: + raise CommandError("You must use --username and --email.") + try: + User.objects.get(username=username) + except User.DoesNotExist: + User.objects.create_user(username=username, email=email) + print 'user created successfully.' + else: + print 'User already exists, no need to create.' |