Exemplo n.º 1
0
def accept_suggestion(request, unit, suggid):
    json = {
        'udbid': unit.id,
        'sugid': suggid,
    }
    translation_project = request.translation_project

    if request.POST.get('accept'):
        try:
            suggestion = unit.suggestion_set.get(id=suggid)
        except ObjectDoesNotExist:
            raise Http404

        old_target = unit.target
        success = unit.accept_suggestion(suggid)

        json['newtargets'] = [highlight_whitespace(target)
                              for target in unit.target.strings]
        json['newdiffs'] = {}
        for sugg in unit.get_suggestions():
            json['newdiffs'][sugg.id] = \
                    [highlight_diffs(unit.target.strings[i], target)
                     for i, target in enumerate(sugg.target.strings)]

        if suggestion is not None and success:
            if suggestion.user:
                translation_submitted.send(sender=translation_project,
                                           unit=unit, profile=suggestion.user)

            # FIXME: we need a totally different model for tracking stats, this
            # is just lame
            suggstat, created = SuggestionStat.objects.get_or_create(
                    translation_project=translation_project,
                    suggester=suggestion.user,
                    state='pending',
                    unit=unit.id,
            )
            suggstat.reviewer = request.profile
            suggstat.state = 'accepted'
            suggstat.save()

            # For now assume the target changed
            # TODO: check all fields for changes
            creation_time = timezone.now()
            sub = Submission(
                    creation_time=creation_time,
                    translation_project=translation_project,
                    submitter=suggestion.user,
                    from_suggestion=suggstat,
                    unit=unit,
                    field=SubmissionFields.TARGET,
                    type=SubmissionTypes.SUGG_ACCEPT,
                    old_value=old_target,
                    new_value=unit.target,
            )
            sub.save()

    response = jsonify(json)
    return HttpResponse(response, mimetype="application/json")
Exemplo n.º 2
0
Arquivo: views.py Projeto: notz/pootle
def accept_suggestion(request, unit, suggid):
    json = {}
    translation_project = request.translation_project
    json["udbid"] = unit.id
    json["sugid"] = suggid
    if request.POST.get('accept'):
        try:
            suggestion = unit.suggestion_set.get(id=suggid)
        except ObjectDoesNotExist:
            raise Http404

        old_target = unit.target
        success = unit.accept_suggestion(suggid)
        json['newtargets'] = [
            highlight_whitespace(target) for target in unit.target.strings
        ]
        json['newdiffs'] = {}
        for sugg in unit.get_suggestions():
            json['newdiffs'][sugg.id] = [highlight_diffs(unit.target.strings[i], target) \
                                         for i, target in enumerate(sugg.target.strings)]

        if suggestion is not None and success:
            if suggestion.user:
                translation_submitted.send(sender=translation_project,
                                           unit=unit,
                                           profile=suggestion.user)
            #FIXME: we need a totally different model for tracking stats, this is just lame
            if suggestion.user != request.profile:
                suggstat, created = SuggestionStat.objects.get_or_create(
                    translation_project=translation_project,
                    suggester=suggestion.user,
                    state='pending',
                    unit=unit.id)
                suggstat.reviewer = request.profile
                suggstat.state = 'accepted'
                suggstat.save()
            else:
                suggstat = None

            # For now assume the target changed
            # TODO: check all fields for changes
            creation_time = timezone.now()
            sub = Submission(
                creation_time=creation_time,
                translation_project=translation_project,
                submitter=suggestion.user,
                from_suggestion=suggstat,
                unit=unit,
                field=SubmissionFields.TARGET,
                type=SubmissionTypes.SUGG_ACCEPT,
                old_value=old_target,
                new_value=unit.target,
            )
            sub.save()
    response = jsonify(json)
    return HttpResponse(response, mimetype="application/json")
Exemplo n.º 3
0
def accept_suggestion(request, uid, suggid):
    unit = get_object_or_404(Unit, id=uid)
    directory = unit.store.parent
    translation_project = unit.store.translation_project

    if not check_profile_permission(
        get_profile(request.user), 'review', directory):
        raise PermissionDenied

    response = {
        'udbid': unit.id,
        'sugid': suggid,
        }

    if request.POST.get('accept'):
        try:
            suggestion = unit.suggestion_set.get(id=suggid)
        except ObjectDoesNotExist:
            suggestion = None

        response['success'] = unit.accept_suggestion(suggid)
        response['newtargets'] = [
            highlight_whitespace(target) for target in unit.target.strings]
        response['newdiffs'] = {}
        for sugg in unit.get_suggestions():
            response['newdiffs'][sugg.id] = [
                highlight_diffs(unit.target.strings[i], target) \
                for i, target in enumerate(sugg.target.strings)]

        if suggestion is not None and response['success']:
            if suggestion.user:
                translation_submitted.send(
                    sender=translation_project, unit=unit,
                    profile=suggestion.user)
            # FIXME: we need a totally different model for tracking
            # stats, this is just lame
            suggstat, created = SuggestionStat.objects.get_or_create(
                translation_project=translation_project,
                suggester=suggestion.user,
                state='pending',
                unit=unit.id)
            suggstat.reviewer = get_profile(request.user)
            suggstat.state = 'accepted'
            suggstat.save()

            sub = Submission(translation_project=translation_project,
                             submitter=get_profile(request.user),
                             from_suggestion=suggstat)
            sub.save()

    response = simplejson.dumps(response)
    return HttpResponse(response, mimetype="application/json")
Exemplo n.º 4
0
def accept_suggestion(request, uid, suggid):
    unit = get_object_or_404(Unit, id=uid)
    directory = unit.store.parent
    translation_project = unit.store.translation_project

    if not check_profile_permission(get_profile(request.user), 'review',
                                    directory):
        raise PermissionDenied

    response = {
        'udbid': unit.id,
        'sugid': suggid,
    }

    if request.POST.get('accept'):
        try:
            suggestion = unit.suggestion_set.get(id=suggid)
        except ObjectDoesNotExist:
            suggestion = None

        response['success'] = unit.accept_suggestion(suggid)
        response['newtargets'] = [
            highlight_whitespace(target) for target in unit.target.strings
        ]
        response['newdiffs'] = {}
        for sugg in unit.get_suggestions():
            response['newdiffs'][sugg.id] = [highlight_diffs(unit.target.strings[i], target) \
                                             for i, target in enumerate(sugg.target.strings)]

        if suggestion is not None and response['success']:
            if suggestion.user:
                translation_submitted.send(sender=translation_project,
                                           unit=unit,
                                           profile=suggestion.user)
            #FIXME: we need a totally different model for tracking stats, this is just lame
            suggstat, created = SuggestionStat.objects.get_or_create(
                translation_project=translation_project,
                suggester=suggestion.user,
                state='pending',
                unit=unit.id)
            suggstat.reviewer = get_profile(request.user)
            suggstat.state = 'accepted'
            suggstat.save()

            sub = Submission(translation_project=translation_project,
                             submitter=get_profile(request.user),
                             from_suggestion=suggstat)
            sub.save()

    response = simplejson.dumps(response)
    return HttpResponse(response, mimetype="application/json")
Exemplo n.º 5
0
def accept_suggestion(request, uid, suggid):
    json = {}
    try:
        unit = Unit.objects.get(id=uid)
        directory = unit.store.parent
        translation_project = unit.store.translation_project
        profile = get_profile(request.user)

        if not check_profile_permission(profile, 'review', directory):
            json["success"] = False
            json["msg"] = _("You do not have rights to access review mode.")
        else:
            json["udbid"] = unit.id
            json["sugid"] = suggid
            if request.POST.get('accept'):
                try:
                    sugg = unit.suggestion_set.get(id=suggid)
                except ObjectDoesNotExist:
                    sugg = None

                json['success'] = unit.accept_suggestion(suggid)
                json['newtargets'] = [
                    highlight_whitespace(target)
                    for target in unit.target.strings
                ]
                json['newdiffs'] = {}
                for sugg in unit.get_suggestions():
                    json['newdiffs'][sugg.id] = [highlight_diffs(unit.target.strings[i], target) \
                                                     for i, target in enumerate(sugg.target.strings)]

                if sugg is not None and json['success']:
                    #FIXME: we need a totally different model for tracking stats, this is just lame
                    suggstat, created = SuggestionStat.objects.get_or_create(
                        translation_project=translation_project,
                        suggester=sugg.user,
                        state='pending',
                        unit=unit.id)
                    suggstat.reviewer = profile
                    suggstat.state = 'accepted'
                    suggstat.save()

                    sub = Submission(translation_project=translation_project,
                                     submitter=profile,
                                     from_suggestion=suggstat)
                    sub.save()
    except Unit.DoesNotExist:
        json["success"] = False
        json["msg"] = _("Unit %(uid)s does not exist." % {'uid': uid})

    response = simplejson.dumps(json)
    return HttpResponse(response, mimetype="application/json")
Exemplo n.º 6
0
def accept_suggestion(request, uid, suggid):
    json = {}
    try:
        unit = Unit.objects.get(id=uid)
        directory = unit.store.parent
        translation_project = unit.store.translation_project
        profile = get_profile(request.user)

        if not check_profile_permission(profile, 'review', directory):
            json["success"] = False
            json["msg"] = _("You do not have rights to access review mode.")
        else:
            json["udbid"] = unit.id
            json["sugid"] = suggid
            if request.POST.get('accept'):
                try:
                    sugg = unit.suggestion_set.get(id=suggid)
                except ObjectDoesNotExist:
                    sugg = None

                json['success'] = unit.accept_suggestion(suggid)
                json['newtargets'] = [highlight_whitespace(target) for target in unit.target.strings]
                json['newdiffs'] = {}
                for sugg in unit.get_suggestions():
                    json['newdiffs'][sugg.id] = [highlight_diffs(unit.target.strings[i], target) \
                                                     for i, target in enumerate(sugg.target.strings)]

                if sugg is not None and json['success']:
                    #FIXME: we need a totally different model for tracking stats, this is just lame
                    suggstat, created = SuggestionStat.objects.get_or_create(translation_project=translation_project,
                                                                    suggester=sugg.user,
                                                                    state='pending',
                                                                    unit=unit.id)
                    suggstat.reviewer = profile
                    suggstat.state = 'accepted'
                    suggstat.save()

                    sub = Submission(translation_project=translation_project,
                                     submitter=profile,
                                     from_suggestion=suggstat)
                    sub.save()
    except Unit.DoesNotExist:
        json["success"] = False
        json["msg"] = _("Unit %(uid)s does not exist." %
                        {'uid': uid})

    response = simplejson.dumps(json)
    return HttpResponse(response, mimetype="application/json")
Exemplo n.º 7
0
def accept_suggestion(request, unit, suggid):
    json = {}
    translation_project = request.translation_project
    json["udbid"] = unit.id
    json["sugid"] = suggid
    if request.POST.get('accept'):
        try:
            suggestion = unit.suggestion_set.get(id=suggid)
        except ObjectDoesNotExist:
            raise Http404

        success = unit.accept_suggestion(suggid)
        json['newtargets'] = [highlight_whitespace(target) for target in unit.target.strings]
        json['newdiffs'] = {}
        for sugg in unit.get_suggestions():
            json['newdiffs'][sugg.id] = [highlight_diffs(unit.target.strings[i], target) \
                                         for i, target in enumerate(sugg.target.strings)]

        if suggestion is not None and success:
            if suggestion.user:
                translation_submitted.send(sender=translation_project, unit=unit, profile=suggestion.user)
            #FIXME: we need a totally different model for tracking stats, this is just lame
            if suggestion.user != request.profile:
                suggstat, created = SuggestionStat.objects.get_or_create(translation_project=translation_project,
                                                                     suggester=suggestion.user,
                                                                     state='pending',
                                                                     unit=unit.id)
                suggstat.reviewer = request.profile
                suggstat.state = 'accepted'
                suggstat.save()
            else:
                suggstat = None
            sub = Submission(translation_project=translation_project,
                             submitter=suggestion.user,
                             from_suggestion=suggstat)
            sub.save()
    response = jsonify(json)
    return HttpResponse(response, mimetype="application/json")