本文整理匯總了Python中qa.models.Question.approved方法的典型用法代碼示例。如果您正苦於以下問題:Python Question.approved方法的具體用法?Python Question.approved怎麽用?Python Question.approved使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類qa.models.Question
的用法示例。
在下文中一共展示了Question.approved方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: ask_question
# 需要導入模塊: from qa.models import Question [as 別名]
# 或者: from qa.models.Question import approved [as 別名]
def ask_question(request):
if not request.user.is_authenticated():
return redirect('/')
else:
hut_slug = request.POST['hut']
hut = Course.objects.get(slug=hut_slug)
title = request.POST['title']
if len(title) == 0:
return ask(request, error='You need to enter a title.', hut_slug=hut_slug)
content = request.POST['content']
if len(content) == 0:
return ask(request, error='You need to enter some content to your question.', title=title, hut_slug=hut_slug)
tags = request.POST['tags'].strip().replace(',', '').replace('#', '').split(' ')
if len(tags) == 1 and len(tags[0]) == 0:
return ask(request, error='You need to enter some tags.', title=title, content=content, hut_slug=hut_slug)
question = Question(title=title, content=content, author=request.user, course=hut)
question.save()
question.add_tag(hut.slug)
question.add_tag(State.CURRENT_QUARTER)
question.add_follower(request.user)
for tag in tags:
question.add_tag(tag)
if hut.has_approved(request.user):
question.approved = True
question.save()
message_subscribers(hut, question, request.user)
return redirect('/question/%d' % question.id)
return redirect('/?msg=moderation')