Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
steering
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AURA
steering
Commits
4e7f13d1
Commit
4e7f13d1
authored
3 years ago
by
Ernesto Rico Schmidt
Browse files
Options
Downloads
Patches
Plain Diff
Fix create and delete user commands
parent
d4caa032
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
program/management/commands/createuser.py
+6
-8
6 additions, 8 deletions
program/management/commands/createuser.py
program/management/commands/deleteuser.py
+4
-6
4 additions, 6 deletions
program/management/commands/deleteuser.py
with
10 additions
and
14 deletions
program/management/commands/createuser.py
+
6
−
8
View file @
4e7f13d1
from
django.contrib.auth.models
import
User
from
django.contrib.auth.models
import
User
from
django.core.management.base
import
BaseCommand
,
CommandError
from
django.core.management.base
import
BaseCommand
,
CommandError
from
optparse
import
make_option
class
Command
(
BaseCommand
):
class
Command
(
BaseCommand
):
help
=
'
creates an user
'
help
=
'
creates an user
'
option_list
=
BaseCommand
.
option_list
+
(
make_option
(
'
--username
'
,
dest
=
'
username
'
,
default
=
None
,
help
=
'
Specifies the username.
'
),
def
add_arguments
(
self
,
parser
):
make_option
(
'
--email
'
,
dest
=
'
email
'
,
default
=
None
,
help
=
'
Specifies the email address.
'
),
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
):
def
handle
(
self
,
*
args
,
**
options
):
username
=
options
.
get
(
'
username
'
,
None
)
username
=
options
.
get
(
'
username
'
,
None
)
...
@@ -21,6 +19,6 @@ class Command(BaseCommand):
...
@@ -21,6 +19,6 @@ class Command(BaseCommand):
User
.
objects
.
get
(
username
=
username
)
User
.
objects
.
get
(
username
=
username
)
except
User
.
DoesNotExist
:
except
User
.
DoesNotExist
:
User
.
objects
.
create_user
(
username
=
username
,
email
=
email
)
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
:
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.
'
)
)
This diff is collapsed.
Click to expand it.
program/management/commands/deleteuser.py
+
4
−
6
View file @
4e7f13d1
from
django.contrib.auth.models
import
User
from
django.contrib.auth.models
import
User
from
django.core.management.base
import
BaseCommand
,
CommandError
from
django.core.management.base
import
BaseCommand
,
CommandError
from
optparse
import
make_option
class
Command
(
BaseCommand
):
class
Command
(
BaseCommand
):
help
=
'
deletes an user
'
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
):
def
handle
(
self
,
*
args
,
**
options
):
username
=
options
.
get
(
'
username
'
,
None
)
username
=
options
.
get
(
'
username
'
,
None
)
...
@@ -20,4 +18,4 @@ class Command(BaseCommand):
...
@@ -20,4 +18,4 @@ class Command(BaseCommand):
except
User
.
DoesNotExist
:
except
User
.
DoesNotExist
:
raise
'
user does not exist.
'
raise
'
user does not exist.
'
else
:
else
:
self
.
stdout
.
write
(
self
.
style
.
SUCCESS
,
'
user deleted succesfuly.
'
)
self
.
stdout
.
write
(
self
.
style
.
SUCCESS
(
'
user deleted succes
s
ful
l
y.
'
)
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment