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)
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')
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' )
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 )
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' )