How to use the weblate.trans.models.change.Change function in weblate

To help you get started, we’ve selected a few weblate examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github WeblateOrg / weblate / weblate / trans / models / translation.py View on Github external
id_hash = unit.id_hash

                # Update position
                pos += 1

                # Check for possible duplicate units
                if id_hash in updated:
                    newunit = updated[id_hash]
                    self.log_warning(
                        'duplicate string to translate: %s (%s)',
                        newunit,
                        repr(newunit.source),
                    )
                    Change.objects.create(
                        unit=newunit,
                        action=Change.ACTION_DUPLICATE_STRING,
                        user=user,
                        author=user,
                    )
                    self.component.trigger_alert(
                        'DuplicateString',
                        language_code=self.language.code,
                        source=newunit.source,
                        unit_pk=newunit.pk,
                    )
                    continue

                try:
                    newunit = dbunits[id_hash]
                    is_new = False
                except KeyError:
                    newunit = Unit(translation=self, id_hash=id_hash, state=-1)
github WeblateOrg / weblate / weblate / trans / models / __init__.py View on Github external
def user_commit_pending(sender, instance, **kwargs):
    """Commit pending changes for user on account removal."""
    # All user changes
    all_changes = Change.objects.last_changes(instance).filter(user=instance)

    # Filter where project is active
    user_translation_ids = all_changes.values_list('translation', flat=True).distinct()

    # Commit changes where user is last author
    for translation in Translation.objects.filter(pk__in=user_translation_ids):
        try:
            last_author = translation.change_set.content()[0].author
        except IndexError:
            # Non content changes
            continue
        if last_author == instance:
            translation.commit_pending('user delete', None)
github WeblateOrg / weblate / weblate / trans / models / unit.py View on Github external
if not user_changes.exists():
            Change.objects.create(
                unit=self,
                action=Change.ACTION_NEW_CONTRIBUTOR,
                user=user,
                author=author,
            )

        # Action type to store
        if change_action is not None:
            action = change_action
        elif self.state == STATE_FUZZY:
            action = Change.ACTION_MARKED_EDIT
        elif self.old_unit.state >= STATE_TRANSLATED:
            if self.state == STATE_APPROVED:
                action = Change.ACTION_APPROVE
            else:
                action = Change.ACTION_CHANGE
        else:
            action = Change.ACTION_NEW

        # Create change object
        Change.objects.create(
            unit=self,
            action=action,
            user=user,
            author=author,
            target=self.target,
            old=self.old_unit.target,
        )
github WeblateOrg / weblate / weblate / trans / models / component.py View on Github external
if not kwargs:
                # Can not create without kwargs
                raise

            else:
                # Set correct state depending on template editing
                if self.template and self.edit_template:
                    kwargs['state'] = STATE_TRANSLATED
                else:
                    kwargs['state'] = STATE_READONLY

                # Create source unit
                source = self.source_translation.unit_set.create(
                    id_hash=id_hash, **kwargs
                )
                Change.objects.create(action=Change.ACTION_NEW_SOURCE, unit=source)
                self.updated_sources[id_hash] = source
        self._sources[id_hash] = source
        return source
github WeblateOrg / weblate / weblate / trans / models / translation.py View on Github external
def check_sync(self, force=False, request=None, change=None):
        """Check whether database is in sync with git and possibly updates"""

        if change is None:
            change = Change.ACTION_UPDATE
        if request is None:
            user = None
        else:
            user = request.user

        # Check if we're not already up to date
        if not self.revision:
            self.reason = 'new file'
        elif self.revision != self.get_git_blob_hash():
            self.reason = 'content changed'
        elif force:
            self.reason = 'check forced'
        else:
            self.reason = ''
            return
github WeblateOrg / weblate / weblate / trans / models / dictionary.py View on Github external
def create(self, user, **kwargs):
        """Create new dictionary object."""
        from weblate.trans.models.change import Change

        action = kwargs.pop('action', Change.ACTION_DICTIONARY_NEW)
        created = super(DictionaryManager, self).create(**kwargs)
        Change.objects.create(
            action=action, dictionary=created, user=user, target=created.target
        )
        return created
github WeblateOrg / weblate / weblate / trans / models / unit.py View on Github external
"""Create Change entry for saving unit."""
        # Notify about new contributor
        user_changes = Change.objects.filter(translation=self.translation, user=user)
        if not user_changes.exists():
            Change.objects.create(
                unit=self,
                action=Change.ACTION_NEW_CONTRIBUTOR,
                user=user,
                author=author,
            )

        # Action type to store
        if change_action is not None:
            action = change_action
        elif self.state == STATE_FUZZY:
            action = Change.ACTION_MARKED_EDIT
        elif self.old_unit.state >= STATE_TRANSLATED:
            if self.state == STATE_APPROVED:
                action = Change.ACTION_APPROVE
            else:
                action = Change.ACTION_CHANGE
        else:
            action = Change.ACTION_NEW

        # Create change object
        Change.objects.create(
            unit=self,
            action=action,
            user=user,
            author=author,
            target=self.target,
            old=self.old_unit.target,
github WeblateOrg / weblate / weblate / trans / models / translation.py View on Github external
def notify_new(self, request):
        if self.was_new:
            # Create change after flags has been updated and cache
            # invalidated, otherwise we might be sending notification
            # with outdated values
            Change.objects.create(
                translation=self,
                action=Change.ACTION_NEW_STRING,
                user=request.user if request else None,
                author=request.user if request else None,
            )
            self.was_new = False
github WeblateOrg / weblate / weblate / trans / models / unit.py View on Github external
user=user,
                author=author,
            )

        # Action type to store
        if change_action is not None:
            action = change_action
        elif self.state == STATE_FUZZY:
            action = Change.ACTION_MARKED_EDIT
        elif self.old_unit.state >= STATE_TRANSLATED:
            if self.state == STATE_APPROVED:
                action = Change.ACTION_APPROVE
            else:
                action = Change.ACTION_CHANGE
        else:
            action = Change.ACTION_NEW

        # Create change object
        Change.objects.create(
            unit=self,
            action=action,
            user=user,
            author=author,
            target=self.target,
            old=self.old_unit.target,
        )
github WeblateOrg / weblate / weblate / trans / models / suggestion.py View on Github external
# Create the suggestion
        suggestion = self.create(
            target=target,
            unit=unit,
            user=user,
            userdetails={
                'address': get_ip_address(request) if request else '',
                'agent': request.META.get('HTTP_USER_AGENT', '') if request else '',
            },
        )

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

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

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

        return True