Coverage for app/venv/lib/python3.14/site-packages/weblate/accounts/management/commands/dumpuserdata.py: 0%
27 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 07:15 +0000
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 07:15 +0000
1# Copyright © Michal Čihař <michal@weblate.org>
2#
3# SPDX-License-Identifier: GPL-3.0-or-later
4from __future__ import annotations
6import json
7from pathlib import Path
8from typing import TYPE_CHECKING
10from django.core.management.base import CommandError
11from django.core.serializers.json import DjangoJSONEncoder
13from weblate.accounts.models import Profile
14from weblate.utils.management.base import BaseCommand
16if TYPE_CHECKING:
17 from django.core.management.base import CommandParser
20class Command(BaseCommand):
21 help = "dumps user data to JSON file"
23 def add_arguments(self, parser: CommandParser) -> None:
24 parser.add_argument("json-file", type=Path, help="File where to export")
26 def handle(self, *args, **options) -> None:
27 data = []
29 profiles = Profile.objects.select_related("user").prefetch_related(
30 "watched", "languages", "secondary_languages"
31 )
33 for profile in profiles:
34 if not profile.user.is_active or profile.user.is_bot:
35 continue
36 data.append(profile.dump_data())
38 try:
39 with options["json-file"].open("w") as handle:
40 json.dump(data, handle, indent=2, cls=DjangoJSONEncoder)
41 except OSError as error:
42 msg = f"Could not open file: {error}"
43 raise CommandError(msg) from error