Commit 39d35f1d authored by Michal Čihař's avatar Michal Čihař

Support for automatic translation across projects

Fixes #969
Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent fbfe1005
...@@ -25,6 +25,7 @@ Released on ? 2015. ...@@ -25,6 +25,7 @@ Released on ? 2015.
* Improved support for XLIFF files. * Improved support for XLIFF files.
* Extended list of options for import_project. * Extended list of options for import_project.
* Improved targeting for whiteboard messages. * Improved targeting for whiteboard messages.
* Support for automatic translation across projects.
weblate 2.4 weblate 2.4
----------- -----------
......
...@@ -624,21 +624,30 @@ class AutoForm(forms.Form): ...@@ -624,21 +624,30 @@ class AutoForm(forms.Form):
initial='' initial=''
) )
def __init__(self, obj, *args, **kwargs): def __init__(self, obj, user, *args, **kwargs):
''' '''
Dynamically generate choices for other subproject Dynamically generate choices for other subproject
in same project in same project
''' '''
project = obj.subproject.project other_subprojects = obj.subproject.project.subproject_set.exclude(
other_subprojects = project.subproject_set.exclude(
id=obj.subproject.id id=obj.subproject.id
) )
choices = [(s.id, s.name) for s in other_subprojects] choices = [(s.id, force_text(s)) for s in other_subprojects]
# Add other owned projects
owned_projects = user.project_set.all().exclude(
pk=obj.subproject.project.id
)
for project in owned_projects:
for component in project.subproject_set.all():
choices.add(
(component.id, force_text(component))
)
super(AutoForm, self).__init__(*args, **kwargs) super(AutoForm, self).__init__(*args, **kwargs)
self.fields['subproject'].choices = \ self.fields['subproject'].choices = \
[('', _('All components'))] + choices [('', _('All components in current project'))] + choices
class WordForm(forms.Form): class WordForm(forms.Form):
......
...@@ -289,7 +289,7 @@ def show_translation(request, project, subproject, lang): ...@@ -289,7 +289,7 @@ def show_translation(request, project, subproject, lang):
# Is user allowed to do automatic translation? # Is user allowed to do automatic translation?
if can_automatic_translation(request.user, obj.subproject.project): if can_automatic_translation(request.user, obj.subproject.project):
autoform = AutoForm(obj) autoform = AutoForm(obj, request.user)
else: else:
autoform = None autoform = None
......
...@@ -606,7 +606,7 @@ def auto_translation(request, project, subproject, lang): ...@@ -606,7 +606,7 @@ def auto_translation(request, project, subproject, lang):
raise PermissionDenied() raise PermissionDenied()
translation.commit_pending(request) translation.commit_pending(request)
autoform = AutoForm(translation, request.POST) autoform = AutoForm(translation, request.user, request.POST)
change = None change = None
if not translation.subproject.locked and autoform.is_valid(): if not translation.subproject.locked and autoform.is_valid():
if autoform.cleaned_data['inconsistent']: if autoform.cleaned_data['inconsistent']:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment