Coverage for app/venv/lib/python3.14/site-packages/weblate/trans/models/workflow.py: 71%
19 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
5from __future__ import annotations
7from django.core.exceptions import ValidationError
8from django.db import models
9from django.utils.translation import gettext, gettext_lazy
11from weblate.lang.models import Language
12from weblate.trans.validators import validate_autoaccept
15class WorkflowSetting(models.Model):
16 project = models.ForeignKey(
17 "trans.Project", on_delete=models.deletion.CASCADE, null=True
18 )
19 language = models.ForeignKey(Language, on_delete=models.deletion.CASCADE)
21 # This should match definitions in Project
22 translation_review = models.BooleanField(
23 verbose_name=gettext_lazy("Enable reviews"),
24 default=False,
25 help_text=gettext_lazy("Requires dedicated reviewers to approve translations."),
26 )
27 # This should match definition in Component
28 enable_suggestions = models.BooleanField(
29 verbose_name=gettext_lazy("Turn on suggestions"),
30 default=True,
31 help_text=gettext_lazy("Whether to allow translation suggestions at all."),
32 )
33 # This should match definition in Component
34 suggestion_voting = models.BooleanField(
35 verbose_name=gettext_lazy("Suggestion voting"),
36 default=False,
37 help_text=gettext_lazy(
38 "Users can only vote for suggestions and can’t make direct translations."
39 ),
40 )
41 # This should match definition in Component
42 suggestion_autoaccept = models.PositiveSmallIntegerField(
43 verbose_name=gettext_lazy("Automatically accept suggestions"),
44 default=0,
45 help_text=gettext_lazy(
46 "Automatically accept suggestions with this number of votes,"
47 " use 0 to turn it off."
48 ),
49 validators=[validate_autoaccept],
50 )
52 def __str__(self) -> str:
53 return f"<WorkflowSetting {self.project}:{self.language}>"
55 def clean(self) -> None:
56 if self.suggestion_autoaccept and not self.suggestion_voting:
57 msg = gettext(
58 "Accepting suggestions automatically only works with voting turned on."
59 )
60 raise ValidationError(
61 {"suggestion_autoaccept": msg, "suggestion_voting": msg}
62 )