Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Debian New Member Process
contributors.debian.org
Commits
e7b6d8cb
Unverified
Commit
e7b6d8cb
authored
Aug 18, 2020
by
Enrico Zini
Browse files
Partial merge to do user merging via management command
parents
3b069f4b
35f2e056
Pipeline
#166131
passed with stage
in 1 minute and 47 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
contributors/management/__init__.py
0 → 100644
View file @
e7b6d8cb
contributors/management/commands/__init__.py
0 → 100644
View file @
e7b6d8cb
contributors/management/commands/usermerge.py
0 → 100644
View file @
e7b6d8cb
from
django.core.management.base
import
BaseCommand
,
CommandError
from
contributors.models
import
User
import
getpass
import
sys
import
logging
log
=
logging
.
getLogger
(
__name__
)
class
Command
(
BaseCommand
):
help
=
'Merge users'
def
add_arguments
(
self
,
parser
):
parser
.
add_argument
(
"--quiet"
,
action
=
"store_true"
,
dest
=
"quiet"
,
default
=
None
,
help
=
"Disable progress reporting"
)
parser
.
add_argument
(
"--author"
,
action
=
"store"
,
metavar
=
"username"
,
default
=
getpass
.
getuser
(),
help
=
"Username of the user performing this operation"
)
parser
.
add_argument
(
"--into"
,
action
=
"store"
,
metavar
=
"dest_username"
,
required
=
True
,
help
=
"Destination user that other user(s) are merged into"
)
parser
.
add_argument
(
"users"
,
nargs
=
"+"
,
metavar
=
"src_username"
,
help
=
"Users to merge into the destination one"
)
def
handle
(
self
,
into
,
users
,
author
,
quiet
=
False
,
*
args
,
**
opts
):
FORMAT
=
"%(asctime)-15s %(levelname)s %(message)s"
if
quiet
:
logging
.
basicConfig
(
level
=
logging
.
WARNING
,
stream
=
sys
.
stderr
,
format
=
FORMAT
)
else
:
logging
.
basicConfig
(
level
=
logging
.
INFO
,
stream
=
sys
.
stderr
,
format
=
FORMAT
)
author
=
User
.
objects
.
get
(
username
=
author
)
dest
=
User
.
objects
.
get
(
username
=
into
)
src
=
[
User
.
objects
.
get
(
x
)
for
x
in
users
]
if
dest
in
src
:
raise
CommandError
(
f
"Cannot merge User
{
src
}
into itself"
)
for
user
in
src
:
dest
.
merge
(
user
,
audit_author
=
author
,
audit_notes
=
"merged from command line"
)
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment