Commit a86d6339 authored by Weblate's avatar Weblate

Merge remote-tracking branch 'origin/master'

parents 22c7315b 61db443e
# -*- 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)
# -*- 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'])
)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment