def test_valid_give_answer(self): form_data = { 'description': 'This is how you handle recurion in python:' } form = GiveAnswerForm(form_data) self.assertTrue(form.is_valid()) self.assertFalse(form.errors)
def view_give_answer(request, question_id, give_answer_template, question_template): question = get_object_or_404(Question, id=int(question_id)) if request.method == 'POST': form = GiveAnswerForm(post_data(request)) if form.is_valid(): userprofile = loggedin_userprofile(request) new_answer = Answer.objects.create_answer( question=question, description=form.cleaned_data.get('description'), userprofile=userprofile) new_anwer_emailer(question, new_answer) from quest.messages import ANSWER_POSTING_SUCCESSFUL messages.success(request, ANSWER_POSTING_SUCCESSFUL) give_answer_form = GiveAnswerForm() return response(request, question_template, { 'question': question, 'give_answer_form': give_answer_form }) return response(request, question_template, { 'question': question, 'give_answer_form': form }) return HttpResponseRedirect(redirect_to=url_reverse( 'quest.views.view_question', args=(question.id, question.slug)))
def view_give_answer(request, question_id, give_answer_template, question_template): question = get_object_or_404(Question, id=int(question_id)) if request.method == 'POST': form = GiveAnswerForm(post_data(request)) if form.is_valid(): userprofile = loggedin_userprofile(request) new_answer = Answer.objects.create_answer(question=question, description=form.cleaned_data.get('description'), userprofile=userprofile) new_anwer_emailer(question, new_answer) from quest.messages import ANSWER_POSTING_SUCCESSFUL messages.success(request, ANSWER_POSTING_SUCCESSFUL) give_answer_form = GiveAnswerForm() return response(request, question_template, {'question':question, 'give_answer_form':give_answer_form}) return response(request, question_template, {'question':question, 'give_answer_form':form}) return HttpResponseRedirect(redirect_to=url_reverse('quest.views.view_question', args=(question.id, question.slug)))
def view_question(request, question_id, question_slug, question_template): question = get_object_or_404( Question, id=int(question_id)) #question_slug is for SEO if question.is_accepting_answers(): give_answer_form = GiveAnswerForm() else: give_answer_form = None return response(request, question_template, { 'question': question, 'give_answer_form': give_answer_form })
def test_invalid_give_answer(self): form_data = {'description': ''} form = GiveAnswerForm(form_data) self.assertFalse(form.is_valid()) self.assertTrue(form.errors) self.assertTrue(form.errors.has_key('description'))
def test_invalid_give_answer(self): form_data = {'description':''} form = GiveAnswerForm(form_data) self.assertFalse(form.is_valid()) self.assertTrue(form.errors) self.assertTrue(form.errors.has_key('description'))
def test_valid_give_answer(self): form_data = {'description':'This is how you handle recurion in python:'} form = GiveAnswerForm(form_data) self.assertTrue(form.is_valid()) self.assertFalse(form.errors)