Exemplo n.º 1
0
def _edit_question(request,
                   question,
                   template='question_edit.html',
                   summary='',
                   action_class=ReviseAction,
                   allow_rollback=True,
                   url_getter=lambda q: q.get_absolute_url()):
    if request.method == 'POST':
        revision_form = RevisionForm(question, data=request.POST)
        revision_form.is_valid()
        revision = question.revisions.get(
            revision=revision_form.cleaned_data['revision'])

        if 'select_revision' in request.POST:
            form = EditQuestionForm(question, request.user, revision)
        else:
            form = EditQuestionForm(question,
                                    request.user,
                                    revision,
                                    data=request.POST)

        if not 'select_revision' in request.POST and form.is_valid():
            if form.has_changed():
                action = action_class(user=request.user,
                                      node=question,
                                      ip=request.META['REMOTE_ADDR']).save(
                                          data=form.cleaned_data)

                if settings.WIKI_ON:
                    if request.POST.get('wiki',
                                        False) and not question.nis.wiki:
                        question.nstate.wiki = action
                    elif question.nis.wiki and (not request.POST.get(
                            'wiki',
                            False)) and request.user.can_cancel_wiki(question):
                        question.nstate.wiki = None
            else:
                if not revision == question.active_revision:
                    if allow_rollback:
                        RollbackAction(
                            user=request.user,
                            node=question).save(data=dict(activate=revision))
                    else:
                        pass

            return HttpResponseRedirect(url_getter(question))
    else:
        revision_form = RevisionForm(question)
        form = EditQuestionForm(question,
                                request.user,
                                initial={'summary': summary})

    return render_to_response(template, {
        'question': question,
        'revision_form': revision_form,
        'form': form,
    },
                              context_instance=RequestContext(request))
Exemplo n.º 2
0
def edit_answer(request, id):
    answer = get_object_or_404(Answer, id=id)
    if answer.deleted and not request.user.can_view_deleted_post(answer):
        raise Http404
    elif not request.user.can_edit_post(answer):
        raise Http404

    from forum.models import CustomBadge
    if CustomBadge.is_response_restricted(request.user, answer.parent):
        raise Http404

    if request.method == "POST":
        revision_form = RevisionForm(answer, data=request.POST)
        revision_form.is_valid()
        revision = answer.revisions.get(
            revision=revision_form.cleaned_data['revision'])

        if 'select_revision' in request.POST:
            form = EditAnswerForm(answer, request.user, revision)
        else:
            form = EditAnswerForm(answer,
                                  request.user,
                                  revision,
                                  data=request.POST)

        if not 'select_revision' in request.POST and form.is_valid():
            if form.has_changed():
                action = ReviseAction(user=request.user,
                                      node=answer,
                                      ip=request.META['REMOTE_ADDR']).save(
                                          data=form.cleaned_data)

                if settings.WIKI_ON:
                    if request.POST.get('wiki', False) and not answer.nis.wiki:
                        answer.nstate.wiki = action
                    elif answer.nis.wiki and (not request.POST.get(
                            'wiki',
                            False)) and request.user.can_cancel_wiki(answer):
                        answer.nstate.wiki = None
            else:
                if not revision == answer.active_revision:
                    RollbackAction(user=request.user,
                                   node=answer,
                                   ip=request.META['REMOTE_ADDR']).save(
                                       data=dict(activate=revision))

            return HttpResponseRedirect(answer.get_absolute_url())

    else:
        revision_form = RevisionForm(answer)
        form = EditAnswerForm(answer, request.user)
    return render_to_response('answer_edit.html', {
        'answer': answer,
        'revision_form': revision_form,
        'form': form,
    },
                              context_instance=RequestContext(request))
Exemplo n.º 3
0
def _edit_question(request, question):
    if request.method == 'POST':
        revision_form = RevisionForm(question, data=request.POST)
        revision_form.is_valid()
        revision = question.revisions.get(
            revision=revision_form.cleaned_data['revision'])

        if 'select_revision' in request.POST:
            form = EditQuestionForm(question, request.user, revision)
        else:
            form = EditQuestionForm(question,
                                    request.user,
                                    revision,
                                    data=request.POST)

        if not 'select_revision' in request.POST and form.is_valid():
            if form.has_changed():
                action = ReviseAction(user=request.user,
                                      node=question,
                                      ip=request.META['REMOTE_ADDR']).save(
                                          data=form.cleaned_data)

                if settings.WIKI_ON:
                    if request.POST.get('wiki',
                                        False) and not question.nis.wiki:
                        question.nstate.wiki = action
                    elif question.nis.wiki and (not request.POST.get(
                            'wiki',
                            False)) and request.user.can_cancel_wiki(question):
                        question.nstate.wiki = None
            else:
                if not revision == question.active_revision:
                    RollbackAction(
                        user=request.user,
                        node=question).save(data=dict(activate=revision))

            return HttpResponseRedirect(question.get_absolute_url())
    else:
        revision_form = RevisionForm(question)
        form = EditQuestionForm(question, request.user)

    return render_to_response(
        'question_edit.html',
        {
            'question': question,
            'revision_form': revision_form,
            'form': form,
            #'tags' : _get_tags_cache_json()
        },
        context_instance=RequestContext(request))