Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
hypha
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
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
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
ots
hypha
Commits
8502d66d
Commit
8502d66d
authored
7 years ago
by
Dan Braghis
Browse files
Options
Downloads
Patches
Plain Diff
Clean-up
parent
1e7ed8b9
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
opentech/apply/users/management/commands/migrate_users.py
+13
-4
13 additions, 4 deletions
opentech/apply/users/management/commands/migrate_users.py
with
13 additions
and
4 deletions
opentech/apply/users/management/commands/migrate_users.py
+
13
−
4
View file @
8502d66d
...
@@ -15,7 +15,7 @@ class Command(BaseCommand):
...
@@ -15,7 +15,7 @@ class Command(BaseCommand):
groups
=
Group
.
objects
.
all
()
groups
=
Group
.
objects
.
all
()
def
add_arguments
(
self
,
parser
):
def
add_arguments
(
self
,
parser
):
parser
.
add_argument
(
'
source
'
,
nargs
=
'
?
'
,
type
=
argparse
.
FileType
(
'
r
'
),
help
=
'
Migration source JSON file
'
)
parser
.
add_argument
(
'
source
'
,
type
=
argparse
.
FileType
(
'
r
'
),
help
=
'
Migration source JSON file
'
)
@transaction.atomic
@transaction.atomic
def
handle
(
self
,
*
args
,
**
options
):
def
handle
(
self
,
*
args
,
**
options
):
...
@@ -37,18 +37,27 @@ class Command(BaseCommand):
...
@@ -37,18 +37,27 @@ class Command(BaseCommand):
operation
=
"
Imported
"
if
created
else
"
Processed
"
operation
=
"
Imported
"
if
created
else
"
Processed
"
for
group
in
self
.
get_user_groups
(
user
)
:
group
s
=
self
.
get_user_groups
(
user
)
user_object
.
groups
.
add
(
group
)
user_object
.
groups
.
set
(
group
s
)
# Ensure uid is set
# Ensure uid is set
user_object
.
drupal_id
=
uid
user_object
.
drupal_id
=
uid
user_object
.
save
()
user_object
.
save
()
print
(
f
"
{
operation
}
user
{
uid
}
(
{
full_name
}
)
"
)
self
.
stdout
.
write
(
f
"
{
operation
}
user
{
uid
}
(
{
full_name
}
)
"
)
def
get_full_name
(
self
,
user
):
def
get_full_name
(
self
,
user
):
full_name
=
user
.
get
(
'
field_otf_real_name
'
,
None
)
full_name
=
user
.
get
(
'
field_otf_real_name
'
,
None
)
try
:
try
:
"""
Drupal is i18n-ready out of the box. As such, the data
structure includes a language reference, defaulting to
'
und
'
(undefined)
In addition to that, most fields are arrays indexed by language, and
the value delta. Different field types will have a different value.
Native entity fields are loaded directly (as string or int). They are
things like entity id, owner, created/updated timestamp.
And name/mail on users.
"""
full_name
=
full_name
[
'
und
'
][
0
][
'
safe_value
'
]
full_name
=
full_name
[
'
und
'
][
0
][
'
safe_value
'
]
except
(
KeyError
,
TypeError
):
except
(
KeyError
,
TypeError
):
full_name
=
user
.
get
(
'
name
'
)
full_name
=
user
.
get
(
'
name
'
)
...
...
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