Example #1
0
def answer_create(user_id, code):
    """
    답변 생성
    """
    member = get_object_or_404(Member, name=user_id)
    answer = Answer(member=member, content=code, create_date=timezone.now())
    answer.save()
Example #2
0
def answer_question(request, q_id):
	if request.POST():
		ansform = AnswerForm(request.POST)
		if ansform.is_valid():
			q = get_object_or_404(Question, id=q_id)
			new_answer = Answer(question = q_id, content=ansform.cleaned_data['content'])
			new_answer.save()
			return render(request, 'success.html')
		else:
			context = {'ansform': ansform}
			return render(request, 'ask_question.html', context)
	else:
		ansform = AnswerForm()
		context = {'ansForm': ansform}
		return render(request, 'answer_question.html', context)
Example #3
0
def answer_question(request, q_id):
    if request.POST():
        ansform = AnswerForm(request.POST)
        if ansform.is_valid():
            q = get_object_or_404(Question, id=q_id)
            new_answer = Answer(question=q_id,
                                content=ansform.cleaned_data['content'])
            new_answer.save()
            return render(request, 'success.html')
        else:
            context = {'ansform': ansform}
            return render(request, 'ask_question.html', context)
    else:
        ansform = AnswerForm()
        context = {'ansForm': ansform}
        return render(request, 'answer_question.html', context)
Example #4
0
def question_detail(request, pk):
    question = get_object_or_404(Question, pk=pk)
    context = {'question':question}

    if request.method == 'POST':
        answer_form = AnswerForm(request.POST)

        if answer_form.is_valid():
            answer_text = answer_form.cleaned_data.get('text')

            #creating new answer for this question
            new_answer = Answer()
            new_answer.text = answer_text
            if request.user.is_authenticated():
                new_answer.user = request.user
            new_answer.question = question
            new_answer.save()

            #message for successful save
            context['answer_saved']=True
            answer_form = AnswerForm()

        context['answer_form'] = answer_form
        # return render(request, 'question/detail.html', context)
        return redirect(request.META['HTTP_REFERER']) # redirect to same url (where form was submitted )

    else:
        answer_form = AnswerForm()
        context['answer_form']=answer_form

    return render(request, 'question/detail.html', context)
Example #5
0
def QuestionView(request, pk):
    if not request.user.is_authenticated():
        return HttpResponseRedirect('/login/')
    if request.method == 'POST':
        form = NewAnswerForm(request.POST)
        if form.is_valid():
            answer = Answer()
            answer.text=form.cleaned_data['text']
            answer.title=form.cleaned_data['title']
            answer.user = request.user
            answer.question=Question.objects.get(pk=int(pk))
            answer.save()
            print "Ok"
            send_mail('Subject', 'You have new answers', '*****@*****.**',
                      ['*****@*****.**'], fail_silently=False)
            return HttpResponseRedirect('/question/'+pk+'/#answer'+str(answer.pk))
        else:
            context = {'form':form}
            context['question']= Question.objects.get(pk=int(pk))
            context['answers']= Answer.objects.filter(question__pk=int(pk))
            return render_to_response('question.html', context, context_instance=RequestContext(request))
    else:
        ''' '''
        form = NewAnswerForm()
        context = {'form':form}
        context['question']= Question.objects.get(pk=int(pk))
        context['answers']= Answer.objects.filter(question__pk=int(pk))
        return  render_to_response('question.html',context, context_instance=RequestContext(request))
Example #6
0
def analyze_answer(request, exam_id):
    if not request.user.is_authenticated():
        return HttpResponseRedirect(reverse('exam:home'))
    template = loader.get_template('answer.html')
    if request.method == "GET":
        try:
            if not validate_number_of_attempts(request.user.id, exam_id):
                return HttpResponse("Noch Noch")

            exam_answer = ExamAnswer.objects.get(user_id=request.user.id, exam_id=exam_id)

            context = RequestContext(request, {'answer': exam_answer})
            return HttpResponse(template.render(context))
        except ObjectDoesNotExist as e:
            return HttpResponseRedirect(reverse('exam:home'))
    if request.method == "POST":
        exam = Exam.objects.get(id=exam_id)
        exam_answer, is_new = ExamAnswer.objects.get_or_create(user_id=request.user.id, exam_id=exam_id)
        if not validate_number_of_attempts(request.user.id, exam_id):
            return HttpResponse("Noch Noch")

        exam_answer_history = ExamAnswerHistory()
        exam_answer_history.user_id = request.user.id
        exam_answer_history.exam = exam
        exam_answer_history.save()
        for q in exam.question_set.all():
            answer = Answer()
            answer.question = q
            answer.exam_answer = exam_answer_history
            answer.save()
            if str(q.id) in request.POST.keys():
                for a in request.POST.getlist(str(q.id)):
                    answer.selected_choices.add(a)
            else:
                answer.selected_choices.add(-1)

        if exam_answer_history.score() > exam_answer.score:
            exam_answer.score = exam_answer_history.score()
            exam_answer.save()

    context = RequestContext(request, {'answer': exam_answer_history})
    return HttpResponse(template.render(context))
Example #7
0
    def handle(self, *args, **options):
        u = []
        for i in range(10):
            u.append(User(name="user{}".format(i), date=timezone.now()))

        for usr in u:
            usr.save()

        t = []
        for i in range(10):
            t.append(Tag(name="tag{}".format(i)))

        for tag in t:
            tag.save()

        q = []
        i = 1
        for usr in u:
            q.append(
                Question(title="question{}".format(i),
                         text="Lorem ipsum question from user: {}".format(usr),
                         date=timezone.now(),
                         user=usr))
            i += 1

        for qst in q:
            qst.save()

        for qst in q:
            tags = qst.tags
            for i in range(3):
                tags.add(t[rnd.randint(0, 9)])
            qst.save()

        a = []
        for que in q:
            for usr in u:
                a.append(
                    Answer(
                        text="Lorem ipsum answer from user: {}".format(usr),
                        date=timezone.now(),
                        user=usr,
                        qst=que,
                    ))

        for ans in a:
            ans.save()