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


Python models.QuestionVote类代码示例

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


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

示例1: test_vote_updates_count

    def test_vote_updates_count(self):
        q = Question.objects.all()[0]
        eq_(0, q.num_votes_past_week)

        vote = QuestionVote(question=q, anonymous_id='abc123')
        vote.save()
        eq_(1, q.num_votes_past_week)
开发者ID:trinaldi,项目名称:kitsune,代码行数:7,代码来源:test_votes.py

示例2: question_vote

def question_vote(request, question_id):
    """I have this problem too."""
    question = get_object_or_404(Question, pk=question_id)
    if question.is_locked:
        raise PermissionDenied

    if not question.has_voted(request):
        vote = QuestionVote(question=question)

        if request.user.is_authenticated():
            vote.creator = request.user
        else:
            vote.anonymous_id = request.anonymous.anonymous_id

        vote.save()
        statsd.incr('questions.votes.question')

        if request.is_ajax():
            tmpl = 'questions/includes/question_vote_thanks.html'
            form = _init_watch_form(request)
            html = jingo.render_to_string(request, tmpl, {'question': question,
                                                          'watch_form': form})
            return HttpResponse(json.dumps({'html': html}))

    return HttpResponseRedirect(question.get_absolute_url())
开发者ID:jledbetter,项目名称:kitsune,代码行数:25,代码来源:views.py

示例3: test_sort

    def test_sort(self):
        default = reverse('questions.questions')
        sorted = urlparams(default, sort='requested')

        q = Question.objects.get(pk=2)
        qv = QuestionVote(question=q, anonymous_id='abc123')
        qv.save()

        response = self.client.get(default)
        doc = pq(response.content)
        eq_('question-1', doc('ol.questions li')[0].attrib['id'])

        response = self.client.get(sorted)
        doc = pq(response.content)
        eq_('question-2', doc('ol.questions li')[0].attrib['id'])
开发者ID:MechanisM,项目名称:kitsune,代码行数:15,代码来源:test_templates.py

示例4: question_vote

def question_vote(request, question_id):
    """I have this problem too."""
    question = get_object_or_404(Question, pk=question_id)
    if question.is_locked:
        raise PermissionDenied

    if not question.has_voted(request):
        vote = QuestionVote(question=question)

        if request.user.is_authenticated():
            vote.creator = request.user
        else:
            vote.anonymous_id = request.anonymous.anonymous_id

        vote.save()
        ua = request.META.get("HTTP_USER_AGENT")
        if ua:
            vote.add_metadata("ua", ua[:1000])  # 1000 max_length
        statsd.incr("questions.votes.question")

        if request.is_ajax():
            tmpl = "questions/includes/question_vote_thanks.html"
            form = _init_watch_form(request)
            html = jingo.render_to_string(request, tmpl, {"question": question, "watch_form": form})
            return HttpResponse(json.dumps({"html": html}))

    return HttpResponseRedirect(question.get_absolute_url())
开发者ID:fox2mike,项目名称:kitsune,代码行数:27,代码来源:views.py

示例5: question_vote

def question_vote(request, question_key, upvote):
    question = get_object_or_404(Question, key=question_key)
    user = users.get_current_user()

    # check it not already voted..
    vote = QuestionVote.all() \
            .filter('question =', question).filter('user =', user).get()

    if vote is None:
        vote = QuestionVote(question=question, user=user, upvote=upvote)
        vote.put()
        question.score += 1 if upvote else -1
        question.put()
    else:
        logging.info('Duplicated vote: %s;;%s', question, user)

    redirect_url = request.META.get('HTTP_REFERER', None)
    if redirect_url is None:
        logging.warning('No referer. Fallback to questions list')
        redirect_url = reverse('questions_question_list')
    return redirect(redirect_url)
开发者ID:kichawa,项目名称:Archquestions,代码行数:21,代码来源:views.py

示例6: question_vote

def question_vote(request, question_id):
    """I have this problem too."""
    question = get_object_or_404(Question, pk=question_id)
    if question.is_locked:
        raise PermissionDenied

    if not question.has_voted(request):
        vote = QuestionVote(question=question)

        if request.user.is_authenticated():
            vote.creator = request.user
        else:
            vote.anonymous_id = request.anonymous.anonymous_id

        vote.save()

        if 'referrer' in request.REQUEST:
            referrer = request.REQUEST.get('referrer')
            vote.add_metadata('referrer', referrer)

            if referrer == 'search' and 'query' in request.REQUEST:
                vote.add_metadata('query', request.REQUEST.get('query'))

        ua = request.META.get('HTTP_USER_AGENT')
        if ua:
            vote.add_metadata('ua', ua[:1000])  # 1000 max_length
        statsd.incr('questions.votes.question')

        if request.is_ajax():
            tmpl = 'questions/includes/question_vote_thanks.html'
            form = WatchQuestionForm(request.user)
            html = jingo.render_to_string(request, tmpl, {'question': question,
                                                          'watch_form': form})
            return HttpResponse(json.dumps({'html': html}))

    return HttpResponseRedirect(question.get_absolute_url())
开发者ID:lonnen,项目名称:kitsune,代码行数:36,代码来源:views.py


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