예제 #1
0
    def setup_data(self, is_anon, can_be_anon, is_owner, box_checked):
        """sets up data in the same order as shown in the
        truth table above

        the four positional arguments are in the same order
        """
        askbot_settings.update('ALLOW_ASK_ANONYMOUSLY', can_be_anon)
        question = self.post_question(is_anonymous=is_anon)
        if is_owner:
            editor = self.user
        else:
            editor = self.other_user
        data = {
            'tags': 'tag1 tag2',
            'text': 'ostaousohuosuh',
            'title': 'stahosetuhaoeudhuh'
        }
        if box_checked:
            data['reveal_identity'] = 'on'
        self.form = forms.EditQuestionForm(
            data,
            question=question,
            user=editor,
            revision=question.get_latest_revision(),
        )
예제 #2
0
def edit_question(request, id):
    """edit question view
    """
    question = get_object_or_404(models.Post, id=id)
    revision = question.get_latest_revision()
    revision_form = None
    try:
        request.user.assert_can_edit_question(question)
        if request.method == 'POST':
            if request.POST['select_revision'] == 'true':
                #revert-type edit - user selected previous revision
                revision_form = forms.RevisionForm(question, revision,
                                                   request.POST)
                if revision_form.is_valid():
                    # Replace with those from the selected revision
                    rev_id = revision_form.cleaned_data['revision']
                    revision = question.revisions.get(revision=rev_id)
                    form = forms.EditQuestionForm(question=question,
                                                  user=request.user,
                                                  revision=revision)
                else:
                    form = forms.EditQuestionForm(request.POST,
                                                  question=question,
                                                  user=question.user,
                                                  revision=revision)
            else:  #new content edit
                # Always check modifications against the latest revision
                form = forms.EditQuestionForm(
                    request.POST,
                    question=question,
                    revision=revision,
                    user=request.user,
                )
                revision_form = forms.RevisionForm(question, revision)
                if form.is_valid():
                    if form.has_changed():
                        if form.cleaned_data['reveal_identity']:
                            question.thread.remove_author_anonymity()

                        if 'language' in form.cleaned_data:
                            question.thread.language_code = form.cleaned_data[
                                'language']

                        is_anon_edit = form.cleaned_data['stay_anonymous']
                        is_wiki = form.cleaned_data.get('wiki', question.wiki)
                        post_privately = form.cleaned_data['post_privately']
                        suppress_email = form.cleaned_data['suppress_email']

                        user = form.get_post_user(request.user)

                        user.edit_question(
                            question=question,
                            title=form.cleaned_data['title'],
                            body_text=form.cleaned_data['text'],
                            revision_comment=form.cleaned_data['summary'],
                            tags=form.cleaned_data['tags'],
                            wiki=is_wiki,
                            edit_anonymously=is_anon_edit,
                            is_private=post_privately,
                            suppress_email=suppress_email)
                    return HttpResponseRedirect(question.get_absolute_url())
        else:
            #request type was "GET"
            revision_form = forms.RevisionForm(question, revision)
            initial = {
                'language': question.thread.language_code,
                'post_privately': question.is_private(),
                'wiki': question.wiki
            }
            form = forms.EditQuestionForm(question=question,
                                          revision=revision,
                                          user=request.user,
                                          initial=initial)

        data = {
            'page_class': 'edit-question-page',
            'active_tab': 'questions',
            'question': question,
            'revision': revision,
            'revision_form': revision_form,
            'mandatory_tags': models.tag.get_mandatory_tags(),
            'form': form,
            'tag_names': question.thread.get_tag_names(),
            'category_tree_data': askbot_settings.CATEGORY_TREE
        }
        data.update(context.get_for_tag_editor())
        return render(request, 'question_edit.html', data)

    except exceptions.PermissionDenied, e:
        request.user.message_set.create(message=unicode(e))
        return HttpResponseRedirect(question.get_absolute_url())
예제 #3
0
def edit_question(request, id):
    """edit question view
    """
    question = get_object_or_404(models.Question, id=id)
    latest_revision = question.get_latest_revision()
    revision_form = None
    try:
        request.user.assert_can_edit_question(question)
        if request.method == 'POST':
            if 'select_revision' in request.POST:
                #revert-type edit - user selected previous revision
                revision_form = forms.RevisionForm(question, latest_revision,
                                                   request.POST)
                if revision_form.is_valid():
                    # Replace with those from the selected revision
                    rev_id = revision_form.cleaned_data['revision']
                    selected_revision = models.QuestionRevision.objects.get(
                        question=question, revision=rev_id)
                    form = forms.EditQuestionForm(question=question,
                                                  user=request.user,
                                                  revision=selected_revision)
                else:
                    form = forms.EditQuestionForm(request.POST,
                                                  question=question,
                                                  user=request.user,
                                                  revision=latest_revision)
            else:  #new content edit
                # Always check modifications against the latest revision
                form = forms.EditQuestionForm(
                    request.POST,
                    question=question,
                    revision=latest_revision,
                    user=request.user,
                )
                revision_form = forms.RevisionForm(question, latest_revision)
                if form.is_valid():
                    if form.has_changed():

                        if form.cleaned_data['reveal_identity']:
                            question.remove_author_anonymity()

                        is_anon_edit = form.cleaned_data['stay_anonymous']
                        is_wiki = form.cleaned_data.get('wiki', question.wiki)
                        request.user.edit_question(
                            question=question,
                            title=form.cleaned_data['title'],
                            body_text=form.cleaned_data['text'],
                            revision_comment=form.cleaned_data['summary'],
                            tags=form.cleaned_data['tags'],
                            wiki=is_wiki,
                            edit_anonymously=is_anon_edit,
                        )
                    return HttpResponseRedirect(question.get_absolute_url())
        else:
            #request type was "GET"
            revision_form = forms.RevisionForm(question, latest_revision)
            form = forms.EditQuestionForm(question=question,
                                          revision=latest_revision,
                                          user=request.user)

        data = {
            'page_class': 'edit-question-page',
            'active_tab': 'questions',
            'question': question,
            'revision_form': revision_form,
            'form': form,
        }
        return render_into_skin('question_edit.html', data, request)

    except exceptions.PermissionDenied, e:
        request.user.message_set.create(message=unicode(e))
        return HttpResponseRedirect(question.get_absolute_url())
예제 #4
0
파일: writers.py 프로젝트: allieus/askbot3
def edit_question(request, id):
    """edit question view
    """
    question = get_object_or_404(models.Post, id=id)

    if askbot_settings.READ_ONLY_MODE_ENABLED:
        return redirect(question)

    try:
        revision = question.revisions.get(revision=0)
    except models.PostRevision.DoesNotExist:
        revision = question.get_latest_revision()

    revision_form = None

    try:
        request.user.assert_can_edit_question(question)
        if request.method == 'POST':
            if request.POST['select_revision'] == 'true':
                # revert-type edit - user selected previous revision
                revision_form = forms.RevisionForm(question, revision,
                                                   request.POST)
                if revision_form.is_valid():
                    # Replace with those from the selected revision
                    rev_id = revision_form.cleaned_data['revision']
                    revision = question.revisions.get(revision=rev_id)
                    form = forms.EditQuestionForm(question=question,
                                                  user=request.user,
                                                  revision=revision)
                else:
                    form = forms.EditQuestionForm(request.POST,
                                                  question=question,
                                                  user=question.user,
                                                  revision=revision)
            else:  # new content edit
                # Always check modifications against the latest revision
                form = forms.EditQuestionForm(request.POST,
                                              question=question,
                                              revision=revision,
                                              user=request.user)
                revision_form = forms.RevisionForm(question, revision)
                if form.is_valid():
                    if form.has_changed():

                        if form.can_edit_anonymously(
                        ) and form.cleaned_data['reveal_identity']:
                            question.thread.remove_author_anonymity()
                            question.is_anonymous = False

                        is_wiki = form.cleaned_data.get('wiki', question.wiki)
                        post_privately = form.cleaned_data['post_privately']
                        suppress_email = form.cleaned_data['suppress_email']

                        user = form.get_post_user(request.user)

                        user.edit_question(
                            question=question,
                            title=form.cleaned_data['title'],
                            body_text=form.cleaned_data['text'],
                            revision_comment=form.cleaned_data['summary'],
                            tags=form.cleaned_data['tags'],
                            wiki=is_wiki,
                            edit_anonymously=form.
                            cleaned_data['edit_anonymously'],
                            is_private=post_privately,
                            suppress_email=suppress_email,
                            ip_addr=request.META.get('REMOTE_ADDR'))

                        if 'language' in form.cleaned_data:
                            question.thread.set_language_code(
                                form.cleaned_data['language'])

                    return redirect(question)
        else:
            # request type was "GET"
            revision_form = forms.RevisionForm(question, revision)
            initial = {
                'language': question.thread.language_code,
                'post_privately': question.is_private(),
                'wiki': question.wiki
            }
            form = forms.EditQuestionForm(question=question,
                                          revision=revision,
                                          user=request.user,
                                          initial=initial)

        data = {
            'page_class': 'edit-question-page',
            'active_tab': 'questions',
            'question': question,
            'revision': revision,
            'revision_form': revision_form,
            'mandatory_tags': models.tag.get_mandatory_tags(),
            'form': form,
            'tag_names': question.thread.get_tag_names(),
            'category_tree_data': askbot_settings.CATEGORY_TREE
        }
        data.update(context.get_for_tag_editor())
        return render(request, 'question_edit.jinja', data)

    except exceptions.PermissionDenied as e:
        traceback.print_exc()
        # request.user.message_set.create(message=force_text(e))
        django_messages.info(request, force_text(e))
        return redirect(question)