Exemplo n.º 1
0
    def add(self, unit, target, request):
        '''
        Creates new suggestion for this unit.
        '''

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

        # Create the suggestion
        suggestion = self.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:
            user.profile.suggested += 1
            user.profile.save()
Exemplo n.º 2
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')
Exemplo n.º 3
0
    def add(self, unit, target, request):
        '''
        Creates new suggestion for this unit.
        '''
        from weblate.accounts.models import notify_new_suggestion

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

        # Create the suggestion
        suggestion = self.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:
            user.profile.suggested += 1
            user.profile.save()

        # Update unit flags
        for relunit in suggestion.get_related_units():
            relunit.update_has_suggestion()
Exemplo n.º 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")
Exemplo n.º 5
0
    def add(self, unit, target, request, vote=False):
        '''
        Creates new suggestion for this unit.
        '''
        user = request.user

        same = self.filter(
            target=target,
            content_hash=unit.content_hash,
            language=unit.translation.language,
            project=unit.translation.subproject.project,
        )

        if same.exists():
            return False

        # Create the suggestion
        suggestion = self.create(target=target,
                                 content_hash=unit.content_hash,
                                 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 vote:
            suggestion.add_vote(unit.translation, request, True)

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

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

        return True