diff --git a/program/management/commands/createuser.py b/program/management/commands/createuser.py index 422c4bff8ebdb76f3e567ba148d862119a74df39..25985c0171ea8e1302053d7c609fd317e71cf20c 100644 --- a/program/management/commands/createuser.py +++ b/program/management/commands/createuser.py @@ -1,15 +1,13 @@ 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 add_arguments(self, parser): + parser.add_argument('--username', action='store', help='Specifies the username.', required=True, type=str) + parser.add_argument('--email', action='store', help='Specifies the email address.', required=True, type=str) def handle(self, *args, **options): username = options.get('username', None) @@ -21,6 +19,6 @@ class Command(BaseCommand): User.objects.get(username=username) except User.DoesNotExist: User.objects.create_user(username=username, email=email) - self.stdout.write(self.style.SUCCESS, 'user created successfully.') + self.stdout.write(self.style.SUCCESS('user created successfully.')) else: - self.stdout.write(self.style.NOTICE, 'User already exists, no need to create.') + self.stdout.write(self.style.NOTICE('User already exists, no need to create.')) diff --git a/program/management/commands/deleteuser.py b/program/management/commands/deleteuser.py index a8bb2308ec7c401c92722e85ddc4750e00469bdc..97c44641e5a9804b237d78ba58b4ee4658762a06 100644 --- a/program/management/commands/deleteuser.py +++ b/program/management/commands/deleteuser.py @@ -1,14 +1,12 @@ from django.contrib.auth.models import User from django.core.management.base import BaseCommand, CommandError -from optparse import make_option - class Command(BaseCommand): help = 'deletes an user' - option_list = BaseCommand.option_list + ( - make_option('--username', dest='username', default=None, help='Specifies the username.'), - ) + + def add_arguments(self, parser): + parser.add_argument('--username', action='store', help='Specifies the username.', required=True, type=str), def handle(self, *args, **options): username = options.get('username', None) @@ -20,4 +18,4 @@ class Command(BaseCommand): except User.DoesNotExist: raise 'user does not exist.' else: - self.stdout.write(self.style.SUCCESS, 'user deleted succesfuly.') + self.stdout.write(self.style.SUCCESS('user deleted successfully.'))