How to use the weblate.trans.models.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 / accounts / notifications.py View on Github external
if change:
            context['language'] = Language.objects.get(code=change.details['language'])
            context['was_added'] = change.action == Change.ACTION_ADDED_LANGUAGE
        return context


@register_notification
class NewComponentNotificaton(Notification):
    actions = (Change.ACTION_CREATE_COMPONENT,)
    verbose = _('New translation component')
    template_name = 'new_component'


@register_notification
class NewWhiteboardMessageNotificaton(Notification):
    actions = (Change.ACTION_MESSAGE,)
    verbose = _('New whiteboard message')
    template_name = 'new_whiteboard'
    required_attr = 'whiteboard'


@register_notification
class NewAlertNotificaton(Notification):
    actions = (Change.ACTION_ALERT,)
    verbose = _('New alert')
    template_name = 'new_alert'
    required_attr = 'alert'

    def should_skip(self, user, change):
        if not change.component.linked_component or not change.alert.obj.link_wide:
            return False
        fake = copy(change)
github WeblateOrg / weblate / weblate / trans / views / js.py View on Github external
if not request.user.has_perm('meta:vcs.status', obj):
        raise PermissionDenied()

    statuses = [
        (force_text(component), component.repository.status)
        for component in obj.all_repo_components()
    ]

    return render(
        request,
        'js/git-status.html',
        {
            'object': obj,
            'project': obj,
            'changes': Change.objects.filter(
                component__project=obj,
                action__in=Change.ACTIONS_REPOSITORY,
            ).order()[:10],
            'statuses': statuses,
            'component': None,
        }
github WeblateOrg / weblate / weblate / billing / models.py View on Github external
def count_changes(self, interval):
        return Change.objects.filter(
            component__project__in=self.projects.all(),
            timestamp__gt=timezone.now() - interval,
        ).count()
github WeblateOrg / weblate / weblate / trans / views / js.py View on Github external
if not request.user.has_perm('meta:vcs.status', obj):
        raise PermissionDenied()

    target = obj
    if target.is_repo_link:
        target = target.linked_component

    return render(
        request,
        'js/git-status.html',
        {
            'object': obj,
            'project': obj.project,
            'changes': Change.objects.filter(
                action__in=Change.ACTIONS_REPOSITORY,
                component=target,
            ).order()[:10],
            'statuses': [(None, obj.repository.status)],
            'component': obj,
        }
github WeblateOrg / weblate / weblate / accounts / notifications.py View on Github external
def notify_daily(self):
        self.notify_digest(FREQ_DAILY, self.filter_changes(days=1))

    def notify_weekly(self):
        self.notify_digest(FREQ_WEEKLY, self.filter_changes(weeks=1))

    def notify_monthly(self):
        self.notify_digest(FREQ_MONTHLY, self.filter_changes(months=1))


@register_notification
class MergeFailureNotification(Notification):
    actions = (
        Change.ACTION_FAILED_MERGE,
        Change.ACTION_FAILED_REBASE,
        Change.ACTION_FAILED_PUSH,
    )
    verbose = _('Repository failure')
    template_name = 'repository_error'
    fake_notify = None

    def should_skip(self, user, change):
        fake = copy(change)
        fake.action = Change.ACTION_ALERT
        fake.alert = Alert()
        if self.fake_notify is None:
            self.fake_notify = NewAlertNotificaton(None, self.perm_cache)
        return bool(
            list(self.fake_notify.get_users(FREQ_INSTANT, fake, users=[user.pk]))
        )
github WeblateOrg / weblate / weblate / trans / forms.py View on Github external
def clean(self):
        super(RevertForm, self).clean()
        if 'unit' not in self.cleaned_data or 'revert' not in self.cleaned_data:
            return None
        try:
            self.cleaned_data['revert_change'] = Change.objects.get(
                pk=self.cleaned_data['revert'], unit=self.cleaned_data['unit']
            )
        except Change.DoesNotExist:
            raise ValidationError(_('Could not find reverted change.'))
        return self.cleaned_data
github WeblateOrg / weblate / weblate / accounts / tasks.py View on Github external
def notify_change(change_id, change_name=''):
    from weblate.trans.models import Change
    from weblate.accounts.notifications import NOTIFICATIONS_ACTIONS

    change = Change.objects.get(pk=change_id)
    perm_cache = {}
    if change.action in NOTIFICATIONS_ACTIONS:
        outgoing = []
        for notification_cls in NOTIFICATIONS_ACTIONS[change.action]:
            notification = notification_cls(outgoing, perm_cache)
            notification.notify_immediate(change)
        if outgoing:
            send_mails.delay(outgoing)
github WeblateOrg / weblate / weblate / trans / models.py View on Github external
def get_last_change(self):
        '''
        Returns date of last change done in Weblate.
        '''
        try:
            change = Change.objects.content().filter(translation=self)[0]
            return change.timestamp
        except IndexError:
            return None
github WeblateOrg / weblate / weblate / trans / tasks.py View on Github external
def project_removal(pk, uid):
    user = User.objects.get(pk=uid)
    try:
        obj = Project.objects.get(pk=pk)
        Change.objects.create(
            action=Change.ACTION_REMOVE_PROJECT, target=obj.slug, user=user, author=user
        )
        obj.delete()
    except Project.DoesNotExist:
        return
github WeblateOrg / weblate / weblate / accounts / notifications.py View on Github external
Change.ACTION_MERGE,
    )
    verbose = _('Repository operation')
    template_name = 'repository_operation'


@register_notification
class ParseErrorNotification(Notification):
    actions = (Change.ACTION_PARSE_ERROR,)
    verbose = _('Parse error')
    template_name = 'parse_error'


@register_notification
class NewStringNotificaton(Notification):
    actions = (Change.ACTION_NEW_STRING,)
    verbose = _('New string')
    template_name = 'new_string'
    filter_languages = True


@register_notification
class NewContributorNotificaton(Notification):
    actions = (Change.ACTION_NEW_CONTRIBUTOR,)
    verbose = _('New contributor')
    template_name = 'new_contributor'
    filter_languages = True


@register_notification
class NewSuggestionNotificaton(Notification):
    actions = (Change.ACTION_SUGGESTION,)