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

mixins: reuse url path for full_slug #9753

Merged
merged 1 commit into from
Aug 16, 2023
Merged
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
18 changes: 10 additions & 8 deletions weblate/trans/mixins.py
Original file line number Diff line number Diff line change
@@ -14,23 +14,25 @@
from weblate.utils.data import data_dir


class URLMixin:
"""Mixin for models providing standard shortcut API for few standard URLs."""

class BaseURLMixin:
def get_url_path(self):
raise NotImplementedError

@cached_property
def full_slug(self):
return "/".join(self.get_url_path())


class URLMixin(BaseURLMixin):
"""Mixin for models providing standard shortcut API for few standard URLs."""

def get_absolute_url(self):
return reverse("show", kwargs={"path": self.get_url_path()})


class LoggerMixin:
class LoggerMixin(BaseURLMixin):
"""Mixin for models with logging."""

@cached_property
def full_slug(self):
return self.slug

def log_hook(self, level, msg, *args):
return

4 changes: 0 additions & 4 deletions weblate/trans/models/component.py
Original file line number Diff line number Diff line change
@@ -1149,10 +1149,6 @@ def append(text: str | None):
regex = "".join(result)
return re.compile(f"^{regex}$")

@cached_property
def full_slug(self):
return f"{self.project.slug}/{self.slug}"

def get_url_path(self):
return (*self.project.get_url_path(), self.slug)

6 changes: 0 additions & 6 deletions weblate/trans/models/translation.py
Original file line number Diff line number Diff line change
@@ -159,12 +159,6 @@ def __init__(self, *args, **kwargs):
self._invalidate_scheduled = False
self.update_changes = []

@cached_property
def full_slug(self):
return (
f"{self.component.project.slug}/{self.component.slug}/{self.language.code}"
)

@property
def code(self):
return self.language.code
11 changes: 0 additions & 11 deletions weblate/trans/models/unit.py
Original file line number Diff line number Diff line change
@@ -503,17 +503,6 @@ def has_comment(self):
def has_suggestion(self):
return bool(self.suggestions)

@cached_property
def full_slug(self):
return "/".join(
(
self.translation.component.project.slug,
self.translation.component.slug,
self.translation.language.code,
str(self.pk),
)
)

def source_unit_save(self):
# Run checks, update state and priority if flags changed
# or running bulk edit
2 changes: 1 addition & 1 deletion weblate/trans/tests/test_manage.py
Original file line number Diff line number Diff line change
@@ -56,7 +56,7 @@ def test_project_language(self):
self.assertContains(
response, "The slug does not match the one marked for deletion!"
)
response = self.client.post(url, {"confirm": "test/cs"}, follow=True)
response = self.client.post(url, {"confirm": "test/-/cs"}, follow=True)
self.assertContains(response, "A language in the project was removed.")
self.assertEqual(Translation.objects.count(), 3)

7 changes: 2 additions & 5 deletions weblate/utils/stats.py
Original file line number Diff line number Diff line change
@@ -23,6 +23,7 @@
from weblate.checks.models import CHECKS
from weblate.lang.models import Language
from weblate.trans.filter import get_filter_choice
from weblate.trans.mixins import BaseURLMixin
from weblate.trans.util import translation_percent
from weblate.utils.db import conditional_sum
from weblate.utils.state import (
@@ -737,7 +738,7 @@ def source_language(self):
return self.translation_set[0].component.source_language


class ProjectLanguage:
class ProjectLanguage(BaseURLMixin):
"""Wrapper class used in project-language listings and stats."""

remove_permission = "translation.delete"
@@ -754,10 +755,6 @@ def __str__(self):
def code(self):
return self.language.code

@property
def full_slug(self):
return f"{self.project.slug}/{self.language.code}"

@cached_property
def stats(self):
return ProjectLanguageStats(self)