Ejemplo n.º 1
0
def notify_change(change_id):
    from weblate.trans.models import Change
    from weblate.accounts.notifications import (
        notify_merge_failure,
        notify_parse_error,
        notify_new_string,
        notify_new_contributor,
        notify_new_suggestion,
        notify_new_comment,
        notify_new_translation,
        notify_new_language,
    )
    change = Change.objects.get(pk=change_id)
    if change.action in (Change.ACTION_FAILED_MERGE,
                         Change.ACTION_FAILED_REBASE):
        notify_merge_failure(change)
    elif change.action == Change.ACTION_PARSE_ERROR:
        notify_parse_error(change)
    elif change.action == Change.ACTION_NEW_STRING:
        notify_new_string(change)
    elif change.action == Change.ACTION_NEW_CONTRIBUTOR:
        notify_new_contributor(change)
    elif change.action == Change.ACTION_SUGGESTION:
        notify_new_suggestion(change)
    elif change.action == Change.ACTION_COMMENT:
        notify_new_comment(change)
    elif change.action in Change.ACTIONS_CONTENT:
        notify_new_translation(change)
    elif change.action in (Change.ACTION_ADDED_LANGUAGE,
                           Change.ACTION_REQUESTED_LANGUAGE):
        notify_new_language(change)
Ejemplo n.º 2
0
    def test_notify_new_comment(self):
        unit = self.get_unit()
        notify_new_comment(
            unit,
            Comment.objects.create(content_hash=unit.content_hash,
                                   project=unit.translation.subproject.project,
                                   language=unit.translation.language,
                                   comment='Foo'), self.second_user(), '')

        # Check mail
        self.assertEqual(len(mail.outbox), 1)
        self.assertEqual(mail.outbox[0].subject,
                         '[Weblate] New comment in Test/Test')
Ejemplo n.º 3
0
    def add(self, unit, user, lang, text):
        """Add comment to this unit."""
        new_comment = self.create(user=user,
                                  content_hash=unit.content_hash,
                                  project=unit.translation.subproject.project,
                                  comment=text,
                                  language=lang)
        Change.objects.create(unit=unit,
                              action=Change.ACTION_COMMENT,
                              translation=unit.translation,
                              user=user,
                              author=user)

        # Notify subscribed users
        notify_new_comment(unit, new_comment, user,
                           unit.translation.subproject.report_source_bugs)
Ejemplo n.º 4
0
    def test_notify_new_comment(self, expected=1, comment='Foo'):
        unit = self.get_unit()
        change = Change(unit=unit,
                        comment=Comment.objects.create(
                            content_hash=unit.content_hash,
                            project=unit.translation.component.project,
                            comment=comment,
                        ),
                        user=self.second_user())
        notify_new_comment(change)

        # Check mail
        self.assertEqual(len(mail.outbox), expected)
        for message in mail.outbox:
            self.assertEqual(message.subject,
                             '[Weblate] New comment in Test/Test')
Ejemplo n.º 5
0
    def test_notify_new_comment(self):
        unit = self.get_unit()
        notify_new_comment(
            unit,
            Comment.objects.create(
                content_hash=unit.content_hash,
                project=unit.translation.component.project,
                language=unit.translation.language,
                comment='Foo'
            ),
            self.second_user(),
            ''
        )

        # Check mail
        self.assertEqual(len(mail.outbox), 1)
        self.assertEqual(
            mail.outbox[0].subject,
            '[Weblate] New comment in Test/Test'
        )
Ejemplo n.º 6
0
    def add(self, unit, user, lang, text):
        """Add comment to this unit."""
        new_comment = self.create(
            user=user,
            content_hash=unit.content_hash,
            project=unit.translation.subproject.project,
            comment=text,
            language=lang
        )
        Change.objects.create(
            unit=unit,
            action=Change.ACTION_COMMENT,
            translation=unit.translation,
            user=user,
            author=user
        )

        # Notify subscribed users
        notify_new_comment(
            unit,
            new_comment,
            user,
            unit.translation.subproject.report_source_bugs
        )