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


Python Answer.save方法代码示例

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


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

示例1: doimport

# 需要导入模块: from questions.models import Answer [as 别名]
# 或者: from questions.models.Answer import save [as 别名]
    def doimport(self,data):

        from django.contrib.auth.models import User
        from questions.models import Question, Answer
        from tagging.models import Tag
    
        try:
            question = Question()
            question.content = data['question']
            question.tags = data['tags']
            question.author = User.objects.get(pk=0) #FIXME: System smrtr user: use constant?
            question.save() # Save to allow m2m

            # Create correct answer
            c = Answer()
            c.content = data['correct']
            c.is_correct = True
            c.question = question
            c.save()
            
            # Save incorrect answers
            data['incorrect'] = filter(lambda x: len(x)>0, data['incorrect']) # Remove empty items
            for incorrect in data['incorrect']:
                ic = Answer()
                ic.content = incorrect
                ic.is_correct = False
                ic.question = question
                ic.save()
        except:
            print "Error importing:" + data['question']    
开发者ID:mfitzp,项目名称:smrtr,代码行数:32,代码来源:import_questions.py

示例2: test_creator_num_answers

# 需要导入模块: from questions.models import Answer [as 别名]
# 或者: from questions.models.Answer import save [as 别名]
    def test_creator_num_answers(self):
        question = Question.objects.all()[0]
        answer = Answer(question=question, creator_id=47963,
                        content="Test Answer")
        answer.save()

        eq_(answer.creator_num_answers, 2)
开发者ID:Curlified,项目名称:kitsune,代码行数:9,代码来源:test_models.py

示例3: update

# 需要导入模块: from questions.models import Answer [as 别名]
# 或者: from questions.models.Answer import save [as 别名]
def update(request, id):
    if request.method != 'POST':
        return return_json(post_error, 400)


    question_text, answers, correct_index = edit_post_vars(request)

    q = Question.objects.get(pk=id)
    q.question = question_text
    q.save()

    q.answer_set.all().delete()

    i=0;
    for answer in answers:
        a = Answer(question=q, choice=answer, correct=(i == correct_index))
        a.save()
        i += 1

    data = {
        'result': 'success',
        'id': id,
    }
    json_result = json.JSONEncoder().encode(data)
    return return_json(json_result)
开发者ID:agronick,项目名称:WebServiceExample,代码行数:27,代码来源:views.py

示例4: test_percent

# 需要导入模块: from questions.models import Answer [as 别名]
# 或者: from questions.models.Answer import save [as 别名]
    def test_percent(self, switch_is_active):
        """Test user API with all defaults."""
        switch_is_active.return_value = True
        u = user()
        u.save()
        add_permission(u, Profile, 'view_kpi_dashboard')
        question = Question(title='Test Question',
                            content='Lorem Ipsum Dolor',
                            creator_id=u.id)
        question.save()
        answer = Answer(question=question, creator_id=u.id,
                        content="Test Answer")
        answer.save()

        question.solution = answer
        question.save()

        url = reverse('api_dispatch_list',
                      kwargs={'resource_name': 'kpi_solution',
                              'api_name': 'v1'})
        self.client.login(username=u.username, password='testpass')
        response = self.client.get(url + '?format=json')
        eq_(200, response.status_code)
        r = json.loads(response.content)
        eq_(r['objects'][0]['with_solutions'], 1)
        eq_(r['objects'][0]['without_solutions'], 0)
开发者ID:erikrose,项目名称:kitsune,代码行数:28,代码来源:test_api.py

示例5: create_answer

# 需要导入模块: from questions.models import Answer [as 别名]
# 或者: from questions.models.Answer import save [as 别名]
 def create_answer(self, name):
     question = Question.objects.order_by("?")[:1][0]
     author = UserWithAvatar.objects.order_by("?")[:1][0]
     pub_date = timezone.now()
     text = self.lorem
     answer = Answer(question=question, author=author, pub_date=pub_date, text=text)
     answer.save()
开发者ID:Oktosha,项目名称:askPupkin,代码行数:9,代码来源:filldata.py

示例6: test_creator_num_answers

# 需要导入模块: from questions.models import Answer [as 别名]
# 或者: from questions.models.Answer import save [as 别名]
    def test_creator_num_answers(self):
        """Test retrieval of answer count for creator of a particular answer"""
        question = Question.objects.all()[0]
        answer = Answer(question=question, creator_id=47963,
                        content="Test Answer")
        answer.save()

        question.solution = answer
        question.save()

        eq_(answer.creator_num_answers, 1)
开发者ID:Akamad007,项目名称:kitsune,代码行数:13,代码来源:test_models.py

示例7: post

# 需要导入模块: from questions.models import Answer [as 别名]
# 或者: from questions.models.Answer import save [as 别名]
    def post(self, request, *args, **kwargs):
        survey = Survey.objects.filter(id=self.kwargs['pk']).first()

        for question_id, option_id in request.POST.items():
            if question_id.isdigit():
                question = Question.objects.filter(id=question_id).first()
                option = Option.objects.filter(id=option_id).first()
                if question and option:
                    answer = Answer(option=option, user=None if request.user.is_anonymous() else request.user)
                    answer.save()

        return HttpResponseRedirect("/survey/%d/results/" %(survey.id))
开发者ID:Imaansadath,项目名称:surveychamp,代码行数:14,代码来源:views.py

示例8: apply_answer

# 需要导入模块: from questions.models import Answer [as 别名]
# 或者: from questions.models.Answer import save [as 别名]
def apply_answer(question, answer, user):
    try:
        a = Answer.objects.get(question=question, user=user)
    except:
        if answer != "0":
            a = Answer(question=question, user=user, answer=answer)
            a.save()
    else:
        if answer == "0":
            a.delete()
        else:
            a.answer = answer
            a.save()
开发者ID:onurmatik,项目名称:kimlerdensin,代码行数:15,代码来源:views.py

示例9: create_answer

# 需要导入模块: from questions.models import Answer [as 别名]
# 或者: from questions.models.Answer import save [as 别名]
def create_answer(question, tiki_post, tiki_thread):
    """Create an answer to a question from a Tiki post."""
    creator = get_django_user(tiki_post)
    created = datetime.fromtimestamp(tiki_post.commentDate)
    content = converter.convert(tiki_post.data)

    ans = Answer(question=question, creator=creator, content=content, created=created, updated=created)
    ans.save(no_update=True, no_notify=True)  # don't send a reply notification

    # Set answer as solution
    if tiki_post.type == "o" and tiki_thread.type == "o":
        question.solution = ans

    return ans
开发者ID:sgarrity,项目名称:kitsune,代码行数:16,代码来源:migrate_questions.py

示例10: handle

# 需要导入模块: from questions.models import Answer [as 别名]
# 或者: from questions.models.Answer import save [as 别名]
    def handle(self, *args, **options):
        i = 0
        k = 0
        n = int(args[0])
        allusers = UserProfile.objects.all()
        tags = Tag.objects.all()
        while i < n:
            titleNumber = random.randint(0, 50)
            textNumber = random.randint(0, 300)
            rate = random.randint(-100, 100)
            number = random.randint(0, 10)

            numberOfTags = random.randint(0, 5)
            tagsList = []
            for q in range(0, numberOfTags):
                randomTag = random.randint(0, len(tags) - 1)
                tagsList.insert(q, tags[randomTag])

            title = "".join(
                random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits + string.whitespace)
                for x in range(titleNumber)
            )
            token = "".join(
                random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits + string.whitespace)
                for x in range(textNumber)
            )
            i = i + 1

            randomUserId = random.randint(0, len(allusers) - 1)
            user = allusers[randomUserId]

            q = Question(title=title, text=token, rate=rate, author=user)
            q.save()
            q.tags.add(*tagsList)

            for j in range(0, number):
                randomUserId = random.randint(0, len(allusers) - 1)
                userComment = allusers[randomUserId]
                rateComment = random.randint(-100, 100)
                textComment = random.randint(0, 300)
                text = "".join(
                    random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits + string.whitespace)
                    for x in range(textComment)
                )
                k = k + 1
                a = Answer(k, text=text, rate=rateComment, answers_question=q, author=userComment)
                a.save()
开发者ID:Zanexess,项目名称:AskingHeapProject,代码行数:49,代码来源:addRandomQuestion.py

示例11: answer

# 需要导入模块: from questions.models import Answer [as 别名]
# 或者: from questions.models.Answer import save [as 别名]
def answer(request):
    if request.method == 'POST':
        form = AnswerForm(request.POST)
        if form.is_valid():
            user = request.user
            answer = Answer()
            answer.user = request.user
            answer.question = form.cleaned_data.get('question')
            answer.description = form.cleaned_data.get('description')
            answer.save()
            user.profile.notify_answered(answer.question)
            return redirect(u'/questions/{0}/'.format(answer.question.pk))
        else:
            question = form.cleaned_data.get('question')
            return render(request, 'questions/question.html', {'question': question, 'form': form})
    else:
        return redirect('/questions/')
开发者ID:kngeno,项目名称:gis_kenya,代码行数:19,代码来源:views.py

示例12: test_delete_answer_removes_flag

# 需要导入模块: from questions.models import Answer [as 别名]
# 或者: from questions.models.Answer import save [as 别名]
    def test_delete_answer_removes_flag(self):
        """Deleting an answer also removes the flags on that answer."""
        question = Question(title='Test Question',
                            content='Lorem Ipsum Dolor',
                            creator_id=118533)
        question.save()

        answer = Answer(question=question, creator_id=47963,
                        content="Test Answer")
        answer.save()

        FlaggedObject.objects.create(
            status=0, content_object=answer,
            reason='language', creator_id=118533)
        eq_(1, FlaggedObject.objects.count())

        answer.delete()
        eq_(0, FlaggedObject.objects.count())
开发者ID:Akamad007,项目名称:kitsune,代码行数:20,代码来源:test_models.py

示例13: reply

# 需要导入模块: from questions.models import Answer [as 别名]
# 或者: from questions.models.Answer import save [as 别名]
def reply(request, question_id):
    """Post a new answer to a question."""
    question = get_object_or_404(Question, pk=question_id)
    answer_preview = None
    if question.is_locked:
        raise PermissionDenied

    form = AnswerForm(request.POST)

    # NOJS: delete images
    if 'delete_images' in request.POST:
        for image_id in request.POST.getlist('delete_image'):
            ImageAttachment.objects.get(pk=image_id).delete()

        return answers(request, question_id=question_id, form=form)

    # NOJS: upload image
    if 'upload_image' in request.POST:
        upload_imageattachment(request, question)
        return answers(request, question_id=question_id, form=form)

    if form.is_valid():
        answer = Answer(question=question, creator=request.user,
                        content=form.cleaned_data['content'])
        if 'preview' in request.POST:
            answer_preview = answer
        else:
            answer.save()
            ct = ContentType.objects.get_for_model(answer)
            # Move over to the answer all of the images I added to the
            # reply form
            up_images = question.images.filter(creator=request.user)
            up_images.update(content_type=ct, object_id=answer.id)
            statsd.incr('questions.answer')

            if Setting.get_for_user(request.user,
                                    'questions_watch_after_reply'):
                QuestionReplyEvent.notify(request.user, question)

            return HttpResponseRedirect(answer.get_absolute_url())

    return answers(request, question_id=question_id, form=form,
                   answer_preview=answer_preview)
开发者ID:lonnen,项目名称:kitsune,代码行数:45,代码来源:views.py

示例14: test_delete_last_answer_of_question

# 需要导入模块: from questions.models import Answer [as 别名]
# 或者: from questions.models.Answer import save [as 别名]
    def test_delete_last_answer_of_question(self):
        """Deleting the last_answer of a Question should update the question.
        """
        question = Question.objects.get(pk=1)
        last_answer = question.last_answer

        # add a new answer and verify last_answer updated
        answer = Answer(question=question, creator_id=47963,
                        content="Test Answer")
        answer.save()
        question = Question.objects.get(pk=question.id)

        eq_(question.last_answer.id, answer.id)

        # delete the answer and last_answer should go back to previous value
        answer.delete()
        question = Question.objects.get(pk=question.id)
        eq_(question.last_answer.id, last_answer.id)
        eq_(Answer.objects.filter(pk=answer.id).count(), 0)
开发者ID:Akamad007,项目名称:kitsune,代码行数:21,代码来源:test_models.py

示例15: test_new_answer_updates_question

# 需要导入模块: from questions.models import Answer [as 别名]
# 或者: from questions.models.Answer import save [as 别名]
    def test_new_answer_updates_question(self):
        """Test saving a new answer updates the corresponding question.
        Specifically, last_post and num_replies should update."""
        question = Question(title='Test Question',
                            content='Lorem Ipsum Dolor',
                            creator_id=118533)
        question.save()

        eq_(0, question.num_answers)
        eq_(None, question.last_answer)

        answer = Answer(question=question, creator_id=47963,
                        content="Test Answer")
        answer.save()

        question = Question.objects.get(pk=question.id)
        eq_(1, question.num_answers)
        eq_(answer, question.last_answer)

        question.delete()
开发者ID:Akamad007,项目名称:kitsune,代码行数:22,代码来源:test_models.py


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