예제 #1
0
def add_comment(request):
    # TODO: Remove as part of bug 1361318
    return JsonResponse(
        {
            "status": False,
            "message": "Not Implemented"
        },
        status=501,
    )
    """Add a comment."""
    try:
        comment = request.POST["comment"]
        comment = bleach.clean(
            comment,
            strip=True,
            tags=settings.ALLOWED_TAGS,
            attributes=settings.ALLOWED_ATTRIBUTES,
        )
        translationId = request.POST["translationId"]
    except MultiValueDictKeyError as e:
        return JsonResponse(
            {
                "status": False,
                "message": "Bad Request: {error}".format(error=e)
            },
            status=400,
        )

    user = request.user
    translation = get_object_or_404(Translation, pk=translationId)

    c = Comment(
        author=user,
        translation=translation,
        content=comment,
    )

    c.save()

    log_action("comment:added", user, translation=translation)

    return JsonResponse({"status": True})
예제 #2
0
파일: views.py 프로젝트: w2816771/pontoon
def add_comment(request):
    """Add a comment."""
    form = forms.AddCommentsForm(request.POST)
    if not form.is_valid():
        return JsonResponse(
            {
                "status":
                False,
                "message":
                "{error}".format(error=form.errors.as_json(escape_html=True)),
            },
            status=400,
        )

    user = request.user
    comment = form.cleaned_data["comment"]
    translationId = form.cleaned_data["translation"]
    entity = get_object_or_404(Entity, pk=form.cleaned_data["entity"])
    locale = get_object_or_404(Locale, code=form.cleaned_data["locale"])
    if translationId:
        translation = get_object_or_404(Translation, pk=translationId)

    if translationId:
        c = Comment(author=user, translation=translation, content=comment)
        log_action("comment:added", user, translation=translation)
    else:
        c = Comment(author=user, entity=entity, locale=locale, content=comment)
        log_action("comment:added", user, entity=entity, locale=locale)

    c.save()

    return JsonResponse({"status": True})
예제 #3
0
def add_comment(request):
    """Add a comment."""
    form = forms.AddCommentForm(request.POST)
    if not form.is_valid():
        return JsonResponse(
            {
                "status":
                False,
                "message":
                "{error}".format(error=form.errors.as_json(escape_html=True)),
            },
            status=400,
        )

    user = request.user
    comment = form.cleaned_data["comment"]
    translationId = form.cleaned_data["translation"]
    entity = get_object_or_404(Entity, pk=form.cleaned_data["entity"])
    locale = get_object_or_404(Locale, code=form.cleaned_data["locale"])

    if translationId:
        translation = get_object_or_404(Translation, pk=translationId)
    else:
        translation = None

    # Translation comment
    if translation:
        c = Comment(author=user, translation=translation, content=comment)
        log_action(ActionLog.ActionType.COMMENT_ADDED,
                   user,
                   translation=translation)

    # Team comment
    else:
        c = Comment(author=user, entity=entity, locale=locale, content=comment)
        log_action(ActionLog.ActionType.COMMENT_ADDED,
                   user,
                   entity=entity,
                   locale=locale)

    c.save()

    _send_add_comment_notifications(user, comment, entity, locale, translation)

    return JsonResponse({"status": True})