Beispiel #1
0
def edit_comment(request, comment_id):
    comment = get_object_or_404(PageComment, id=comment_id)
    if not comment.can_edit(request.user):
        messages.error(request, _('You can not edit this comment.'))
        return http.HttpResponseRedirect(comment.get_absolute_url())
    if request.method == 'POST':
        form = CommentForm(request.POST, instance=comment)
        if form.is_valid():
            comment = form.save(commit=False)
            if 'show_preview' not in request.POST:
                comment.save()
                messages.success(request, _('Comment updated!'))
                return http.HttpResponseRedirect(comment.get_absolute_url())
        else:
            messages.error(request, _('Please correct errors below.'))
    else:
        form = CommentForm(instance=comment)
    return render_to_response('replies/comment_page.html', {
        'form': form,
        'comment': comment,
        'page_object': comment.page_object,
        'scope_object': comment.scope_object,
        'reply_to': comment.reply_to,
        'preview': ('show_preview' in request.POST),
    }, context_instance=RequestContext(request))
Beispiel #2
0
def comment_page(request, page_model, page_app_label, page_pk,
        scope_model=None, scope_app_label=None, scope_pk=None):

    page_ct_cls = get_object_or_404(ContentType, model=page_model,
        app_label=page_app_label).model_class()
    page_object = get_object_or_404(page_ct_cls, pk=page_pk)

    scope_object = None
    if scope_model:
        scope_ct_cls = get_object_or_404(ContentType, model=scope_model,
            app_label=scope_app_label).model_class()
        scope_object = get_object_or_404(scope_ct_cls, pk=scope_pk)

    can_comment = page_object.can_comment(request.user)
    if not can_comment:
        msg = _('You can not post a comment at %s.')
        messages.error(request, msg % page_object)
        return http.HttpResponseRedirect(page_object.get_absolute_url())

    kwargs = dict(page_app_label=page_app_label,
        page_model=page_model, page_pk=page_pk)
    if scope_object:
        kwargs.update(dict(scope_app_label=scope_app_label,
            scope_model=scope_model, scope_pk=scope_pk))
    new_comment_url = reverse('page_comment', kwargs=kwargs)

    user = request.user.get_profile()

    comment = None
    if request.method == 'POST':
        form = CommentForm(request.POST)
        if form.is_valid():
            comment = form.save(commit=False)
            comment.page_object = page_object
            comment.scope_object = scope_object
            comment.author = user
            if 'show_preview' not in request.POST:
                comment.save()
                messages.success(request, _('Comment posted!'))
                return http.HttpResponseRedirect(comment.get_absolute_url())
        else:
            messages.error(request, _('Please correct errors below.'))
    else:
        form = CommentForm()
    from projects.models import Project
    is_challenge = False
    if scope_object:
        is_challenge = (scope_object.category == Project.CHALLENGE)
    return render_to_response('replies/comment_page.html', {
        'form': form,
        'scope_object': scope_object,
        'page_object': page_object,
        'comment': comment,
        'create': True,
        'preview': ('show_preview' in request.POST),
        'new_comment_url': new_comment_url,
        'is_challenge': is_challenge,
    }, context_instance=RequestContext(request))
Beispiel #3
0
def reply_comment(request, comment_id):
    reply_to = get_object_or_404(PageComment, id=comment_id)
    if reply_to.deleted:
        return http.HttpResponseRedirect(reply_to.get_absolute_url())
    can_reply = reply_to.page_object.can_comment(request.user,
        reply_to=reply_to)
    can_reply = can_reply and request.user.get_profile().can_post()
    if not can_reply:
        messages.error(request, _('You can not reply to this comment.'))
        return http.HttpResponseRedirect(reply_to.get_absolute_url())
    user = request.user.get_profile()
    comment = None
    if request.method == 'POST':
        form = CommentForm(request.POST)
        if form.is_valid():
            comment = form.save(commit=False)
            comment.page_object = reply_to.page_object
            comment.scope_object = reply_to.scope_object
            comment.author = user
            comment.reply_to = reply_to
            comment.abs_reply_to = reply_to.abs_reply_to or reply_to
            if 'show_preview' not in request.POST:
                comment.save()
                comment.send_comment_notification()
                messages.success(request, _('Comment posted!'))
                return http.HttpResponseRedirect(comment.get_absolute_url())
        else:
            messages.error(request, _('Please correct errors below.'))
    else:
        form = CommentForm()

    context = {
        'form': form,
        'scope_object': reply_to.scope_object,
        'page_object': reply_to.page_object,
        'reply_to': reply_to,
        'comment': comment,
        'create': True,
        'preview': ('show_preview' in request.POST),
    }

    return render_to_response('replies/comment_page.html', context,
        context_instance=RequestContext(request))
Beispiel #4
0
def edit_comment(request, comment_id):
    comment = get_object_or_404(PageComment, id=comment_id)
    if not comment.can_edit(request.user):
        messages.error(request, _('You can not edit this comment.'))
        return http.HttpResponseRedirect(comment.get_absolute_url())
    if request.method == 'POST':
        form = CommentForm(request.POST, instance=comment)
        if form.is_valid():
            comment = form.save(commit=False)
            if 'show_preview' not in request.POST:
                comment.save()
                messages.success(request, _('Comment updated!'))
                return http.HttpResponseRedirect(comment.get_absolute_url())
        else:
            messages.error(request, _('Please correct errors below.'))
    else:
        form = CommentForm(instance=comment)

    return render_to_response('replies/comment_page.html', {
        'form': form,
        'comment': comment,
        'page_object': comment.page_object,
        'scope_object': comment.scope_object,
        'reply_to': comment.reply_to,
        'preview': ('show_preview' in request.POST),
    },
                              context_instance=RequestContext(request))
Beispiel #5
0
def reply_comment(request, comment_id):
    reply_to = get_object_or_404(PageComment, id=comment_id)
    if reply_to.deleted:
        return http.HttpResponseRedirect(reply_to.get_absolute_url())
    can_reply = reply_to.page_object.can_comment(request.user,
                                                 reply_to=reply_to)
    can_reply = can_reply and request.user.get_profile().can_post()
    if not can_reply:
        messages.error(
            request,
            _('You can not reply to this comment. Please ensure that you have confirmed your email address.'
              ))
        return http.HttpResponseRedirect(reply_to.get_absolute_url())
    user = request.user.get_profile()
    comment = None
    if request.method == 'POST':
        form = CommentForm(request.POST)
        if form.is_valid():
            comment = form.save(commit=False)
            comment.page_object = reply_to.page_object
            comment.scope_object = reply_to.scope_object
            comment.author = user
            comment.reply_to = reply_to
            comment.abs_reply_to = reply_to.abs_reply_to or reply_to
            if 'show_preview' not in request.POST:
                comment.save()
                comment.send_comment_notification()
                messages.success(request, _('Comment posted!'))
                return http.HttpResponseRedirect(comment.get_absolute_url())
        else:
            messages.error(request, _('Please correct errors below.'))
    else:
        form = CommentForm()

    context = {
        'form': form,
        'scope_object': reply_to.scope_object,
        'page_object': reply_to.page_object,
        'reply_to': reply_to,
        'comment': comment,
        'create': True,
        'preview': ('show_preview' in request.POST),
    }

    return render_to_response('replies/comment_page.html',
                              context,
                              context_instance=RequestContext(request))
Beispiel #6
0
def reply_comment(request, comment_id):
    reply_to = get_object_or_404(PageComment, id=comment_id)
    if reply_to.deleted:
        return http.HttpResponseRedirect(reply_to.get_absolute_url())
    can_reply = reply_to.page_object.can_comment(request.user,
                                                 reply_to=reply_to)
    if not can_reply:
        messages.error(request, _('You can not reply to this comment.'))
        return http.HttpResponseRedirect(reply_to.get_absolute_url())
    user = request.user.get_profile()
    comment = None
    if request.method == 'POST':
        form = CommentForm(request.POST)
        if form.is_valid():
            comment = form.save(commit=False)
            comment.page_object = reply_to.page_object
            comment.scope_object = reply_to.scope_object
            comment.author = user
            comment.reply_to = reply_to
            comment.abs_reply_to = reply_to.abs_reply_to or reply_to
            if 'show_preview' not in request.POST:
                comment.save()
                messages.success(request, _('Comment posted!'))
                return http.HttpResponseRedirect(comment.get_absolute_url())
        else:
            messages.error(request, _('Please correct errors below.'))
    else:
        form = CommentForm()
    from projects.models import Project
    is_challenge = False
    if reply_to.scope_object:
        is_challenge = (reply_to.scope_object.category == Project.CHALLENGE)
    return render_to_response('replies/comment_page.html', {
        'form': form,
        'scope_object': reply_to.scope_object,
        'page_object': reply_to.page_object,
        'reply_to': reply_to,
        'comment': comment,
        'create': True,
        'preview': ('show_preview' in request.POST),
        'is_challenge': is_challenge,
    },
                              context_instance=RequestContext(request))
Beispiel #7
0
def comment_page(request,
                 page_model,
                 page_app_label,
                 page_pk,
                 scope_model=None,
                 scope_app_label=None,
                 scope_pk=None):

    page_ct_cls = get_object_or_404(ContentType,
                                    model=page_model,
                                    app_label=page_app_label).model_class()
    page_object = get_object_or_404(page_ct_cls, pk=page_pk)

    scope_object = None
    if scope_model:
        scope_ct_cls = get_object_or_404(
            ContentType, model=scope_model,
            app_label=scope_app_label).model_class()
        scope_object = get_object_or_404(scope_ct_cls, pk=scope_pk)

    can_comment = page_object.can_comment(request.user)
    can_comment = can_comment and request.user.get_profile().can_post()
    if not can_comment:
        msg = _('You can not post a comment at %s.')
        messages.error(request, msg % page_object)
        return http.HttpResponseRedirect(page_object.get_absolute_url())

    kwargs = {
        'page_app_label': page_app_label,
        'page_model': page_model,
        'page_pk': page_pk
    }
    if scope_object:
        kwargs.update({
            'scope_app_label': scope_app_label,
            'scope_model': scope_model,
            'scope_pk': scope_pk
        })

    new_comment_url = reverse('page_comment', kwargs=kwargs)
    user = request.user.get_profile()

    comment = None
    if request.method == 'POST':
        form = CommentForm(request.POST)
        if form.is_valid():
            comment = form.save(commit=False)
            comment.page_object = page_object
            comment.scope_object = scope_object
            comment.author = user
            if 'show_preview' not in request.POST:
                comment.save()
                comment.send_comment_notification()
                messages.success(request, _('Comment posted!'))
                return http.HttpResponseRedirect(comment.get_absolute_url())
        else:
            messages.error(request, _('Please correct errors below.'))
    else:
        form = CommentForm()

    return render_to_response('replies/comment_page.html', {
        'form': form,
        'scope_object': scope_object,
        'page_object': page_object,
        'comment': comment,
        'create': True,
        'preview': ('show_preview' in request.POST),
        'new_comment_url': new_comment_url,
    },
                              context_instance=RequestContext(request))