Example #1
0
    def add(self, unit, target, user):
        """
        Creates new suggestion for this unit.
        """
        from accounts.models import notify_new_suggestion

        if not user.is_authenticated():
            user = None

        # Create the suggestion
        suggestion = Suggestion.objects.create(
            target=target,
            checksum=unit.checksum,
            language=unit.translation.language,
            project=unit.translation.subproject.project,
            user=user,
        )

        # Record in change
        Change.objects.create(unit=unit, action=Change.ACTION_SUGGESTION, translation=unit.translation, user=user)

        # Notify subscribed users
        notify_new_suggestion(unit, suggestion, user)

        # Update suggestion stats
        if user is not None:
            profile = user.get_profile()
            profile.suggested += 1
            profile.save()

        # Update unit flags
        for relunit in suggestion.get_related_units():
            relunit.update_has_suggestion()
Example #2
0
    def test_notify_new_suggestion(self):
        unit = self.get_unit()
        notify_new_suggestion(
            unit,
            Suggestion.objects.create(
                checksum=unit.checksum,
                project=unit.translation.subproject.project,
                language=unit.translation.language,
                target='Foo'), self.second_user())

        # Check mail
        self.assertEqual(len(mail.outbox), 1)
        self.assertEqual(mail.outbox[0].subject,
                         '[Weblate] New suggestion in Test/Test - Czech')
Example #3
0
    def add(self, unit, target, request):
        '''
        Creates new suggestion for this unit.
        '''
        from accounts.models import notify_new_suggestion

        if not request.user.is_authenticated():
            user = None
        else:
            user = request.user

        # Create the suggestion
        suggestion = Suggestion.objects.create(
            target=target,
            contentsum=unit.contentsum,
            language=unit.translation.language,
            project=unit.translation.subproject.project,
            user=user
        )

        # Record in change
        Change.objects.create(
            unit=unit,
            action=Change.ACTION_SUGGESTION,
            translation=unit.translation,
            user=user,
            author=user
        )

        # Add unit vote
        if user is not None and unit.can_vote_suggestions():
            suggestion.add_vote(
                unit.translation,
                request,
                True
            )

        # Notify subscribed users
        notify_new_suggestion(unit, suggestion, user)

        # Update suggestion stats
        if user is not None:
            profile = user.get_profile()
            profile.suggested += 1
            profile.save()

        # Update unit flags
        for relunit in suggestion.get_related_units():
            relunit.update_has_suggestion()
Example #4
0
    def test_notify_new_suggestion(self):
        unit = self.get_unit()
        notify_new_suggestion(
            unit,
            Suggestion.objects.create(
                contentsum=unit.contentsum,
                project=unit.translation.subproject.project,
                language=unit.translation.language,
                target='Foo'
            ),
            self.second_user()
        )

        # Check mail
        self.assertEqual(len(mail.outbox), 1)
        self.assertEqual(
            mail.outbox[0].subject,
            '[Weblate] New suggestion in Test/Test - Czech'
        )
Example #5
0
    def add(self, unit, target, user):
        '''
        Creates new suggestion for this unit.
        '''
        from trans.models.changes import Change
        from accounts.models import notify_new_suggestion

        if not user.is_authenticated():
            user = None

        # Create the suggestion
        suggestion = Suggestion.objects.create(
            target=target,
            checksum=unit.checksum,
            language=unit.translation.language,
            project=unit.translation.subproject.project,
            user=user)

        # Record in change
        Change.objects.create(unit=unit,
                              action=Change.ACTION_SUGGESTION,
                              translation=unit.translation,
                              user=user)

        # Notify subscribed users
        notify_new_suggestion(unit, suggestion, user)

        # Update suggestion stats
        if user is not None:
            profile = user.get_profile()
            profile.suggested += 1
            profile.save()

        # Update unit flags
        for relunit in suggestion.get_related_units():
            relunit.update_has_suggestion()