• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python models.Answer类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中models.Answer的典型用法代码示例。如果您正苦于以下问题:Python Answer类的具体用法?Python Answer怎么用?Python Answer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: add_answer

def add_answer(get_data):
	'''
	@summary: to add multi-choice answer
	@param: <data> answer data dictionary
	'''
	data = {}
	answer_text = get_data.get('answer_text')
	answer_rating = get_data.get('answer_rating','')
	presentation_order = get_data.get('presentation_order')
	question_id = get_data.get('question_id')
	status_cd = get_data.get('status_cd')
	created_by = get_data.get('created_by')
	now_date = datetime.now()
	if answer_text and answer_rating and presentation_order.isdigit() and question_id and status_cd and created_by:
		answer_data = Answer(
			answer_text = answer_text,
			answer_rating = answer_rating,
			presentation_order = presentation_order,
			question_id = question_id,
			status_cd = status_cd,
			created_by = created_by,
			updated_by = created_by,
			created_date = now_date,
			updated_date = now_date)
			
		answer_data.save()
		data['status'] = 1
		data['msg'] = 'Answer Added succssfully'
		data['data'] = {'question_id': answer_data.question_id, 'answer_id': answer_data.answer_id}
	else:
		data['status'] = 0
		data['msg'] = 'Some fields are missing'
	return data
开发者ID:amitpandita,项目名称:TPMS,代码行数:33,代码来源:question_answer_api.py


示例2: save

 def save(self):
     question = Question.objects.get(pk=self.cleaned_data.get('question'))
     answer = Answer(text = self.cleaned_data['text'],
                     question=question,
                     author=self._user)
     answer.save()
     return answer
开发者ID:denproger,项目名称:stepic_web_project,代码行数:7,代码来源:forms.py


示例3: receive_ans_ajax

def receive_ans_ajax(request, round_number):
    if request.is_ajax() and request.method == 'POST':
        json_data = json.loads(request.readline())
        
        player = request.user.player
        
        room_query = GameRoom.objects.filter(players__id=player.id)
        room = room_query[0]

        round_query = GameRound.objects.filter(room__id=room.id)
        cur_round = round_query.filter(round_number=round_number)[0]

        for key in json_data:
            value = json_data[key]
            field_query = Field.objects.filter(short_name=key)
            field = field_query[0]
            if len(value) >0:
                valid = value[0].lower() == cur_round.cur_letter.lower()
            else:
                valid = False

            ans = Answer(roundd=cur_round, player=player, field=field, ans=value, valid=valid,points= 10 if valid else 0 )
            ans.save()
        return HttpResponse("OK")
    else:
        if not request.is_ajax():
            return HttpResponse('Only ajax is allowed')
        elif not request.method == 'POST':
            return HttpResponse(request.method + ' is not allowed')
        else:
            return HttpResponse('unknown error')
开发者ID:lucasamaral,项目名称:stop-game,代码行数:31,代码来源:views.py


示例4: save

 def save(self, user_id):
     user = User.objects.get(id=user_id)
     self.cleaned_data['author'] = user
     question = Question.objects.get(id=self.cleaned_data['question'])
     self.cleaned_data['question'] = question
     answer = Answer(**self.cleaned_data)
     answer.save()
     return answer
开发者ID:ivansemin,项目名称:stepic_mail_django,代码行数:8,代码来源:forms.py


示例5: save

 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
开发者ID:xiva-wgt,项目名称:web_project,代码行数:8,代码来源:forms.py


示例6: save

 def save(self):
     if self._user.is_authenticated():
         self.cleaned_data['author'] = self._user
     url = '/question/'+ str(self.cleaned_data['question'])+'/' # bad pracrtice hardcoded link
     self.cleaned_data['question'] = Question.objects.get(id=self.cleaned_data['question'])
     answer = Answer(**self.cleaned_data)
     answer.save()
     return url
开发者ID:xkotok,项目名称:demo_ask,代码行数:8,代码来源:forms.py


示例7: post

 def post(self, boragle_slug, question_slug):
     question = Question.find_by_slug(question_slug)
     avatar = self.get_avatar_for_boragle(question.boragle)
     assert avatar, question
     answer = self.read('answer')
     if not(answer and answer.strip()): raise PostingError('Please provide an answer')
     Answer.create(question = question, text = answer, creator = avatar)
     page = self.calc_last_page(question.answer_count, settings.answer_page_size)
     self.redirect(question.url+'?page='+str(page))
开发者ID:sudhirj,项目名称:boragle,代码行数:9,代码来源:main.py


示例8: test_voting_security

 def test_voting_security(self):
     answer = Answer.create(question = self.question, text= 'fake answer', creator = self.avatar)
     self.app.get(answer.voting_url+'/up', status = 302)
     answer = Answer.get(answer.key())
     self.assertEqual(answer.vote_count, 1)
     self.logout()
     self.app.get(answer.voting_url+'/down', status = 302)
     answer = Answer.get(answer.key())
     self.assertEqual(answer.vote_count, 1)        
开发者ID:sudhirj,项目名称:boragle,代码行数:9,代码来源:web_question_tests.py


示例9: save

 def save(self):
     # getting Question by ID
     print 'AnswerF save: %s (%s)' % ( self.cleaned_data, self.cleaned_data['question'])
     q_id = int(self.cleaned_data['question'])
     quest = Question.objects.get(id = q_id)
     #ans = Answer(**self.cleaned_data)
     ans = Answer(text = self.cleaned_data['text'])
     ans.author_id = 1
     quest.answer_set.add(ans)
     quest.save()
     return ans
开发者ID:Bushische,项目名称:stepic16,代码行数:11,代码来源:forms.py


示例10: createQuestion

def createQuestion(match_id):
    player_id = request.form['player_id']
    correct = request.form['correct'] == '1'
    tags = request.form.getlist('tags[]')

    answer = Answer(player_id, correct)
    question = Question(tags, answers=[answer.asJSON()])
    question.save()

    match = MatchFinder().find(match_id)
    match.addQuestionAndAnswer(question, answer)
    return "OK " + str(question._id)
开发者ID:ryoung786,项目名称:quick_recall,代码行数:12,代码来源:server.py


示例11: question

def question(request):
    if request.method == 'POST' :
        req = simplejson.loads(request.body,strict=False)
        # get the json parameters,username,course,questionnumber and answer
        username = req['username']
        course = req['course']
        role = req['role']
        quetionnumber = req['questionnumber']
        answer = req['answer']
        #check the parameter validating
        #store to the db
        ans = Answer(question_id = questionnumber, course_id = course,text = answer)
        ans.save()
开发者ID:CharlesCliff,项目名称:SC,代码行数:13,代码来源:views.py


示例12: run

 def run(self):
     Answer.query.delete()
     db.session.commit()
     for file_name in glob(os.path.join(ANSWERS_DIR, '**/*.csv')):
         with open(file_name, 'rb') as csvfile:
             locale = file_name.split('/')[-2]
             csv_reader = csv.reader(csvfile)
             for row in csv_reader:
                 answer = Answer()
                 answer.locale = locale
                 answer.text = unicode(row[0], 'utf-8')
                 db.session.add(answer)
             db.session.commit()
开发者ID:taras1k,项目名称:askme,代码行数:13,代码来源:commands.py


示例13: set_answer

def set_answer(puzzle_name, player_id, question, content_type, content):
    player = Player.get(Player.id == player_id)
    puzzle, _ = Puzzle.get_or_create(name=puzzle_name)
    try:
        answer = Answer.get(
            (Answer.puzzle == puzzle) & (Answer.player == player))
    except Answer.DoesNotExist:
        answer = Answer(puzzle=puzzle, player=player)

    answer.question = question

    if content_type == 'text':
        answer.value = content
    elif content_type == 'image':
        filename = '%s_%s.jpg' %  (puzzle.id, player.id)
        path = '%s/images/%s' % (STATIC_DIR, filename)
        with open(path, 'wb') as fp:
            fp.write(content)
        answer.value = 'image:' + filename
    elif content_type == 'video':
        filename = '%s_%s.mp4' %  (puzzle.id, player.id)
        path = '%s/videos/%s' % (STATIC_DIR, filename)
        with open(path, 'wb') as fp:
            fp.write(content)
        answer.value = 'video:' + filename

    answer.save()
开发者ID:ChickTech,项目名称:puzzle-hunt,代码行数:27,代码来源:flask_app.py


示例14: filldb

def filldb(request, cou):
    for x in range(0, int(cou)):
        q = Question(title = "Question #"+str(x),
                     text = "Just a question with number "+str(x))
        q.rating = x
        q.author_id = 1
        q.added_at = date(2016, 03, 1+x)
        q.save()
        q.added_at = date(2016, 03, 1+x)
        for y in range(1, x+2):
            a = Answer(text = "answer #"+str(y)+" for question #"+str(x))
            a.author_id = 1
            q.answer_set.add(a)
        q.save()
    return HttpResponse("OK")
开发者ID:Bushische,项目名称:stepic16,代码行数:15,代码来源:views.py


示例15: user_profile

def user_profile():
    """Displays the user profile page"""
    user = users.get_current_user()
    question_count = Question.count_for(user)
    answer_count = Answer.count_for(user)
    form = ProspectiveUserForm()
    all_prospective_users = ProspectiveUser.get_for(user)
    prospective_user = all_prospective_users.get()

    if request.method == 'POST':
        if prospective_user is None:
            prospective_user = ProspectiveUser (
                login = user,
                origin_location = get_location(form.origin_location.data),
                notification_radius_in_km = form.notification_radius_in_km.data,
                screen_name = form.screen_name.data
            )
        else:
            prospective_user.origin_location = get_location(form.origin_location.data)
            prospective_user.notification_radius_in_km = form.notification_radius_in_km.data
            prospective_user.screen_name = form.screen_name.data
        try:
            prospective_user.put()
            subscribe_user_for_nearby_questions(prospective_user.key.id())
            flash(u'Home location successfully saved.', 'success')

            return redirect(url_for('user_profile'))
        except CapabilityDisabledError:
            flash(u'App Engine Datastore is currently in read-only mode.', 'info')
            return redirect(url_for('user_profile'))

    return render_template('user_profile.html', user=user, prospective_user=prospective_user,
                           question_count=question_count, answer_count=answer_count, form=form)
开发者ID:ahbuntu,项目名称:ece1779,代码行数:33,代码来源:views.py


示例16: get_rev_set_raw

def get_rev_set_raw(rev):
    qs = []
    #first object to be the description of the revision
    lect_class = LectClass.get(rev.lect_class)
    rev_desc = {
                'lecturer':rev.user.name,
                'institution':rev.user.institution,
                'title':rev.title,
                'class':lect_class.name,
                'description':rev.description,
                'created':rev.created.strftime("%B %d, %Y")
                }
    qs.append(rev_desc)
    questions = Question.gql('WHERE revision = :1',rev).fetch(100) #how do we fetch all the Qs?
    for q in questions:
        answers = Answer.gql('WHERE question=:1',q)
        ans = []
        for a in answers:
            ans.append(a.answer)
        question = {
                    'question':q.question.replace("\n","").replace("\r",""),
                    'answers':ans
                    }
        qs.append(question)
    return qs
开发者ID:BeyondeLabs,项目名称:quizer,代码行数:25,代码来源:explore.py


示例17: answer_question

def answer_question(request, question_id):
    if request.user.is_authenticated():
        if request.method == 'POST':
            form = AnswerForm(request.POST)
            if form.is_valid():
                question = Question.objects.get(id = question_id)
                author = request.user
                text = form.cleaned_data['answer']
                answer = Answer(text = text, author = author,
                        question = question)
                answer.save()
                return  view_question(request, question_id)
            else:
                pass #TODO: validar cuando el formulario de errores.
    else:
        return HttpResponseRedirect('/cuentas/login')
开发者ID:igorgue,项目名称:softwarelibre.org.ni,代码行数:16,代码来源:views.py


示例18: handleForm

def handleForm(request):
    new_title = request.POST['title']
    new_author = request.POST['author']
    new_desc = request.POST['desc']
    answers = []
    for i in range(1, 20):
        input_name = "answer" + str(i)
        if input_name in request.POST:
            s = request.POST[input_name].replace("'", "")
            answers.append(s)
    new_survey = Survey(title=new_title, author=new_author, desc=new_desc)
    new_survey.save()
    for answer in answers:
        new_answer = Answer(survey=new_survey, text=answer, votes=0)
        new_answer.save()
    return HttpResponseRedirect('/survey/' + str(new_survey.id))
开发者ID:meet-projects,项目名称:survme-y2-2013,代码行数:16,代码来源:views.py


示例19: reply_question

def reply_question(question_id):
	user_id = session['user_id']
	data = json.loads(request.data)
	data['author_id'] = user_id
	data['question_id'] = question_id
	
	answer = Answer(**data)
	result = answer.save()
	
	if result:
		answer = answer.to_dict()
		author = User.query.get(user_id).to_dict()
		answer['author'] = author
		socketio.emit('question' + str(question_id), answer, namespace='/qa')
	
	return jsonify({'status': 1 if result else 0})
开发者ID:khanhicetea,项目名称:sourcesage-dev-test,代码行数:16,代码来源:controllers.py


示例20: save

 def save(self, commit=True):
     test = super(TestAdminForm, self).save(False)
     file = self.cleaned_data['file']
     questions_count = self.cleaned_data['questions_count']
     
     if file:
         test_name = test.name
         test.save()
         AnswerResult.objects.filter(answer__question__test=test).delete()
         AnswerChoice.objects.filter(question__test=test).delete()
         TestPass.objects.filter(test=test).delete()
         Answer.objects.filter(question__test=test).delete()
         Question.objects.filter(test=test).delete()
         
         questions = parser(file)
         count = 0
         cur_test = test
         
         for i, question in enumerate(questions):
             count += 1
             q = Question(test=cur_test, question=question['question'])
             if question['text_answer']:
                 q.text_answer = question['text_answer']
                 q.save()
             else:
                 q.save()
                 for answer in question['answers']:
                     a = Answer(question=q)
                     a.answer = answer['text']
                     a.correct = answer['correct']
                     a.save()
             
             if questions_count and count >= questions_count:
                 if (len(questions) - i) >= questions_count:
                     cur_test.name = '%s [%s-%s]' % (test_name, i+1-count, i+1)
                     cur_test.save()                           
                     cur_test = copy(test)
                     cur_test.pk = None
                     cur_test.save()
                 else:
                     cur_test.name = '%s [%s-%s]' % (test_name, i+1-count, len(questions))
                     cur_test.save()
                                                   
                 count = 0
             
     return test
开发者ID:Alerion,项目名称:testing-for-Kate,代码行数:46,代码来源:forms.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python models.Article类代码示例发布时间:2022-05-27
下一篇:
Python models.Album类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap