Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
converse.js
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
converse.js
Commits
5270dade
Commit
5270dade
authored
Jul 16, 2015
by
Michal Čihař
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add --check to user import
Signed-off-by:
Michal Čihař
<
michal@cihar.com
>
parent
548ca19d
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
11 deletions
+32
-11
docs/admin/management.rst
docs/admin/management.rst
+5
-2
weblate/accounts/management/commands/importusers.py
weblate/accounts/management/commands/importusers.py
+27
-9
No files found.
docs/admin/management.rst
View file @
5270dade
...
...
@@ -159,13 +159,16 @@ importuserdata <file.json>
Imports userdata from file created by :djadmin:`dumpuserdata`
importusers <file.json>
-----------------------
importusers
--checck
<file.json>
-----------------------
---------
.. django-admin:: importusers
Imports users from JSON dump of Django auth_users database.
With ``--check`` it will just check whether given file can be imported and
report possible conflicts on usernames or emails.
You can dump users from existing Django installation using:
.. code-block:: sh
...
...
weblate/accounts/management/commands/importusers.py
View file @
5270dade
...
...
@@ -20,12 +20,20 @@
from
django.core.management.base
import
BaseCommand
,
CommandError
from
django.contrib.auth.models
import
User
from
optparse
import
make_option
import
json
class
Command
(
BaseCommand
):
help
=
'imports users from JSON dump of database'
args
=
'<json-file>'
option_list
=
BaseCommand
.
option_list
+
(
make_option
(
'--check'
,
action
=
'store_true'
,
help
=
'Only check import, do not actually create users'
),
)
def
handle
(
self
,
*
args
,
**
options
):
'''
...
...
@@ -41,14 +49,23 @@ class Command(BaseCommand):
if
'fields'
in
line
:
line
=
line
[
'fields'
]
if
'is_active'
in
line
and
not
line
[
'is_active'
]:
continue
if
not
line
[
'email'
]
or
not
line
[
'username'
]:
self
.
stderr
.
write
(
'Skipping {}, has blank username or email'
.
format
(
line
)
)
continue
if
User
.
objects
.
filter
(
username
=
line
[
'username'
]).
exists
():
self
.
std
out
.
write
(
self
.
std
err
.
write
(
'Skipping {}, username exists'
.
format
(
line
[
'username'
])
)
continue
if
User
.
objects
.
filter
(
email
=
line
[
'email'
]).
exists
():
self
.
std
out
.
write
(
self
.
std
err
.
write
(
'Skipping {}, email exists'
.
format
(
line
[
'email'
])
)
continue
...
...
@@ -61,6 +78,7 @@ class Command(BaseCommand):
else
:
full_name
=
line
[
'first_name'
]
if
not
options
[
'check'
]:
User
.
objects
.
create
(
username
=
line
[
'username'
],
first_name
=
full_name
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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