Example #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)
Example #2
0
    def add(self, unit, target, request, vote=False):
        """Create new suggestion for this unit."""
        user = request.user

        if unit.translated and unit.target == target:
            return False

        try:
            same = self.get(
                target=target,
                content_hash=unit.content_hash,
                language=unit.translation.language,
                project=unit.translation.component.project,
            )

            if same.user == user or not vote:
                return False
            same.add_vote(unit.translation, request, True)
            return False

        except ObjectDoesNotExist:
            pass

        # Create the suggestion
        suggestion = self.create(
            target=target,
            content_hash=unit.content_hash,
            language=unit.translation.language,
            project=unit.translation.component.project,
            user=user,
            userdetails={
                'address': get_ip_address(request),
                'agent': request.META.get('HTTP_USER_AGENT', ''),
            },
        )

        # Record in change
        for aunit in suggestion.related_units:
            Change.objects.create(unit=aunit,
                                  action=Change.ACTION_SUGGESTION,
                                  user=user,
                                  target=target,
                                  author=user)

        # Add unit vote
        if vote:
            suggestion.add_vote(unit.translation, request, True)

        # Notify subscribed users
        from weblate.accounts.notifications import notify_new_suggestion
        notify_new_suggestion(unit, suggestion, user)

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

        return True
Example #3
0
    def add(self, unit, target, request, vote=False):
        """Create 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() or (unit.target == target and not unit.fuzzy):
            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
        for aunit in suggestion.related_units:
            Change.objects.create(
                unit=aunit,
                action=Change.ACTION_SUGGESTION,
                translation=aunit.translation,
                user=user,
                target=target,
                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
Example #4
0
    def add(self, unit, target, request, vote=False):
        """Create 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.component.project,
        )

        if same.exists() or (unit.target == target and not unit.fuzzy):
            return False

        # Create the suggestion
        suggestion = self.create(
            target=target,
            content_hash=unit.content_hash,
            language=unit.translation.language,
            project=unit.translation.component.project,
            user=user
        )

        # Record in change
        for aunit in suggestion.related_units:
            Change.objects.create(
                unit=aunit,
                action=Change.ACTION_SUGGESTION,
                user=user,
                target=target,
                author=user
            )

        # Add unit vote
        if vote:
            suggestion.add_vote(
                unit.translation,
                request,
                True
            )

        # Notify subscribed users
        from weblate.accounts.notifications import notify_new_suggestion
        notify_new_suggestion(unit, suggestion, user)

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

        return True
Example #5
0
    def test_notify_new_suggestion(self):
        unit = self.get_unit()
        notify_new_suggestion(
            unit,
            Suggestion.objects.create(
                content_hash=unit.content_hash,
                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 #6
0
    def add(self, unit, target, request, vote=False):
        """Create 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() or unit.target == target:
            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,
            target=target,
            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
Example #7
0
    def test_notify_new_suggestion(self):
        unit = self.get_unit()
        notify_new_suggestion(
            unit,
            Suggestion.objects.create(
                content_hash=unit.content_hash,
                project=unit.translation.component.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 #8
0
    def add(self, unit, target, request, vote=False):
        """Create new suggestion for this unit."""
        user = request.user

        try:
            same = self.get(
                target=target,
                content_hash=unit.content_hash,
                language=unit.translation.language,
                project=unit.translation.component.project,
            )

            if same.user == user or not vote:
                return False
            else:
                same.add_vote(unit.translation, request, True)
                return False

        except ObjectDoesNotExist:
            pass

        # Create the suggestion
        suggestion = self.create(
            target=target,
            content_hash=unit.content_hash,
            language=unit.translation.language,
            project=unit.translation.component.project,
            user=user,
            userdetails={
                'address': get_ip_address(request),
                'agent': request.META.get('HTTP_USER_AGENT', ''),
            },
        )

        # Record in change
        for aunit in suggestion.related_units:
            Change.objects.create(
                unit=aunit,
                action=Change.ACTION_SUGGESTION,
                user=user,
                target=target,
                author=user
            )

        # Add unit vote
        if vote:
            suggestion.add_vote(
                unit.translation,
                request,
                True
            )

        # Notify subscribed users
        from weblate.accounts.notifications import notify_new_suggestion
        notify_new_suggestion(unit, suggestion, user)

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

        return True