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