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


Python Question.approved方法代码示例

本文整理汇总了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')
开发者ID:imclab,项目名称:QuestionHut,代码行数:43,代码来源:views.py


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