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


Python AnswerForm.is_valid方法代码示例

本文整理汇总了Python中forms.AnswerForm.is_valid方法的典型用法代码示例。如果您正苦于以下问题:Python AnswerForm.is_valid方法的具体用法?Python AnswerForm.is_valid怎么用?Python AnswerForm.is_valid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在forms.AnswerForm的用法示例。


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

示例1: question_details

# 需要导入模块: from forms import AnswerForm [as 别名]
# 或者: from forms.AnswerForm import is_valid [as 别名]
def question_details(request, id):
    try:
        question = Question.objects.get(pk=id)
    except Question.DoesNotExist:
        raise Http404
    if request.method == "POST":
        user = request.user
        if not user.is_authenticated():
            return HttpResponseRedirect('/login/')
        form = AnswerForm(request.POST)
        form.setUser(user)
        if form.is_valid():
            answer = form.save()
            question = answer.question
            url = question.get_absolute_url()
            return HttpResponseRedirect(url)
    else:
        default_data = {'question': question.id}
        form = AnswerForm(initial=default_data);
    answers = Answer.objects.filter(question=question).order_by('-added_at')
    return render(request, 'question.html', {
                  'question': question,
                  'answers': answers,
                  'form': form,
    })
开发者ID:denproger,项目名称:stepic_web_project,代码行数:27,代码来源:views_question.py

示例2: answer

# 需要导入模块: from forms import AnswerForm [as 别名]
# 或者: from forms.AnswerForm import is_valid [as 别名]
def answer(request, quest):
    if request.method == 'POST':
        form = AnswerForm(request.POST)
        form._user = request.user
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(quest.get_url())
开发者ID:bgv26,项目名称:WebTech,代码行数:9,代码来源:views.py

示例3: answer

# 需要导入模块: from forms import AnswerForm [as 别名]
# 或者: from forms.AnswerForm import is_valid [as 别名]
def answer(request, *args, **kwargs):
    quest_id = kwargs['pk']
#    print 'in answer'

    if request.method == "POST":
#        print 'post on answer'
        form = AnswerForm(request.POST)
        if request.user.is_authenticated():
            form._user=request.user
        if form.is_valid():
            form.save()
            redir_url = '/question/'+str(quest_id)+'/'
            return HttpResponseRedirect(redir_url) 
    else:
#        print 'get on answer'
        try:
            question = Question.objects.get(id=quest_id)
#            print 'from anser'
#            user = request.user
#            print user
            form=AnswerForm(initial={'question': question})
#            form = AnswerForm(initial={'question': question, 'author': user})    
            answers = question.answer_set.all()        
            ans= (answers.values('text'))
            l=[l['text'] for l in ans]
            #answers =str(answers).decode('utf8')
#               print repr(answers).decode("unicode_escape")        
        except Question.DoesNotExist:
            raise Http404
    return render(request, 'question_old.html', {'form': form, 'quest_title': question.title, 'quest_text': question.text, 'answers':l,})
开发者ID:k549at,项目名称:stepic_web_project,代码行数:32,代码来源:views.py

示例4: answer

# 需要导入模块: from forms import AnswerForm [as 别名]
# 或者: from forms.AnswerForm import is_valid [as 别名]
def answer(request):
    form = AnswerForm(request.POST)
    if form.is_valid():
        a = form.save()
        url = '/question/%s/' % a.question.pk
        return HttpResponseRedirect(url)
    return HttpResponseRedirect('/answer/')
开发者ID:ky4web,项目名称:stepic,代码行数:9,代码来源:views.py

示例5: answer

# 需要导入模块: from forms import AnswerForm [as 别名]
# 或者: from forms.AnswerForm import is_valid [as 别名]
def answer(request):
    form = AnswerForm(request.POST)
    form._user = request.user
    if form.is_valid():
        answer = form.save()
        url = answer.get_question_url()
        return HttpResponseRedirect(url)
开发者ID:SvetlanaKantola,项目名称:stepic_web_project,代码行数:9,代码来源:views.py

示例6: newanswer

# 需要导入模块: from forms import AnswerForm [as 别名]
# 或者: from forms.AnswerForm import is_valid [as 别名]
def newanswer(request):
	url = '/question/'
	if request.method == "POST":
		newanswer = AnswerForm(request.POST)
		if newanswer.is_valid():
			url = url + str(newanswer.save()) + '/'
	return HttpResponseRedirect(url) 
开发者ID:AleksStek,项目名称:stepic-web,代码行数:9,代码来源:views.py

示例7: create_answer

# 需要导入模块: from forms import AnswerForm [as 别名]
# 或者: from forms.AnswerForm import is_valid [as 别名]
def create_answer(request, article_id):
	a = Article.objects.get(id=article_id)
	
	if request.POST:
		f = AnswerForm(request.POST)
		if f.is_valid():
			c = f.save(commit=False)
			c.pub_date = timezone.now()
			c.related_article = a
			c.posted_by = request.user
			c.save()
			a.num_answers += 1
			a.answers.add(c)
			a.save()			
			
			return HttpResponseRedirect('/get/%s' % article_id)
	else:
		f = CommentForm()
	
	args = {}
	args.update(csrf(request))
	args['article'] = a
	args['form'] = f
	
	return render(request, 'add_comment.html', args)
开发者ID:Radicis,项目名称:asktag,代码行数:27,代码来源:views.py

示例8: answer

# 需要导入模块: from forms import AnswerForm [as 别名]
# 或者: from forms.AnswerForm import is_valid [as 别名]
def answer(request, id=None):
    if request.method != 'POST':
        return redirect('polling.views.question_list')

    if UserReply.objects.filter(user=request.user, question_id=id).exists():
        return redirect('polling.views.question_list')

    form = AnswerForm(request.POST, question_id=id)

    if form.is_valid() and len(form.cleaned_data['answers']) <= 7:
        UserReply.objects.create(user=request.user, question_id=id)

        key = ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(6))
        reply = Reply.objects.create(key=key, question_id=id)

        for answer_id in form.cleaned_data['answers']:
            rd_key = hashlib.sha1(str(datetime.datetime.now()) + key).hexdigest()
            ReplyData.objects.create(
                key=rd_key,
                reply=reply,
                answer_id=answer_id
            )

        success = True
    else:
        success = False

    return TemplateResponse(request, 'answer.html', locals())
开发者ID:spbelect,项目名称:spbelect-voting,代码行数:30,代码来源:views.py

示例9: answer

# 需要导入模块: from forms import AnswerForm [as 别名]
# 或者: from forms.AnswerForm import is_valid [as 别名]
def answer(request):
    form = AnswerForm(request.POST)
    if form.is_valid():
        answer = form.save(commit=False)
        answer.author = request.user
        answer.save()
        return redirect(answer.question)
开发者ID:milton14,项目名称:webStepic,代码行数:9,代码来源:views.py

示例10: add_answer

# 需要导入模块: from forms import AnswerForm [as 别名]
# 或者: from forms.AnswerForm import is_valid [as 别名]
def add_answer(request):
    if request.method == 'POST':
        form = AnswerForm(request.POST)
        form._user = request.user
        if form.is_valid():
            answer = form.save()
            return HttpResponseRedirect(answer.get_url())
    return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))
开发者ID:AbiGeuS2,项目名称:webstepicrepo2,代码行数:10,代码来源:views.py

示例11: answer_add

# 需要导入模块: from forms import AnswerForm [as 别名]
# 或者: from forms.AnswerForm import is_valid [as 别名]
def answer_add(request):
    if request.method == 'POST':
	form = AnswerForm(request.POST)
	if form.is_valid():
	    answer = form.save()
	    url = question.get_url()
	    return HttpResponseRedirect(reverse(url))
    return HttpResponseRedirect('/')
开发者ID:igorlutsenko,项目名称:stepic_web_project_6,代码行数:10,代码来源:views.py

示例12: newanswer

# 需要导入模块: from forms import AnswerForm [as 别名]
# 或者: from forms.AnswerForm import is_valid [as 别名]
def newanswer (request, *args, **kwargs):
    form = AnswerForm(request.POST)
    form.user = request.user
    if form.is_valid():
        question_id = form.save()
        return HttpResponseRedirect(reverse('question', kwargs={'question_id': question_id}))
    else:
        return question(request, **{'form' : form, 'question_id': form.get_question_id()})
开发者ID:smartybit,项目名称:stepic_webtech1,代码行数:10,代码来源:views.py

示例13: answer

# 需要导入模块: from forms import AnswerForm [as 别名]
# 或者: from forms.AnswerForm import is_valid [as 别名]
def answer(request, *args, **kwargs):
    if request.method == "POST":
        form = AnswerForm(request.POST)
        if form.is_valid():
            form.cleaned_data['author'] = request.user
            a = form.save()
            return HttpResponseRedirect(a.question.get_absolute_url())
        return render(request, "form.html", {'url':request.path, 'form':form})
开发者ID:a2151257-2,项目名称:web,代码行数:10,代码来源:views.py

示例14: post_answer_add

# 需要导入模块: from forms import AnswerForm [as 别名]
# 或者: from forms.AnswerForm import is_valid [as 别名]
def post_answer_add(request):
        if request.method == "POST":
                form = AnswerForm(request.POST)
                if form.is_valid():
                        post = form.save()
                        #url = post.get_url()
                        return HttpResponseRedirect('/question/'+request.GET.get('question')+'/')
        else:
                return HttpResponseRedirect('/')
开发者ID:PHantoMby,项目名称:3,代码行数:11,代码来源:views.py

示例15: answer_question

# 需要导入模块: from forms import AnswerForm [as 别名]
# 或者: from forms.AnswerForm import is_valid [as 别名]
def answer_question(request):
    form = AnswerForm(request.POST)
    form._user = request.user
    if form.is_valid():
        answer = form.save()
        url = answer.question.get_url()
        return HttpResponseRedirect(url)
    else:
        return HttpResponseBadRequest()
开发者ID:krkmetal,项目名称:webtech-project,代码行数:11,代码来源:views.py


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