Exemplo n.º 1
0
 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']
Exemplo n.º 2
0
	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
Exemplo n.º 3
0
 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
Exemplo n.º 4
0
 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
Exemplo n.º 5
0
	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
Exemplo n.º 6
0
 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')
Exemplo n.º 7
0
 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
Exemplo n.º 8
0
 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')
Exemplo n.º 9
0
 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
Exemplo n.º 10
0
 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
Exemplo n.º 11
0
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)
Exemplo n.º 12
0
 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
Exemplo n.º 13
0
	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
Exemplo n.º 14
0
	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
Exemplo n.º 15
0
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)
Exemplo n.º 16
0
 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
Exemplo n.º 17
0
Arquivo: forms.py Projeto: VioletM/web
 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
Exemplo n.º 18
0
 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
Exemplo n.º 19
0
Arquivo: forms.py Projeto: a-back/web
 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
Exemplo n.º 20
0
    def save(self):

        a = Answer(text=self.cleaned_data['text'],
                   question_id=self.cleaned_data['question'])

        a.save()

        return a
Exemplo n.º 21
0
 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
Exemplo n.º 22
0
    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
Exemplo n.º 23
0
 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
Exemplo n.º 24
0
	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
Exemplo n.º 25
0
	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
Exemplo n.º 26
0
    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
Exemplo n.º 27
0
Arquivo: forms.py Projeto: kyuiva/2_6
 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
Exemplo n.º 28
0
 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
Exemplo n.º 29
0
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())
Exemplo n.º 30
0
 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 
Exemplo n.º 31
0
 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
Exemplo n.º 32
0
  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
Exemplo n.º 33
0
	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	
Exemplo n.º 34
0
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
    })
Exemplo n.º 35
0
 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          
Exemplo n.º 36
0
 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"
Exemplo n.º 37
0
 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
Exemplo n.º 38
0
    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())
Exemplo n.º 39
0
    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()
Exemplo n.º 40
0
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={}))
Exemplo n.º 41
0
 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
Exemplo n.º 42
0
 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
Exemplo n.º 43
0
 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
Exemplo n.º 44
0
 def save(self):
     a = Answer(text=self.cleaned_data['text'],
                question_id=self.cleaned_data['question'])
     a.save()
     return a
Exemplo n.º 45
0
 def save(self):
     answer = Answer(**self.cleaned_data)
     answer.author_id = self._user.id
     answer.save()
     return answer
Exemplo n.º 46
0
 def save(self):
     self.cleaned_data['author'] = self._user
     answer = Answer(**self.cleaned_data)
     answer.save()
     return answer
Exemplo n.º 47
0
    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
Exemplo n.º 48
0
 def save(self):
     self.cleaned_data['author'] = self._user
     answer = Answer(**self.cleaned_data)
     answer.save()
     return answer
Exemplo n.º 49
0
 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']
Exemplo n.º 50
0
 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
Exemplo n.º 51
0
 def save(self):
     answer = Answer(**self.cleaned_data)
     answer.save()
     return answer
Exemplo n.º 52
0
 def save(self, question_id):
     qu = Question.objects.get(pk=question_id)
     answer = Answer(self.cleaned_data['test'])
     answer.question = qu
     answer.save()
Exemplo n.º 53
0
	def save(self):
		a = Answer(**self.cleaned_data)
		a.save()
		return a
Exemplo n.º 54
0
 def save(self, question):
     self.cleaned_data['author'] = self._user
     self.cleaned_data['question'] = question
     answer = Answer(**self.cleaned_data)
     answer.save()
     return answer
Exemplo n.º 55
0
	["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()


Exemplo n.º 56
0
 def save(self):
     answer = Answer(**self.cleaned_data)
     answer.author_id = self._user.id
     answer.save()
     return answer
Exemplo n.º 57
0
 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