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


Python models.Answer类代码示例

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


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

示例1: test_percent

    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,代码行数:26,代码来源:test_api.py

示例2: test_creator_num_answers

    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,代码行数:7,代码来源:test_models.py

示例3: update

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,代码行数:25,代码来源:views.py

示例4: create_answer

 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,代码行数:7,代码来源:filldata.py

示例5: test_creator_num_answers

    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,代码行数:11,代码来源:test_models.py

示例6: post

    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,代码行数:12,代码来源:views.py

示例7: create_answer

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,代码行数:14,代码来源:migrate_questions.py

示例8: handle

    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,代码行数:47,代码来源:addRandomQuestion.py

示例9: test_delete_answer_removes_flag

    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,代码行数:18,代码来源:test_models.py

示例10: test_delete_last_answer_of_question

    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,代码行数:19,代码来源:test_models.py

示例11: reply

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,代码行数:43,代码来源:views.py

示例12: test_new_answer_updates_question

    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,代码行数:20,代码来源:test_models.py

示例13: apply_answer

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,代码行数:13,代码来源:views.py

示例14: new

def new(request):
    if request.method != 'POST':
        return return_json(post_error)

    question_text, answers, correct_index = edit_post_vars(request)

    q = Question(question=question_text)
    q.save()

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

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

示例15: add_answer_to_db

    def add_answer_to_db(self, tweet):
        question = Question.objects.get_current_question()
        person = Person.objects.filter(twitter_username=tweet.user.screen_name)

        #TODO: could this sort of logic be moved to the model?
        if not person:
            # Get the users real name
            user = self.twitter_api.GetUser(tweet.user.screen_name)
            full_name_list = user.name.split(" ")
            first_name = full_name_list[0]
            middle_names = " ".join(full_name_list[1:-1])
            if len(full_name_list) > 1:
                surname = full_name_list[-1]
            else:
                surname = ""

            person = Person(twitter_username=tweet.user.screen_name,
                first_name=first_name,
                middle_names=middle_names,
                surname=surname)
            person.save()
        else:
            # get person from the query set.
            # Inelegant could this be modified with custom save() on the model?
            person = person[0]

        # Remove @FavouriteQueston from the tweet (+2 is for @ and space)
        answer_text = tweet.text[len(self.twitter_account) + 2:]
        # Decode HTML encoded entities from Twitter
        h = HTMLParser.HTMLParser()
        answer_text = h.unescape(answer_text)

        a = Answer(answer_text=answer_text,
                   person=person,
                   question=question,
                   tweet_id=tweet.id)
        a.save()
开发者ID:GuntLondon,项目名称:favouriteQ,代码行数:37,代码来源:search_twitter.py


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