コード例 #1
0
    def add_comment(self, user, lang, text):
        '''
        Adds comment to this unit.
        '''
        from trans.models.unitdata import Comment
        from trans.models.changes import Change
        from accounts.models import Profile, send_notification_email

        new_comment = Comment.objects.create(
            user=user,
            checksum=self.checksum,
            project=self.translation.subproject.project,
            comment=text,
            language=lang
        )
        Change.objects.create(
            unit=self,
            action=Change.ACTION_COMMENT,
            translation=self.translation,
            user=user
        )

        # Invalidate counts cache
        if lang is None:
            self.translation.invalidate_cache('sourcecomments')
        else:
            self.translation.invalidate_cache('targetcomments')

        # Update unit stats
        for unit in new_comment.get_related_units():
            unit.update_has_comment()

        # Notify subscribed users
        subscriptions = Profile.objects.subscribed_new_comment(
            self.translation.subproject.project,
            lang,
            user
        )
        for subscription in subscriptions:
            subscription.notify_new_comment(self, new_comment)

        # Notify upstream
        report_source_bugs = self.translation.subproject.report_source_bugs
        if lang is None and report_source_bugs != '':
            send_notification_email(
                'en',
                report_source_bugs,
                'new_comment',
                self.translation,
                {
                    'unit': self,
                    'comment': new_comment,
                    'subproject': self.translation.subproject,
                },
                from_email=user.email,
            )
コード例 #2
0
ファイル: pipeline.py プロジェクト: spc-12/weblate
def send_validation(strategy, code):
    '''
    Sends verification email.
    '''
    url = '%s?verification_code=%s' % (
        reverse('social:complete', args=(get_backend_name(strategy),)),
        code.code
    )

    send_notification_email(
        None,
        code.email,
        'activation',
        info=code.code,
        context={
            'url': url
        }
    )
コード例 #3
0
ファイル: subproject.py プロジェクト: camilonova/weblate
    def notify_merge_failure(self, error, status):
        '''
        Sends out notifications on merge failure.
        '''
        # Notify subscribed users about failure
        from accounts.models import Profile, send_notification_email
        subscriptions = Profile.objects.subscribed_merge_failure(
            self.project,
        )
        for subscription in subscriptions:
            subscription.notify_merge_failure(self, error, status)

        # Notify admins
        send_notification_email(
            'en',
            'ADMINS',
            'merge_failure',
            self,
            {
                'subproject': self,
                'status': status,
                'error': error,
            }
        )
コード例 #4
0
ファイル: subproject.py プロジェクト: msoftware/weblate
    def notify_merge_failure(self, error, status):
        '''
        Sends out notifications on merge failure.
        '''
        # Notify subscribed users about failure
        from accounts.models import Profile, send_notification_email
        subscriptions = Profile.objects.subscribed_merge_failure(
            self.project,
        )
        for subscription in subscriptions:
            subscription.notify_merge_failure(self, error, status)

        # Notify admins
        send_notification_email(
            'en',
            'ADMINS',
            'merge_failure',
            self,
            {
                'subproject': self,
                'status': status,
                'error': error,
            }
        )
コード例 #5
0
ファイル: edit.py プロジェクト: camilonova/weblate
def comment(request, pk):
    '''
    Adds new comment.
    '''
    obj = get_object_or_404(Unit, pk=pk)
    obj.check_acl(request)
    if request.POST.get('type', '') == 'source':
        lang = None
    else:
        lang = obj.translation.language

    form = CommentForm(request.POST)

    if form.is_valid():
        new_comment = Comment.objects.create(
            user=request.user,
            checksum=obj.checksum,
            project=obj.translation.subproject.project,
            comment=form.cleaned_data['comment'],
            language=lang
        )
        Change.objects.create(
            unit=obj,
            action=Change.ACTION_COMMENT,
            translation=obj.translation,
            user=request.user
        )

        # Invalidate counts cache
        if lang is None:
            obj.translation.invalidate_cache('sourcecomments')
        else:
            obj.translation.invalidate_cache('targetcomments')
        messages.info(request, _('Posted new comment'))
        # Notify subscribed users
        subscriptions = Profile.objects.subscribed_new_comment(
            obj.translation.subproject.project,
            lang,
            request.user
        )
        for subscription in subscriptions:
            subscription.notify_new_comment(obj, new_comment)
        # Notify upstream
        report_source_bugs = obj.translation.subproject.report_source_bugs
        if lang is None and report_source_bugs != '':
            send_notification_email(
                'en',
                report_source_bugs,
                'new_comment',
                obj.translation,
                {
                    'unit': obj,
                    'comment': new_comment,
                    'subproject': obj.translation.subproject,
                },
                from_email=request.user.email,
            )
    else:
        messages.error(request, _('Failed to add comment!'))

    return HttpResponseRedirect(obj.get_absolute_url())