本文整理汇总了Python中questions.models.QuestionVote.anonymous_id方法的典型用法代码示例。如果您正苦于以下问题:Python QuestionVote.anonymous_id方法的具体用法?Python QuestionVote.anonymous_id怎么用?Python QuestionVote.anonymous_id使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类questions.models.QuestionVote
的用法示例。
在下文中一共展示了QuestionVote.anonymous_id方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: question_vote
# 需要导入模块: from questions.models import QuestionVote [as 别名]
# 或者: from questions.models.QuestionVote import anonymous_id [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())
示例2: question_vote
# 需要导入模块: from questions.models import QuestionVote [as 别名]
# 或者: from questions.models.QuestionVote import anonymous_id [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())
示例3: question_vote
# 需要导入模块: from questions.models import QuestionVote [as 别名]
# 或者: from questions.models.QuestionVote import anonymous_id [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 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())