本文整理汇总了Python中askbot.forms.ShowQuestionForm.full_clean方法的典型用法代码示例。如果您正苦于以下问题:Python ShowQuestionForm.full_clean方法的具体用法?Python ShowQuestionForm.full_clean怎么用?Python ShowQuestionForm.full_clean使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类askbot.forms.ShowQuestionForm
的用法示例。
在下文中一共展示了ShowQuestionForm.full_clean方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: question
# 需要导入模块: from askbot.forms import ShowQuestionForm [as 别名]
# 或者: from askbot.forms.ShowQuestionForm import full_clean [as 别名]
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'))
示例2: question
# 需要导入模块: from askbot.forms import ShowQuestionForm [as 别名]
# 或者: from askbot.forms.ShowQuestionForm import full_clean [as 别名]
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'))
示例3: question_print
# 需要导入模块: from askbot.forms import ShowQuestionForm [as 别名]
# 或者: from askbot.forms.ShowQuestionForm import full_clean [as 别名]
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'))
示例4: question
# 需要导入模块: from askbot.forms import ShowQuestionForm [as 别名]
# 或者: from askbot.forms.ShowQuestionForm import full_clean [as 别名]
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"))
示例5: question
# 需要导入模块: from askbot.forms import ShowQuestionForm [as 别名]
# 或者: from askbot.forms.ShowQuestionForm import full_clean [as 别名]
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'))
示例6: question
# 需要导入模块: from askbot.forms import ShowQuestionForm [as 别名]
# 或者: from askbot.forms.ShowQuestionForm import full_clean [as 别名]
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)
#.........这里部分代码省略.........