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
a86d6339
Commit
a86d6339
authored
Oct 03, 2014
by
Weblate
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/master'
parents
22c7315b
61db443e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
175 additions
and
0 deletions
+175
-0
weblate/accounts/management/commands/dumpuserdata.py
weblate/accounts/management/commands/dumpuserdata.py
+75
-0
weblate/accounts/management/commands/importuserdata.py
weblate/accounts/management/commands/importuserdata.py
+100
-0
No files found.
weblate/accounts/management/commands/dumpuserdata.py
0 → 100644
View file @
a86d6339
# -*- coding: utf-8 -*-
#
# Copyright © 2012 - 2014 Michal Čihař <michal@cihar.com>
#
# This file is part of Weblate <http://weblate.org/>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
from
django.core.management.base
import
BaseCommand
,
CommandError
from
weblate.accounts.models
import
Profile
import
json
class
Command
(
BaseCommand
):
help
=
'dumps user data to JSON file'
def
handle
(
self
,
*
args
,
**
options
):
'''
Creates default set of groups and optionally updates them and moves
users around to default group.
'''
if
len
(
args
)
!=
1
:
raise
CommandError
(
'Please specify JSON file to create!'
)
data
=
[]
fields
=
(
'language'
,
'translated'
,
'suggested'
,
'subscribe_any_translation'
,
'subscribe_new_string'
,
'subscribe_new_suggestion'
,
'subscribe_new_contributor'
,
'subscribe_new_comment'
,
'subscribe_merge_failure'
,
'subscribe_new_language'
,
)
profiles
=
Profile
.
objects
.
select_related
(
'user'
,
'subscriptions'
)
for
profile
in
profiles
.
iterator
():
if
not
profile
.
user
.
is_active
:
continue
item
=
{
'username'
:
profile
.
user
.
username
,
'subscriptions'
:
[
p
.
slug
for
p
in
profile
.
subscriptions
.
all
()
],
'languages'
:
[
l
.
code
for
l
in
profile
.
languages
.
all
()
],
'secondary_languages'
:
[
l
.
code
for
l
in
profile
.
secondary_languages
.
all
()
],
}
for
field
in
fields
:
item
[
field
]
=
getattr
(
profile
,
field
)
data
.
append
(
item
)
json
.
dump
(
data
,
open
(
args
[
0
],
'w'
),
indent
=
2
)
weblate/accounts/management/commands/importuserdata.py
0 → 100644
View file @
a86d6339
# -*- coding: utf-8 -*-
#
# Copyright © 2012 - 2014 Michal Čihař <michal@cihar.com>
#
# This file is part of Weblate <http://weblate.org/>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
from
django.core.management.base
import
BaseCommand
,
CommandError
from
django.contrib.auth.models
import
User
from
weblate.accounts.models
import
Profile
from
weblate.lang.models
import
Language
from
weblate.trans.models
import
Project
import
json
class
Command
(
BaseCommand
):
help
=
'imports userdata from JSON dump of database'
def
handle
(
self
,
*
args
,
**
options
):
'''
Creates default set of groups and optionally updates them and moves
users around to default group.
'''
if
len
(
args
)
!=
1
:
raise
CommandError
(
'Please specify JSON file to import!'
)
data
=
json
.
load
(
open
(
args
[
0
]))
fields
=
(
'subscribe_any_translation'
,
'subscribe_new_string'
,
'subscribe_new_suggestion'
,
'subscribe_new_contributor'
,
'subscribe_new_comment'
,
'subscribe_merge_failure'
,
'subscribe_new_language'
,
)
for
line
in
data
:
try
:
user
=
User
.
objects
.
get
(
username
=
line
[
'username'
])
update
=
False
try
:
profile
=
Profile
.
objects
.
get
(
user
=
user
)
if
not
profile
.
language
:
update
=
True
except
Profile
.
DoesNotExist
:
update
=
True
profile
=
Profile
.
objects
.
create
(
user
=
user
)
self
.
stdout
.
write
(
'Creating profile for {0}'
.
format
(
line
[
'username'
])
)
# Merge stats
profile
.
translated
+=
line
[
'translated'
]
profile
.
suggested
+=
line
[
'suggested'
]
# Update fields if we should
if
update
:
profile
.
language
=
line
[
'language'
]
for
lang
in
line
[
'secondary_languages'
]:
profile
.
secondary_languages
.
add
(
Language
.
objects
.
get
(
code
=
lang
)
)
for
lang
in
line
[
'languages'
]:
profile
.
languages
.
add
(
Language
.
objects
.
get
(
code
=
lang
)
)
# Add subscriptions
for
subscription
in
line
[
'subscriptions'
]:
try
:
profile
.
subscriptions
.
add
(
Project
.
objects
.
get
(
slug
=
subscription
)
)
except
Project
.
DoesNotExist
:
continue
# Subscription settings
for
field
in
fields
:
setattr
(
profile
,
field
,
line
[
field
])
profile
.
save
()
except
User
.
DoesNotExist
:
self
.
stderr
.
write
(
'User not found: {0}
\
n
'
.
format
(
line
[
'username'
])
)
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