当前位置: 首页>>代码示例>>Python>>正文


Python forms.ShowQuestionForm类代码示例

本文整理汇总了Python中askbot.forms.ShowQuestionForm的典型用法代码示例。如果您正苦于以下问题:Python ShowQuestionForm类的具体用法?Python ShowQuestionForm怎么用?Python ShowQuestionForm使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ShowQuestionForm类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: question

def question(request, id):#refactor - long subroutine. display question body, answers and comments
    """view that displays body of the question and
    all answers to it

    todo: convert this view into class
    """
    #process url parameters
    #todo: fix inheritance of sort method from questions
    #before = datetime.datetime.now()
    form = ShowQuestionForm(request.REQUEST)
    form.full_clean()#always valid
    show_answer = form.cleaned_data['show_answer']
    show_comment = form.cleaned_data['show_comment']
    show_page = form.cleaned_data['show_page']
    answer_sort_method = form.cleaned_data['answer_sort_method']

    #load question and maybe refuse showing deleted question
    #if the question does not exist - try mapping to old questions
    #and and if it is not found again - then give up
    try:
        question_post = models.Post.objects.filter(
                                post_type = 'question',
                                id = id
                            ).select_related('thread')[0]
    except IndexError:
    # Handle URL mapping - from old Q/A/C/ URLs to the new one
        try:
            question_post = models.Post.objects.filter(
                                    post_type='question',
                                    old_question_id = id
                                ).select_related('thread')[0]
        except IndexError:
            raise Http404

        if show_answer:
            try:
                old_answer = models.Post.objects.get_answers().get(old_answer_id=show_answer)
                return HttpResponseRedirect(old_answer.get_absolute_url())
            except models.Post.DoesNotExist:
                pass

        elif show_comment:
            try:
                old_comment = models.Post.objects.get_comments().get(old_comment_id=show_comment)
                return HttpResponseRedirect(old_comment.get_absolute_url())
            except models.Post.DoesNotExist:
                pass

    try:
        question_post.assert_is_visible_to(request.user)
    except exceptions.QuestionHidden, error:
        request.user.message_set.create(message = unicode(error))
        return HttpResponseRedirect(reverse('index'))
开发者ID:bsmithgall,项目名称:askpgh,代码行数:53,代码来源:readers.py

示例2: question

def question(request, id):#refactor - long subroutine. display question body, answers and comments
    """view that displays body of the question and
    all answers to it
    """
    #process url parameters
    #todo: fix inheritance of sort method from questions
    default_sort_method = request.session.get('questions_sort_method', 'votes')
    form = ShowQuestionForm(request.GET, default_sort_method)
    form.full_clean()#always valid
    show_answer = form.cleaned_data['show_answer']
    show_comment = form.cleaned_data['show_comment']
    show_page = form.cleaned_data['show_page']
    is_permalink = form.cleaned_data['is_permalink']
    answer_sort_method = form.cleaned_data['answer_sort_method']

    #resolve comment and answer permalinks
    #they go first because in theory both can be moved to another question
    #this block "returns" show_post and assigns actual comment and answer
    #to show_comment and show_answer variables
    #in the case if the permalinked items or their parents are gone - redirect
    #redirect also happens if id of the object's origin post != requested id
    show_post = None #used for permalinks
    if show_comment is not None:
        #if url calls for display of a specific comment,
        #check that comment exists, that it belongs to
        #the current question
        #if it is an answer comment and the answer is hidden -
        #redirect to the default view of the question
        #if the question is hidden - redirect to the main page
        #in addition - if url points to a comment and the comment
        #is for the answer - we need the answer object
        try:
            show_comment = models.Comment.objects.get(id = show_comment)
            if str(show_comment.get_origin_post().id) != id:
                return HttpResponseRedirect(show_comment.get_absolute_url())
            show_post = show_comment.content_object
            show_comment.assert_is_visible_to(request.user)
        except models.Comment.DoesNotExist:
            error_message = _(
                'Sorry, the comment you are looking for has been '
                'deleted and is no longer accessible'
            )
            request.user.message_set.create(message = error_message)
            return HttpResponseRedirect(reverse('question', kwargs = {'id': id}))
        except exceptions.AnswerHidden, error:
            request.user.message_set.create(message = unicode(error))
            #use reverse function here because question is not yet loaded
            return HttpResponseRedirect(reverse('question', kwargs = {'id': id}))
        except exceptions.QuestionHidden, error:
            request.user.message_set.create(message = unicode(error))
            return HttpResponseRedirect(reverse('index'))
开发者ID:rosihorrorshow,项目名称:askbot-devel,代码行数:51,代码来源:readers.py

示例3: question_print

def question_print(request, id):#refactor - long subroutine. print question body, answers and comments
    """view that displays body of the question and 
    all answers to it in print format
    """
    #todo: fix inheritance of sort method from questions
    default_sort_method = request.session.get('questions_sort_method', 'votes')
    form = ShowQuestionForm(request.GET, default_sort_method)
    form.full_clean()#always valid
    show_answer = form.cleaned_data['show_answer']
    show_comment = form.cleaned_data['show_comment']
    show_page = form.cleaned_data['show_page']
    is_permalink = form.cleaned_data['is_permalink']
    answer_sort_method = form.cleaned_data['answer_sort_method']

    #load question and maybe refuse showing deleted question
    try:
        question = get_object_or_404(models.Question, id=id)
        question.assert_is_visible_to(request.user)
    except exceptions.QuestionHidden, error:
        request.user.message_set.create(message = unicode(error))
        return HttpResponseRedirect(reverse('index'))
开发者ID:NoahY,项目名称:askbot-devel,代码行数:21,代码来源:readers.py

示例4: question

def question(request, id):  # refactor - long subroutine. display question body, answers and comments
    """view that displays body of the question and 
    all answers to it
    """
    # todo: fix inheritance of sort method from questions
    default_sort_method = request.session.get("questions_sort_method", "votes")
    form = ShowQuestionForm(request.GET, default_sort_method)
    form.full_clean()  # always valid
    show_answer = form.cleaned_data["show_answer"]
    show_comment = form.cleaned_data["show_comment"]
    show_page = form.cleaned_data["show_page"]
    is_permalink = form.cleaned_data["is_permalink"]
    answer_sort_method = form.cleaned_data["answer_sort_method"]

    # resolve comment and answer permalinks
    # they go first because in theory both can be moved to another question
    # this block "returns" show_post and assigns actual comment and answer
    # to show_comment and show_answer variables
    # in the case if the permalinked items or their parents are gone - redirect
    # redirect also happens if id of the object's origin post != requested id
    show_post = None  # used for permalinks
    if show_comment is not None:
        # comments
        try:
            show_comment = models.Comment.objects.get(id=show_comment)
            if str(show_comment.get_origin_post().id) != id:
                return HttpResponseRedirect(show_comment.get_absolute_url())
            show_post = show_comment.content_object
            show_comment.assert_is_visible_to(request.user)
        except models.Comment.DoesNotExist:
            error_message = _("Sorry, the comment you are looking for has been " "deleted and is no longer accessible")
            request.user.message_set.create(message=error_message)
            return HttpResponseRedirect(reverse("question", kwargs={"id": id}))
        except exceptions.AnswerHidden, error:
            request.user.message_set.create(message=unicode(error))
            # use reverse function here because question is not yet loaded
            return HttpResponseRedirect(reverse("question", kwargs={"id": id}))
        except exceptions.QuestionHidden, error:
            request.user.message_set.create(message=unicode(error))
            return HttpResponseRedirect(reverse("index"))
开发者ID:raags,项目名称:askbot-devel,代码行数:40,代码来源:readers.py

示例5: question

def question(request, id):#refactor - long subroutine. display question body, answers and comments
    """view that displays body of the question and
    all answers to it
    """
    #process url parameters
    #todo: fix inheritance of sort method from questions
    default_sort_method = request.session.get('questions_sort_method', 'votes')
    form = ShowQuestionForm(request.GET, default_sort_method)
    form.full_clean()#always valid
    show_answer = form.cleaned_data['show_answer']
    show_comment = form.cleaned_data['show_comment']
    show_page = form.cleaned_data['show_page']
    answer_sort_method = form.cleaned_data['answer_sort_method']

    # Handle URL mapping - from old Q/A/C/ URLs to the new one
    if not models.Post.objects.get_questions().filter(id=id).exists() and models.Post.objects.get_questions().filter(old_question_id=id).exists():
        old_question = models.Post.objects.get_questions().get(old_question_id=id)

        # If we are supposed to show a specific answer or comment, then just redirect to the new URL...
        if show_answer:
            try:
                old_answer = models.Post.objects.get_answers().get(old_answer_id=show_answer)
                return HttpResponseRedirect(old_answer.get_absolute_url())
            except models.Post.DoesNotExist:
                pass

        elif show_comment:
            try:
                old_comment = models.Post.objects.get_comments().get(old_comment_id=show_comment)
                return HttpResponseRedirect(old_comment.get_absolute_url())
            except models.Post.DoesNotExist:
                pass

        # ...otherwise just patch question.id, to make URLs like this one work: /question/123#345
        # This is because URL fragment (hash) (i.e. #345) is not passed to the server so we can't know which
        # answer user expects to see. If we made a redirect to the new question.id then that hash would be lost.
        # And if we just hack the question.id (and in question.html template /or its subtemplate/ we create anchors for both old and new id-s)
        # then everything should work as expected.
        id = old_question.id


    #resolve comment and answer permalinks
    #they go first because in theory both can be moved to another question
    #this block "returns" show_post and assigns actual comment and answer
    #to show_comment and show_answer variables
    #in the case if the permalinked items or their parents are gone - redirect
    #redirect also happens if id of the object's origin post != requested id
    show_post = None #used for permalinks
    if show_comment:
        #if url calls for display of a specific comment,
        #check that comment exists, that it belongs to
        #the current question
        #if it is an answer comment and the answer is hidden -
        #redirect to the default view of the question
        #if the question is hidden - redirect to the main page
        #in addition - if url points to a comment and the comment
        #is for the answer - we need the answer object
        try:
            show_comment = models.Post.objects.get_comments().get(id=show_comment)
        except models.Post.DoesNotExist:
            error_message = _(
                'Sorry, the comment you are looking for has been '
                'deleted and is no longer accessible'
            )
            request.user.message_set.create(message = error_message)
            return HttpResponseRedirect(reverse('question', kwargs = {'id': id}))

        if str(show_comment.thread._question_post().id) != str(id):
            return HttpResponseRedirect(show_comment.get_absolute_url())
        show_post = show_comment.parent

        try:
            show_comment.assert_is_visible_to(request.user)
        except exceptions.AnswerHidden, error:
            request.user.message_set.create(message = unicode(error))
            #use reverse function here because question is not yet loaded
            return HttpResponseRedirect(reverse('question', kwargs = {'id': id}))
        except exceptions.QuestionHidden, error:
            request.user.message_set.create(message = unicode(error))
            return HttpResponseRedirect(reverse('index'))
开发者ID:basel-shishani,项目名称:askbot-devel,代码行数:80,代码来源:readers.py

示例6: question

def question(request, id):  # refactor - long subroutine. display question body, answers and comments
    """view that displays body of the question and
    all answers to it

    TODO: convert this view into class
    """
    # process url parameters
    # TODO: fix inheritance of sort method from questions

    form = ShowQuestionForm(dict(tuple(request.POST.items()) + tuple(request.GET.items())))

    form.full_clean()  # always valid
    show_answer = form.cleaned_data['show_answer']
    show_comment = form.cleaned_data['show_comment']
    show_page = form.cleaned_data['show_page']
    answer_sort_method = form.cleaned_data['answer_sort_method']

    # load question and maybe refuse showing deleted question
    # if the question does not exist - try mapping to old questions
    # and and if it is not found again - then give up

    qs = Post.objects.filter(post_type='question').select_related('thread')

    question_post = qs.filter(id=id).first()
    if question_post is None:
        # Handle URL mapping - from old Q/A/C/ URLs to the new one
        question_post = qs.filter(old_question_id=id).first()
        if question_post is None:
            raise Http404

        if show_answer:
            try:
                old_answer = Post.objects.get_answers().get(old_answer_id=show_answer)
            except Post.DoesNotExist:
                pass
            else:
                return redirect(old_answer)

        elif show_comment:
            try:
                old_comment = Post.objects.get_comments().get(old_comment_id=show_comment)
            except Post.DoesNotExist:
                pass
            else:
                return redirect(old_comment)

    if show_comment or show_answer:
        try:
            show_post = Post.objects.get(pk=(show_comment or show_answer))
        except Post.DoesNotExist:
            # missing target post will be handled later
            pass
        else:
            if (show_comment and not show_post.is_comment()) or \
                    (show_answer and not show_post.is_answer()):
                return redirect(show_post)

    try:
        question_post.assert_is_visible_to(request.user)
    except exceptions.QuestionHidden as error:
        traceback.print_exc()
        # request.user.message_set.create(message=force_text(error))
        django_messages.info(request, force_text(error))
        return redirect('index')

    # redirect if slug in the url is wrong
    if request.path.split('/')[-2] != question_post.slug:
        logging.debug('no slug match!')
        lang = translation.get_language()
        question_url = question_post.get_absolute_url(language=lang)
        if request.GET:
            question_url += '?' + urlencode(request.GET)
        return redirect(question_url)

    # resolve comment and answer permalinks
    # they go first because in theory both can be moved to another question
    # this block "returns" show_post and assigns actual comment and answer
    # to show_comment and show_answer variables
    # in the case if the permalinked items or their parents are gone - redirect
    # redirect also happens if id of the object's origin post != requested id
    show_post = None  # used for permalinks
    if show_comment:
        # if url calls for display of a specific comment,
        # check that comment exists, that it belongs to
        # the current question
        # if it is an answer comment and the answer is hidden -
        # redirect to the default view of the question
        # if the question is hidden - redirect to the main page
        # in addition - if url points to a comment and the comment
        # is for the answer - we need the answer object
        try:
            show_comment = Post.objects.get_comments().get(id=show_comment)
        except Post.DoesNotExist as e:
            traceback.print_exc()
            error_message = _(
                'Sorry, the comment you are looking for has been '
                'deleted and is no longer accessible'
            )
            # request.user.message_set.create(message=error_message)
            django_messages.info(request, error_message)
#.........这里部分代码省略.........
开发者ID:allieus,项目名称:askbot3,代码行数:101,代码来源:readers.py


注:本文中的askbot.forms.ShowQuestionForm类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。