def save(self): newanswer = Answer(text=self.cleaned_data['text'], author=self.cleaned_data['author']) newanswer.question = Question.objects.get( pk=self.cleaned_data['question']) newanswer.save() return self.cleaned_data['question']
def save(self): answer = Answer(text = self.cleaned_data['text'], question=Question.objects.get(pk=self.cleaned_data['question']), author=self._user) answer.save() return answer
def save(self, question_id): question_id = self.cleaned_data.pop('question') q = Question.objects.get(id=question_id) answer = Answer(question=q, **self.cleaned_data) answer.author = self._author answer.save() return answer
def save(self, author): data = self.cleaned_data data['question'] = Question.objects.get(pk=data['question']) answer = Answer(**self.cleaned_data) answer.author = author answer.save() return answer
def save(self, **kwargs): answer = Answer(**self.cleaned_data) # question_id = re.findall(r'/question/(\d+)/',kwargs['HTTP_REFERER']) answer.author_id = self._user # answer.question_id = int(question_id[0]) answer.save() return answer
def post(self, request): if not request.user.is_authenticated(): return HttpResponse(json.dumps({ "status": "fail", "msg": "用户未登录" }), content_type='application/json') choices = request.POST.get('choices', '') question_id = request.POST.get('question_id', '') if int(question_id) > 0 and choices: exist_records = Answer.objects.filter(user_id=request.user.id, question_id=int(question_id)) if exist_records: return HttpResponse('{"status":"success","msg":"你已经回答过这个问题"}', content_type='application/json') answer = Answer() question = Question.objects.get(id=question_id) question_standard_choices = QuestionStandardAnswers.objects.get( question_id=question_id).choice_position answer.question_id = question.id answer.content = choices answer.user = request.user if choices != question_standard_choices: answer.correct = False answer.save() return HttpResponse('{"status":"success","msg":"答案错误"}', content_type='application/json') answer.save() return HttpResponse('{"status":"success","msg":"答案正确"}', content_type='application/json') else: return HttpResponse('{"status":"fail","msg":"回答失败"}', content_type='application/json')
def save(self): answer = Answer() answer.author = self._user answer.text = self.cleaned_data['text'] answer.question_id = self.cleaned_data['question'] answer.save() return answer
def post(self, request): if not request.user.is_authenticated(): return HttpResponse(json.dumps({ "status": "fail", "msg": "用户未登录" }), content_type='application/json') content = request.POST.get('content', '') question_id = request.POST.get('question_id', '') if int(question_id) > 0 and content: answer = Answer() question = Question.objects.get(id=question_id) answer.question_id = question.id answer.content = content answer.user = request.user answer.save() return HttpResponse(json.dumps({ "status": "success", "msg": "回答成功", "id": answer.id }), content_type='application/json') else: return HttpResponse('{"status":"fail","msg":"回答失败,请重新回答"}', content_type='application/json')
def save(self): author = User.objects.get(username=self.cleaned_data['author']) answer = Answer(text=self.cleaned_data['text'], question_id=self.cleaned_data['question'], author=author) answer.save() return answer
def save(self): q = get_object_or_404(Question, pk=self.cleaned_data['question']) a = Answer(question=q, text=self.cleaned_data['text'], author=self._user) a.save() return a
def answer_question(request): if not request.user.is_authenticated(): return redirect('/') else: q_id = request.POST['question'] content = request.POST['answer'] question = Question.objects.get(pk=q_id) question.update_timestamp() answer = Answer(author=request.user, question=question, content=content) answer.save() message_followers(question=question, actor=request.user) ## Add the user to the list of followers for this question question.add_follower(request.user) if question.course.has_approved(request.user): answer.approved = True answer.save() return redirect('/question/%s' % q_id) return redirect('/question/%s?msg=amod' % q_id)
def save(self): self.cleaned_data['author'] = self.user self.cleaned_data['question'] = get_object_or_404( Question, pk=self.cleaned_data['question']) answer = Answer(**self.cleaned_data) answer.save() return answer
def save(self): self.cleaned_data['question'] = Question.objects.get(id=self.cleaned_data['question']) self.cleaned_data['author'] = self._user #print self.cleaned_data answer = Answer(**self.cleaned_data) answer.save() return answer
def save(self): self.cleaned_data['author'] = self.user answer = Answer(**self.cleaned_data) # answer.question = Question.objects.get(id=self._question) answer.save() # answer = Answer.objects.create(text=self.cleaned_data['text'], question=self.cleaned_data['question_id']) return answer
def test_model(request, *args, **kwargs): user = User(username='******', password='******') user.save() question = Question(title='qwe', text='qwe', author=user) question.save() answer = Answer(text='qwe', question=question, author=user) answer.save() return HttpResponse('OK', status=200)
def save(self): self.cleaned_data['question'] = Question.objects.get( id=self.cleaned_data['question']) answer = Answer(**self.cleaned_data) answer.author_id = 1 #answer.question = Question.objects.get(id = self.cleaned_data[question]) answer.save() return answer
def save(self): question = get_object_or_404(Question, id=self.cleaned_data['question']) answer = Answer(text=self.cleaned_data['text'], question=question, author=self._user) answer.save() return answer
def save(self): q_id = self.cleaned_data['question'] q = Question.objects.get(id=q_id) self.cleaned_data['question'] = q self.cleaned_data['author'] = self._user a = Answer(**self.cleaned_data) a.save() return a
def save(self): if self._user.is_anonymous(): self.cleaned_data['author_id'] = 1 else: self.cleaned_data['author'] = self._user answer = Answer(**self.cleaned_data) answer.save() return answer
def save(self): a = Answer(text=self.cleaned_data['text'], question_id=self.cleaned_data['question']) a.save() return a
def save(self): question = Question.objects.get(pk = self.cleaned_data['question']) self.cleaned_data['question'] = question self.cleaned_data['author'] = self._user answer = Answer(**self.cleaned_data) answer.save() return answer
def save(self): a = Answer() a.text = self.cleaned_data['text'] #a.author = self._user a.author_id = self._user.pk a.question_id = self.cleaned_data['question'] a.save() return a
def save(self): self.cleaned_data['question'] = get_object_or_404( Question, pk=self.cleaned_data['question']) self.cleaned_data['author_id'] = 1 answer = Answer(**self.cleaned_data) answer.save() return answer
def save(self): self.cleaned_data['question'] = get_object_or_404(Question,pk=self.cleaned_data['question']) if self._user.is_anonymous(): self.cleaned_data['author_id'] = 1 else: self.cleaned_data['author'] = self._user answer = Answer(**self.cleaned_data) answer.save() return answer
def save(self): user = User.objects.get(id=3) self.cleaned_data['author'] = user self.cleaned_data['added_at'] = datetime.now() self.cleaned_data['question'] = self.question answer = Answer(**self.cleaned_data) answer.save() return answer
def save(self): #answer = Answer(**self.cleaned_data) u = User.objects.all()[0] #answer.question = Question.objects.get(id=self.cleaned_data["question"]) #answer.author = u q = Question.objects.get(id=self.cleaned_data["question"]) t = self.cleaned_data["text"] answer = Answer(text = t, question = q, author = u) answer.save() return answer
def save(self): self.cleaned_data['question'] = get_object_or_404( Question, pk=self.cleaned_data['question']) if self._user.is_anonymous(): self.cleaned_data['author_id'] = 1 else: self.cleaned_data['author'] = self._user answer = Answer(**self.cleaned_data) answer.save() return answer
def answer(request, *args, **kwargs): answer = Answer(author=request.user) form = AnswerForm(request.POST, instance=answer) if form.is_valid(): answer.save() url = answer.question.get_url() return HttpResponseRedirect(url) q = get_object_or_404(Question, id=form['question'].data) return HttpResponseRedirect(q.get_url())
def save(self): data = { 'text': self.cleaned_data['text'], 'added_at': datetime.now().strftime("%Y-%m-%d %H:%M:%S"), 'question_id': int(self.cleaned_data['question']), 'author_id': self._user.id, } answer = Answer(**data) answer.save() return answer
def save(self): # self.cleaned_data['question'] = Question.objects.filter(pk = self.cleaned_data['question']) self.cleaned_data['question'] = get_object_or_404(Question, pk=self.cleaned_data['question']) if self._user.is_anonymous(): self.cleaned_data['author_id'] = 1 else: self.cleaned_data['author'] = self._user post = Answer(**self.cleaned_data) post.save() return post
def save(self): question_id = self.cleaned_data['question'] data = {'text': self.cleaned_data['text'], #'question': Question.objects.get(pk=question_id), 'question_id': int(question_id), 'author': self._user } #answer = Answer(**self.cleaned_data) answer = Answer(**data) answer.save() return answer
def question(request, id): if request.method == 'POST': form = AnswerForm(request.POST) if form.is_valid(): answer = Answer(**form.cleaned_data) answer.save() question = get_object_or_404(Question, pk=id) form = AnswerForm() return render(request, 'qa/question.html', { 'question': question, 'form': form })
def save(self): question = Question.objects.get(id = self.cleaned_data['question']) # if not question.id: # return HttpResponse('question id is empty') self.cleaned_data['author'] = self._user answer = Answer(text=self.cleaned_data['text'], author = self.cleaned_data['author'], question=question) #answer = Answer(**self.cleaned_data) answer.save() return answer
def test_question(self): user, _ = User.objects.get_or_create(username='******', password='******') try: question = Question(title='qwe', text='qwe', author=user) question.save() except: assert False, "Failed to create question model, check db connection" try: answer = Answer(text='qwe', question=question, author=user) question.save() answer.save() except: assert False, "Failed to create answer model, check db connection"
def save(self): answer = Answer(**self.cleaned_data) #t7 user,_ = User.objects.get_or_create(username='******',password='******') #t7 answer.author=user answer.author_id = self._user.id if self._user.id is None: user, _ = User.objects.get_or_create(username='******', password='******') answer.author = user else: pass answer.save() return answer
def test_cannot_save_empty_answers(self): answer = Answer(text='', question=self.question, author=self.other_user) with self.assertRaises(ValidationError): answer.save() answer.full_clean() answer = Answer(text='Text', question=self.question, author=self.other_user) answer.save() answer.full_clean() self.assertEqual(answer, Answer.objects.first())
def run(self): answer = Answer() answer.question = self.question answer.user = self.user question_title = self.question.title question_description = self.question.description if USE_SERVER: answer_content = self.reuse(question_title, question_description) if not answer_content: answer_content = self.answer(question_title, question_description) if answer_content: answer.answer_text = answer_content answer.save()
def answer(request): """Answer post form.""" if request.method == 'POST': form = AnswerForm(request.POST) if form.is_valid(): question = form.question params = { 'text': form.cleaned_data['text'], 'question': question } if request.user.is_authenticated(): params.update({'author': request.user}) answer = Answer(**params) answer.save() return HttpResponseRedirect( reverse('question', kwargs={'id': question.id}) ) return HttpResponseRedirect(reverse('root', kwargs={}))
def save(self): question = Question.objects.get(id=self.cleaned_data['question']) answer = Answer(text=self.cleaned_data['text'], question=question) answer.save() return answer
def save(self): self.cleaned_data['question'] = Question(self.cleaned_data['question']) answer = Answer(**self.cleaned_data) answer.author_id = self.user.id answer.save() return answer
def save(self, user): q = get_object_or_404(Question, id=self.cleaned_data['question']) a = Answer(author=user, question=q, text=self.cleaned_data['text']) a.save() return a
def save(self): answer = Answer(**self.cleaned_data) answer.author_id = self._user.id answer.save() return answer
def save(self): self.cleaned_data['author'] = self._user answer = Answer(**self.cleaned_data) answer.save() return answer
def save(self): user, _ = User.objects.get_or_create(username='******', defaults={'password': '******'}) ans = Answer(text=self.cleaned_data['text'], question=self.cleaned_data['question'], author=user) ans.save() return ans
def save(self): newanswer = Answer(text=self.cleaned_data['text'], author=self.cleaned_data['author']) newanswer.question = Question.objects.get(pk=self.cleaned_data['question']) newanswer.save() return self.cleaned_data['question']
def save(self): answer = Answer(**self.cleaned_data) if self._user is not None and self._user.is_anonymous() == False: answer.author = self._user answer.save() return answer
def save(self): answer = Answer(**self.cleaned_data) answer.save() return answer
def save(self, question_id): qu = Question.objects.get(pk=question_id) answer = Answer(self.cleaned_data['test']) answer.question = qu answer.save()
def save(self): a = Answer(**self.cleaned_data) a.save() return a
def save(self, question): self.cleaned_data['author'] = self._user self.cleaned_data['question'] = question answer = Answer(**self.cleaned_data) answer.save() return answer
["sixth","what is the time now??", datetime.now(),17,56,User.objects.get(username="******")], ["seventh","how much is the fish",datetime.now(),12,8,User.objects.get(username="******")], ["eghth","WTF 0_o ???", datetime.now(),6,14,User.objects.get(username="******")], ["ninegth","what is the time now??", datetime.now(),10,20,User.objects.get(username="******")], ["tenth","how much is the fish",datetime.now(),0,0,User.objects.get(username="******")], ["eleven","WTF 0_o ???", datetime.now(),14,56,User.objects.get(username="******")], ["tvelve","what is the time now??", datetime.now(),22,34,User.objects.get(username="******")], ["forteen","how much is the fish",datetime.now(),24,56,User.objects.get(username="******")], ["sixteenth","WTF 0_o ???", datetime.now(),23,32,User.objects.get(username="******")], ["eigtheenth","what is the time now??", datetime.now(),34,17,User.objects.get(username="******")], ] for question in questions: title,text,added_at,rating,likes,author = question question=Question(title=title,text=text,added_at=added_at,rating=rating,likes=likes,author=author) question.save() answers = [ ["dorogo",datetime.now(),Question.objects.get(title="first"),User.objects.get(username="******")], ["togo!togo",datetime.now(),Question.objects.get(title="second"),User.objects.get(username="******")], ["13:00 o clock!!", datetime.now(),Question.objects.get(title="second"),User.objects.get(username="******")], ] for answer in answers: text,added_at,question,author = answer answer=Answer(text=text,added_at=added_at,question=question,author=author) answer.save()
def save(self): if self.is_valid(): pass answer = Answer(text=self.cleaned_data['text'], question_id=self.cleaned_data['question']) answer.save() return answer