示例#1
0
    def add(self, unit, user, lang, text):
        '''
        Adds comment to this unit.
        '''
        from trans.models.changes import Change
        from accounts.models import notify_new_comment

        new_comment = Comment.objects.create(
            user=user,
            checksum=unit.checksum,
            project=unit.translation.subproject.project,
            comment=text,
            language=lang)
        Change.objects.create(unit=unit,
                              action=Change.ACTION_COMMENT,
                              translation=unit.translation,
                              user=user)

        # Invalidate counts cache
        if lang is None:
            unit.translation.invalidate_cache('sourcecomments')
        else:
            unit.translation.invalidate_cache('targetcomments')

        # Update unit stats
        for relunit in new_comment.get_related_units():
            relunit.update_has_comment()

        # Notify subscribed users
        notify_new_comment(unit, new_comment, user,
                           unit.translation.subproject.report_source_bugs)
示例#2
0
    def test_notify_new_comment(self):
        unit = self.get_unit()
        notify_new_comment(
            unit,
            Comment.objects.create(checksum=unit.checksum,
                                   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')
示例#3
0
    def test_notify_new_comment(self):
        unit = self.get_unit()
        notify_new_comment(
            unit,
            Comment.objects.create(
                contentsum=unit.contentsum,
                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'
        )
示例#4
0
    def add(self, unit, user, lang, text):
        '''
        Adds comment to this unit.
        '''
        from trans.models.changes import Change
        from accounts.models import notify_new_comment

        new_comment = Comment.objects.create(
            user=user,
            checksum=unit.checksum,
            project=unit.translation.subproject.project,
            comment=text,
            language=lang
        )
        Change.objects.create(
            unit=unit,
            action=Change.ACTION_COMMENT,
            translation=unit.translation,
            user=user
        )

        # Invalidate counts cache
        if lang is None:
            unit.translation.invalidate_cache('sourcecomments')
        else:
            unit.translation.invalidate_cache('targetcomments')

        # Update unit stats
        for relunit in new_comment.get_related_units():
            relunit.update_has_comment()

        # Notify subscribed users
        notify_new_comment(
            unit,
            new_comment,
            user,
            unit.translation.subproject.report_source_bugs
        )
示例#5
0
文件: tests.py 项目: Marlinc/weblate
    def test_notify_new_comment_report(self):
        unit = self.get_unit()
        notify_new_comment(
            unit,
            Comment.objects.create(
                checksum=unit.checksum,
                project=unit.translation.subproject.project,
                language=None,
                comment='Foo'
            ),
            self.second_user(),
            '*****@*****.**'
        )

        # Check mail
        self.assertEqual(len(mail.outbox), 2)
        self.assertEqual(
            mail.outbox[0].subject,
            '[Weblate] New comment in Test/Test'
        )
        self.assertEqual(
            mail.outbox[1].subject,
            '[Weblate] New comment in Test/Test'
        )