Exemple #1
0
    def test_notify_new_contributor(self):
        unit = self.get_unit()
        notify_new_contributor(unit, self.second_user())

        # Check mail
        self.assertEqual(len(mail.outbox), 1)
        self.assertEqual(mail.outbox[0].subject,
                         '[Weblate] New contributor in Test/Test - Czech')
Exemple #2
0
    def test_notify_new_contributor(self):
        unit = self.get_unit()
        notify_new_contributor(
            unit,
            self.second_user()
        )

        # Check mail
        self.assertEqual(len(mail.outbox), 1)
        self.assertEqual(
            mail.outbox[0].subject,
            '[Weblate] New contributor in Test/Test - Czech'
        )
Exemple #3
0
    def save_backend(self, request, propagate=True, gen_change=True,
                     change_action=None, user=None):
        '''
        Stores unit to backend.
        '''
        from accounts.models import (
            notify_new_translation, notify_new_contributor
        )
        from trans.models.changes import Change

        # Update lock timestamp
        self.translation.update_lock(request)

        # Store to backend
        try:
            (saved, pounit) = self.translation.update_unit(self, request, user)
        except FileLockException:
            weblate.logger.error('failed to lock backend for %s!', self)
            messages.error(
                request,
                _(
                    'Failed to store message in the backend, '
                    'lock timeout occurred!'
                )
            )
            return False

        # Handle situation when backend did not find the message
        if pounit is None:
            weblate.logger.error('message %s disappeared!', self)
            messages.error(
                request,
                _(
                    'Message not found in backend storage, '
                    'it is probably corrupted.'
                )
            )
            # Try reloading from backend
            self.translation.update_from_blob(True)
            return False

        # Return if there was no change
        if not saved:
            # Propagate if we should
            if propagate:
                self.propagate(request, change_action)
            return False

        # Update translated flag
        self.translated = pounit.is_translated()

        # Update comments as they might have been changed (eg, fuzzy flag
        # removed)
        self.flags = pounit.get_flags()

        # Get old unit from database (for notifications)
        oldunit = Unit.objects.get(id=self.id)

        # Save updated unit to database
        self.save(backend=True)

        # Update translation stats
        old_translated = self.translation.translated
        self.translation.update_stats()

        # Notify subscribed users about new translation
        notify_new_translation(self, oldunit, request.user)

        # Update user stats
        profile = request.user.get_profile()
        profile.translated += 1
        profile.save()

        # Notify about new contributor
        user_changes = Change.objects.filter(
            translation=self.translation,
            user=request.user
        )
        if not user_changes.exists():
            notify_new_contributor(self, request.user)

        # Generate Change object for this change
        if gen_change:
            if change_action is not None:
                action = change_action
            elif oldunit.translated:
                action = Change.ACTION_CHANGE
            else:
                action = Change.ACTION_NEW
            # Create change object
            Change.objects.create(
                unit=self,
                translation=self.translation,
                action=action,
                user=request.user
            )

        # Force commiting on completing translation
        if (old_translated < self.translation.translated
                and self.translation.translated == self.translation.total):
            self.translation.commit_pending(request)
            Change.objects.create(
                translation=self.translation,
                action=Change.ACTION_COMPLETE,
                user=request.user
            )

        # Propagate to other projects
        if propagate:
            self.propagate(request, change_action)

        return True
Exemple #4
0
    def save_backend(self, request, propagate=True, gen_change=True, user=None):
        '''
        Stores unit to backend.
        '''
        from accounts.models import (
            notify_new_translation, notify_new_contributor
        )
        from trans.models.changes import Change

        # Update lock timestamp
        self.translation.update_lock(request)

        # Store to backend
        try:
            (saved, pounit) = self.translation.update_unit(self, request, user)
        except FileLockException:
            weblate.logger.error('failed to lock backend for %s!', self)
            messages.error(
                request,
                _(
                    'Failed to store message in the backend, '
                    'lock timeout occurred!'
                )
            )
            return False

        # Handle situation when backend did not find the message
        if pounit is None:
            weblate.logger.error('message %s disappeared!', self)
            messages.error(
                request,
                _(
                    'Message not found in backend storage, '
                    'it is probably corrupted.'
                )
            )
            # Try reloading from backend
            self.translation.update_from_blob(True)
            return False

        # Return if there was no change
        if not saved:
            # Propagate if we should
            if propagate:
                self.propagate(request)
            return False

        # Update translated flag
        self.translated = pounit.is_translated()

        # Update comments as they might have been changed (eg, fuzzy flag
        # removed)
        self.flags = pounit.get_flags()

        # Get old unit from database (for notifications)
        oldunit = Unit.objects.get(id=self.id)

        # Save updated unit to database
        self.save(backend=True)

        # Update translation stats
        old_translated = self.translation.translated
        self.translation.update_stats()

        # Notify subscribed users about new translation
        notify_new_translation(self, oldunit, request.user)

        # Update user stats
        profile = request.user.get_profile()
        profile.translated += 1
        profile.save()

        # Notify about new contributor
        user_changes = Change.objects.filter(
            translation=self.translation,
            user=request.user
        )
        if not user_changes.exists():
            notify_new_contributor(self, request.user)

        # Generate Change object for this change
        if gen_change:
            if oldunit.translated:
                action = Change.ACTION_CHANGE
            else:
                action = Change.ACTION_NEW
            # Create change object
            Change.objects.create(
                unit=self,
                translation=self.translation,
                action=action,
                user=request.user
            )

        # Force commiting on completing translation
        if (old_translated < self.translation.translated
                and self.translation.translated == self.translation.total):
            self.translation.commit_pending(request)
            Change.objects.create(
                translation=self.translation,
                action=Change.ACTION_COMPLETE,
                user=request.user
            )

        # Propagate to other projects
        if propagate:
            self.propagate(request)

        return True
Exemple #5
0
    def save_backend(self, request, propagate=True, gen_change=True,
                     change_action=None, user=None):
        '''
        Stores unit to backend.

        Optional user parameters defines authorship of a change.
        '''
        from accounts.models import (
            notify_new_translation, notify_new_contributor
        )
        from trans.models.changes import Change

        # Update lock timestamp
        self.translation.update_lock(request)

        # For case when authorship specified, use user from request
        if user is None:
            user = request.user

        # Store to backend
        try:
            (saved, pounit) = self.translation.update_unit(self, request, user)
        except FileLockException:
            weblate.logger.error('failed to lock backend for %s!', self)
            messages.error(
                request,
                _(
                    'Failed to store message in the backend, '
                    'lock timeout occurred!'
                )
            )
            return False

        # Handle situation when backend did not find the message
        if pounit is None:
            weblate.logger.error('message %s disappeared!', self)
            messages.error(
                request,
                _(
                    'Message not found in backend storage, '
                    'it is probably corrupted.'
                )
            )
            # Try reloading from backend
            self.translation.check_sync(True)
            return False

        # Get old unit from database (for notifications)
        oldunit = Unit.objects.get(id=self.id)

        # Return if there was no change
        # We have to explicitly check for fuzzy flag change on monolingual
        # files, where we handle it ourselves without storing to backend
        if not saved and oldunit.fuzzy == self.fuzzy:
            # Propagate if we should
            if propagate:
                self.propagate(request, change_action)
            return False

        # Update translated flag
        self.translated = pounit.is_translated()

        # Update comments as they might have been changed (eg, fuzzy flag
        # removed)
        self.flags = pounit.get_flags()

        # Save updated unit to database
        self.save(backend=True)

        # Update translation stats
        old_translated = self.translation.translated
        self.translation.update_stats()

        # Notify subscribed users about new translation
        notify_new_translation(self, oldunit, request.user)

        # Update user stats
        user.profile.translated += 1
        user.profile.save()

        # Notify about new contributor
        user_changes = Change.objects.filter(
            translation=self.translation,
            user=request.user
        )
        if not user_changes.exists():
            notify_new_contributor(self, request.user)

        # Generate Change object for this change
        if gen_change:
            self.generate_change(request, user, oldunit, change_action)

        # Force commiting on completing translation
        if (old_translated < self.translation.translated
                and self.translation.translated == self.translation.total):
            self.translation.commit_pending(request)
            Change.objects.create(
                translation=self.translation,
                action=Change.ACTION_COMPLETE,
                user=request.user,
                author=user
            )

        # Propagate to other projects
        if propagate:
            self.propagate(request, change_action)

        return True