Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(workflow): add string filter for languages #13521

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions weblate/trans/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2947,6 +2947,7 @@ class Meta:
"enable_suggestions",
"suggestion_voting",
"suggestion_autoaccept",
"string_filter",
]

def __init__(
Expand Down Expand Up @@ -2992,6 +2993,7 @@ def __init__(
Field("enable_suggestions"),
Field("suggestion_voting"),
Field("suggestion_autoaccept"),
Field("string_filter"),
css_id="workflow-enable-target",
),
)
Expand Down
21 changes: 21 additions & 0 deletions weblate/trans/migrations/0026_workflowsetting_string_filter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 5.0.6 on 2025-01-14 16:45

Check failure on line 1 in weblate/trans/migrations/0026_workflowsetting_string_filter.py

View workflow job for this annotation

GitHub Actions / pre-commit

Ruff (CPY001)

weblate/trans/migrations/0026_workflowsetting_string_filter.py:1:1: CPY001 Missing copyright notice at top of file

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("trans", "0025_alter_announcement_notify"),
]

operations = [
migrations.AddField(
model_name="workflowsetting",
name="string_filter",
field=models.CharField(
blank=True,
help_text="Only include strings matching the filter.",
verbose_name="Filter strings",
),
),
]
6 changes: 6 additions & 0 deletions weblate/trans/models/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ class WorkflowSetting(models.Model):
validators=[validate_autoaccept],
)

string_filter = models.CharField(
verbose_name=gettext_lazy("Filter strings"),
blank=True,
help_text=gettext_lazy("Only include strings matching the filter."),
)

def __str__(self) -> str:
return f"<WorkflowSetting {self.project}:{self.language}>"

Expand Down
5 changes: 4 additions & 1 deletion weblate/utils/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
if sort_by:
object_list, sort_by = sort_objects(object_list, sort_by)
paginator = Paginator(object_list, limit)
paginator.sort_by = sort_by

Check failure on line 152 in weblate/utils/views.py

View workflow job for this annotation

GitHub Actions / mypy

"Paginator[Any]" has no attribute "sort_by"
try:
return paginator.page(page)
except EmptyPage:
Expand Down Expand Up @@ -244,7 +244,7 @@
# First level is always project
project = get_object_or_404(Project, slug=path.pop(0))
if not skip_acl:
request.user.check_access(project)

Check failure on line 247 in weblate/utils/views.py

View workflow job for this annotation

GitHub Actions / mypy

Item "None" of "AuthenticatedHttpRequest | None" has no attribute "user"
project.acting_user = acting_user
if not path:
check_type(Project)
Expand Down Expand Up @@ -276,14 +276,14 @@
with suppress(Component.DoesNotExist):
current = current.component_set.get(slug=slug, **category_args)
if not skip_acl:
request.user.check_access_component(current)

Check failure on line 279 in weblate/utils/views.py

View workflow job for this annotation

GitHub Actions / mypy

Item "None" of "AuthenticatedHttpRequest | None" has no attribute "user"
current.acting_user = acting_user
break

# Try category
with suppress(Category.DoesNotExist):
current = current.category_set.get(slug=slug, **category_args)

Check failure on line 285 in weblate/utils/views.py

View workflow job for this annotation

GitHub Actions / mypy

Item "Component" of "Project | Category | Component" has no attribute "category_set"
current.acting_user = acting_user

Check failure on line 286 in weblate/utils/views.py

View workflow job for this annotation

GitHub Actions / mypy

Item "Category" of "Any | Category" has no attribute "acting_user"
category_args = {}
continue

Expand All @@ -302,7 +302,7 @@
msg = "No remaining supported object type"
raise UnsupportedPathObjectError(msg)

translation = get_object_or_404(current.translation_set, language__code=path.pop(0))

Check failure on line 305 in weblate/utils/views.py

View workflow job for this annotation

GitHub Actions / mypy

Item "Project" of "Project | Category | Component" has no attribute "translation_set"

Check failure on line 305 in weblate/utils/views.py

View workflow job for this annotation

GitHub Actions / mypy

Item "Category" of "Project | Category | Component" has no attribute "translation_set"
if not path:
check_type(Translation)
return translation
Expand Down Expand Up @@ -330,7 +330,10 @@

context = {"components": None, "path_object": obj}
if isinstance(obj, Translation):
unit_set = obj.unit_set.all()
if obj.workflow_settings and obj.workflow_settings.string_filter:
unit_set = obj.unit_set.search(obj.workflow_settings.string_filter)
else:
unit_set = obj.unit_set.all()
context["translation"] = obj
context["component"] = obj.component
context["project"] = obj.component.project
Expand Down Expand Up @@ -479,7 +482,7 @@
extra: dict[str, bytes] | None = None,
):
response = HttpResponse(content_type="application/zip")
with ZipFile(response, "w", strict_timestamps=False) as zipfile:

Check failure on line 485 in weblate/utils/views.py

View workflow job for this annotation

GitHub Actions / mypy

No overload variant of "ZipFile" matches argument types "HttpResponse", "str", "bool"
for filename in iter_files(filenames):
try:
zipfile.write(filename, arcname=os.path.relpath(filename, root))
Expand Down Expand Up @@ -556,7 +559,7 @@
else:
extension = ".zip"
response = zip_download(
translation.get_filename(),

Check failure on line 562 in weblate/utils/views.py

View workflow job for this annotation

GitHub Actions / mypy

Argument 1 to "zip_download" has incompatible type "str | None"; expected "str"
filenames,
translation.full_slug.replace("/", "-"),
)
Expand Down Expand Up @@ -607,6 +610,6 @@
show_form_errors(self.request, form)
return HttpResponseRedirect(self.get_success_url())

def get(self, request: AuthenticatedHttpRequest, *args, **kwargs):

Check failure on line 613 in weblate/utils/views.py

View workflow job for this annotation

GitHub Actions / mypy

Argument 1 of "get" is incompatible with supertype "ProcessFormView"; supertype defines the argument type as "HttpRequest"
"""There is no GET view here."""
return HttpResponseRedirect(self.get_success_url())
Loading