Skip to content

Commit

Permalink
component: support additional attributes in component duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
ParthS007 committed May 10, 2024
1 parent 55a9bd3 commit 1066285
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
9 changes: 9 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
Weblate 5.6
-----------

To be released.

**Improvements**

* :ref:`trans` Clone more settings automatically during duplication of existing component.

Weblate 5.5.4
-------------

Expand Down
1 change: 1 addition & 0 deletions weblate/templates/component.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
<li><a href="{% url 'manage-access' project=object.project.slug %}">{% trans "Users" %}</a></li>
{% endif %}
{% if user_can_edit_component %}
<li><a href="{% url 'create-component' %}#existing">{% trans "Duplicate Component" %}</li>
<li><a href="{% url 'guide' path=object.get_url_path %}">{% trans "Community localization checklist" %}</a></li>
<li><a href="{% url 'addons' path=object.get_url_path %}">{% trans "Add-ons" %}</a></li>
{% endif %}
Expand Down
10 changes: 9 additions & 1 deletion weblate/trans/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from weblate.auth.models import User
from weblate.configuration.models import Setting
from weblate.formats.models import FILE_FORMATS
from weblate.trans.models import Component, Project
from weblate.trans.models import Category, Component, Project
from weblate.utils.files import remove_tree
from weblate.vcs.models import VCS_REGISTRY

Expand Down Expand Up @@ -167,6 +167,12 @@ def create_project(self, **kwargs):
self.addCleanup(remove_tree, project.full_path, True)
return project

def create_category(self, project, **kwargs):
"""Create test category."""
return Category.objects.create(
name="Test", slug="test", project=project, **kwargs
)

def format_local_path(self, path):
"""Format path for local access to the repository."""
if sys.platform != "win32":
Expand All @@ -188,6 +194,8 @@ def _create_component(
raise SkipTest(f"File format {file_format} is not supported!")
if "project" not in kwargs:
kwargs["project"] = self.create_project()
if "category" not in kwargs:
kwargs["category"] = self.create_category(project=kwargs["project"])

repo = push = self.format_local_path(getattr(self, f"{vcs}_repo_path"))
if vcs not in VCS_REGISTRY:
Expand Down
10 changes: 10 additions & 0 deletions weblate/trans/views/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,10 +520,20 @@ def form_valid(self, form):
return self.redirect_create(
repo=component.get_repo_link_url(),
project=component.project.pk,
category=component.category.pk,
name=form.cleaned_data["name"],
slug=form.cleaned_data["slug"],
vcs=component.vcs,
source_language=component.source_language.pk,
license=component.license,
agreement=component.agreement,
merge_style=component.merge_style,
commit_message=component.commit_message,
add_message=component.add_message,
delete_message=component.delete_message,
merge_message=component.merge_message,
addon_message=component.addon_message,
pull_message=component.pull_message,
)
if self.origin == "branch":
form.instance.save()
Expand Down

0 comments on commit 1066285

Please sign in to comment.