From 4e7f13d190ac9443ec2f779b90309d0de1871106 Mon Sep 17 00:00:00 2001 From: Ernesto Rico Schmidt <ernesto@ontolabs.com> Date: Fri, 10 Dec 2021 12:00:18 -0400 Subject: [PATCH] Fix create and delete user commands --- program/management/commands/createuser.py | 14 ++++++-------- program/management/commands/deleteuser.py | 10 ++++------ 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/program/management/commands/createuser.py b/program/management/commands/createuser.py index 422c4bff..25985c01 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 a8bb2308..97c44641 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.')) -- GitLab