Commit df0f4570 authored by Michal Čihař's avatar Michal Čihař

Add hook after adding new translation.

Issue #840
Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent 8ebeab8f
......@@ -440,6 +440,18 @@ information about Piwik see <http://piwik.org/>.
.. seealso:: :setting:`PIWIK_SITE_ID`
.. setting:: POST_ADD_SCRIPTS
POST_ADD_SCRIPTS
----------------
.. versionadded:: 2.3
List of scripts which are allowed as post add scripts. The script needs to be
later enabled in the :ref:`component`.
.. seealso:: :ref:`processing`
.. setting:: POST_UPDATE_SCRIPTS
POST_UPDATE_SCRIPTS
......
......@@ -217,8 +217,8 @@ Processing repository with scripts
You can customize way how Weblate manipulates with repository by set of
scripts. These include :guilabel:`Post-update script`, :guilabel:`Pre-commit
script`, :guilabel:`Post-commit script` and :guilabel:`Post-push script` and
are briefly described in :ref:`component`.
script`, :guilabel:`Post-commit script`, :guilabel:`Post-add script` and
:guilabel:`Post-push script` and are briefly described in :ref:`component`.
Their naming quite clearly tells when given script is executed. The commit
related scripts always get one parameter with full path to the translation file
......
......@@ -208,6 +208,10 @@ Post-push script
One of scripts defined in :setting:`POST_PUSH_SCRIPTS` which is executed
after push to remote repository. This can be used to generate notify external
parties about the change in repository (i.e. create pull request).
Post-add script
One of scripts defined in :setting:`POST_ADD_SCRIPTS` which is executed
when new translation has been added. This can be used to adjust additional
files in the repository when adding new translation.
Additional commit file
Additional file to include in commit, usually this one is generated by pre
commit script described above.
......
......@@ -34,6 +34,7 @@ Released on ? 2015.
* Commit pending changes on account removal.
* Add management command to change site name.
* Add option to confiugure default committer.
* Add hook after adding new translation.
weblate 2.3
-----------
......
......@@ -159,6 +159,10 @@ POST_PUSH_SCRIPTS = getvalue('POST_PUSH_SCRIPTS', ())
POST_PUSH_SCRIPT_CHOICES = [
(script, get_script_name(script)) for script in POST_PUSH_SCRIPTS
] + [('', '')]
POST_ADD_SCRIPTS = getvalue('POST_ADD_SCRIPTS', ())
POST_ADD_SCRIPT_CHOICES = [
(script, get_script_name(script)) for script in POST_ADD_SCRIPTS
] + [('', '')]
# Font for charts and widgets
TTF_PATH = getvalue('TTF_PATH', os.path.join(BASE_DIR, 'ttf'))
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('trans', '0041_auto_20150819_1457'),
]
operations = [
migrations.AddField(
model_name='subproject',
name='post_add_script',
field=models.CharField(default=b'', choices=[(b'', b'')], max_length=200, blank=True, help_text='Script to be executed after adding new translation, please check documentation for more details.', verbose_name='Post-add script'),
),
]
......@@ -39,11 +39,11 @@ from weblate.trans.models.advertisement import Advertisement
from weblate.trans.models.whiteboard import WhiteboardMessage
from weblate.trans.signals import (
vcs_post_push, vcs_post_update, vcs_pre_commit, vcs_post_commit,
user_pre_delete,
user_pre_delete, translation_post_add,
)
from weblate.trans.scripts import (
run_post_push_script, run_post_update_script, run_pre_commit_script,
run_post_commit_script,
run_post_commit_script, run_post_add_script,
)
__all__ = [
......@@ -227,6 +227,11 @@ def post_commit(sender, translation, **kwargs):
run_post_commit_script(translation.subproject, translation.get_filename())
@receiver(translation_post_add)
def post_add(sender, translation, **kwargs):
run_post_add_script(translation.subproject, translation.get_filename())
@receiver(user_pre_delete)
def user_commit_pending(sender, instance, **kwargs):
"""Commit pending changes for user on account removal."""
......
......@@ -40,7 +40,9 @@ from weblate.trans.fields import RegexField
from weblate.trans.util import (
is_repo_link, get_site_url, cleanup_repo_url, cleanup_path, report_error,
)
from weblate.trans.signals import vcs_post_push, vcs_post_update
from weblate.trans.signals import (
vcs_post_push, vcs_post_update, translation_post_add
)
from weblate.trans.vcs import RepositoryException, VCS_REGISTRY, VCS_CHOICES
from weblate.trans.models.translation import Translation
from weblate.trans.validators import (
......@@ -52,6 +54,7 @@ from weblate.lang.models import Language
from weblate.appsettings import (
PRE_COMMIT_SCRIPT_CHOICES, POST_UPDATE_SCRIPT_CHOICES,
POST_COMMIT_SCRIPT_CHOICES, POST_PUSH_SCRIPT_CHOICES,
POST_ADD_SCRIPT_CHOICES,
HIDE_REPO_CREDENTIALS,
DEFAULT_COMMITER_EMAIL, DEFAULT_COMMITER_NAME,
)
......@@ -266,6 +269,18 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
'please check documentation for more details.'
),
)
post_add_script = models.CharField(
verbose_name=ugettext_lazy('Post-add script'),
max_length=200,
default='',
blank=True,
choices=POST_ADD_SCRIPT_CHOICES,
help_text=ugettext_lazy(
'Script to be executed after adding new translation, '
'please check documentation for more details.'
),
)
locked = models.BooleanField(
verbose_name=ugettext_lazy('Locked'),
......@@ -1476,6 +1491,10 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
language_code=language.code,
commit_message='Created new translation.'
)
translation_post_add.send(
sender=self.__class__,
translation=translation
)
translation.git_commit(
request,
translation.get_author_name(request.user),
......
......@@ -57,6 +57,13 @@ def run_post_commit_script(component, filename):
run_hook(component, component.post_commit_script, filename)
def run_post_add_script(component, filename):
"""
Post add hook
"""
run_hook(component, component.post_add_script, filename)
def run_hook(component, script, *args):
"""
Generic script hook executor.
......
......@@ -25,4 +25,5 @@ vcs_post_push = Signal(providing_args=['subproject'])
vcs_post_update = Signal(providing_args=['subproject'])
vcs_pre_commit = Signal(providing_args=['translation'])
vcs_post_commit = Signal(providing_args=['translation'])
translation_post_add = Signal(providing_args=['translation'])
user_pre_delete = Signal()
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