当前位置: 首页>>代码示例>>Python>>正文


Python Answer.save方法代码示例

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


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

示例1: add_answer

# 需要导入模块: from models import Answer [as 别名]
# 或者: from models.Answer import save [as 别名]
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,代码行数:35,代码来源:question_answer_api.py

示例2: receive_ans_ajax

# 需要导入模块: from models import Answer [as 别名]
# 或者: from models.Answer import save [as 别名]
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,代码行数:33,代码来源:views.py

示例3: save

# 需要导入模块: from models import Answer [as 别名]
# 或者: from models.Answer import save [as 别名]
 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,代码行数:9,代码来源:forms.py

示例4: set_answer

# 需要导入模块: from models import Answer [as 别名]
# 或者: from models.Answer import save [as 别名]
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,代码行数:29,代码来源:flask_app.py

示例5: save

# 需要导入模块: from models import Answer [as 别名]
# 或者: from models.Answer import save [as 别名]
 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,代码行数:10,代码来源:forms.py

示例6: save

# 需要导入模块: from models import Answer [as 别名]
# 或者: from models.Answer import save [as 别名]
 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,代码行数:10,代码来源:forms.py

示例7: save

# 需要导入模块: from models import Answer [as 别名]
# 或者: from models.Answer import save [as 别名]
 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,代码行数:10,代码来源:forms.py

示例8: question

# 需要导入模块: from models import Answer [as 别名]
# 或者: from models.Answer import save [as 别名]
def question(request):
    if request.method == 'GET':
        # zasad koristim page parametar za jedno pitanje (id)
        # page = request.GET['page']
        question_number = request.GET['page']
        questions_per_page = 2

        question = Question.objects.get(number=question_number)
        answers = question.answer_set.all()

        return render(request, 'prikaz.html', { 'question': question, 'answers': answers })

    elif request.method == 'POST':
        question = Question()
        post_data = request.POST;

        try:
            question.image = request.FILES['image']
        except:
            pass

        question.answer_type = AnswerType.objects.get(name = post_data['type'])
        question.text = post_data['text']
        question.number = post_data['number']

        question.save()

        answers = []
        print post_data
        for key in [x for x in post_data if x.startswith('answer')]:
            current = key.replace('answer', '')

            post_answer = post_data['answer' + current]
            post_solution = post_data['solution' + current]

            if post_answer != '':
                answer = Answer()
                answer.text = post_answer
                answer.value = post_solution
                answer.question = question
                answers.append(answer)

        for answer in answers:
            answer.save()

        answer_types = AnswerType.objects.all()
        return render(request, 'unos.html', \
                     { 'question_number': int(question.number) + 1, \
                       'answer_types': answer_types })

    else:
        return HttpResponse("Method not allowed.", status=405)
开发者ID:jrocketfingers,项目名称:matura,代码行数:54,代码来源:views.py

示例9: question

# 需要导入模块: from models import Answer [as 别名]
# 或者: from models.Answer import save [as 别名]
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,代码行数:15,代码来源:views.py

示例10: generate_answers

# 需要导入模块: from models import Answer [as 别名]
# 或者: from models.Answer import save [as 别名]
def generate_answers(attempt, qnlist):
  ret={}
  for qn in qnlist:
    qnid = qn.qn.id
    ret[qnid]=[]
    smallans=Answer(testattempt=attempt, qn=qn.qn, qtype="small") 
    smallans.save()
    ret[qnid].append(smallans)
    if qn.qn.need2questions:
      largeans=Answer(testattempt=attempt, qn=qn.qn, qtype="large") 
      largeans.save()
      ret[qnid].append(largeans)
  return ret
开发者ID:param108,项目名称:ccodejam,代码行数:15,代码来源:views.py

示例11: save

# 需要导入模块: from models import Answer [as 别名]
# 或者: from models.Answer import save [as 别名]
 def save(self, commit=True):
     if not self.cleaned_data['answer']:
         if self.fields['answer'].required:
             raise ValidationError, _('This field is required.')
         return
     ans_list = []
     for text in self.cleaned_data['answer']:
         ans = Answer()
         ans.question = self.question
         ans.session_key = self.session_key
         ans.text = text
         if commit: ans.save()
         ans_list.append(ans)
     return ans_list
开发者ID:scanner,项目名称:my-django-survey,代码行数:16,代码来源:forms.py

示例12: add_new_answer

# 需要导入模块: from models import Answer [as 别名]
# 或者: from models.Answer import save [as 别名]
def add_new_answer(request):
    _check_for_admin()
    post = request.POST
    if post:
        new_answer = post["new_answer"]
        new_link = post["new_link"]
        new_date = datetime.strptime(post["date"], "%d.%m.%Y").date()
        new_question = get_question()
        answer = Answer()
        answer.text=new_answer
        answer.more_link = new_link
        answer.question=new_question
        answer.date = new_date
        answer.save()
    return redirect("polls.views.main_page")
开发者ID:soswow,项目名称:yet-another-one-poll-on-app-engine,代码行数:17,代码来源:views.py

示例13: create_answer

# 需要导入模块: from models import Answer [as 别名]
# 或者: from models.Answer import save [as 别名]
def create_answer(request):
    user = User.objects.get(code=request.POST['user_code'])
    image = Image.objects.get(pk=request.POST['image_id'])

    a = Answer()
    a.user = user
    a.image = image
    a.index_1 = request.POST['index_1']
    a.index_2 = request.POST['index_2']
    a.score = request.POST['score']
    a.save()

    user.answer_number += 1
    user.save()

    return HttpResponse()
开发者ID:morningsyj,项目名称:qa-online,代码行数:18,代码来源:views.py

示例14: answer_question

# 需要导入模块: from models import Answer [as 别名]
# 或者: from models.Answer import save [as 别名]
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,代码行数:18,代码来源:views.py

示例15: handleForm

# 需要导入模块: from models import Answer [as 别名]
# 或者: from models.Answer import save [as 别名]
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,代码行数:18,代码来源:views.py


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