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


Python QuestionVote.add_metadata方法代码示例

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


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

示例1: question_vote

# 需要导入模块: from questions.models import QuestionVote [as 别名]
# 或者: from questions.models.QuestionVote import add_metadata [as 别名]
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:victorneo,项目名称:kitsune,代码行数:30,代码来源:views.py

示例2: question_vote

# 需要导入模块: from questions.models import QuestionVote [as 别名]
# 或者: from questions.models.QuestionVote import add_metadata [as 别名]
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:pablocubico,项目名称:kitsune,代码行数:37,代码来源:views.py


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