本文整理汇总了Python中questions.events.QuestionSolvedEvent.notify方法的典型用法代码示例。如果您正苦于以下问题:Python QuestionSolvedEvent.notify方法的具体用法?Python QuestionSolvedEvent.notify怎么用?Python QuestionSolvedEvent.notify使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类questions.events.QuestionSolvedEvent
的用法示例。
在下文中一共展示了QuestionSolvedEvent.notify方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_solution_notification
# 需要导入模块: from questions.events import QuestionSolvedEvent [as 别名]
# 或者: from questions.events.QuestionSolvedEvent import notify [as 别名]
def test_solution_notification(self, get_current):
"""Assert that hitting the watch toggle toggles and that proper mails
are sent to anonymous and registered watchers."""
# TODO: Too monolithic. Split this test into several.
get_current.return_value.domain = 'testserver'
question = self._toggle_watch_question('solution', turn_on=True)
QuestionSolvedEvent.notify('[email protected]', question)
answer = question.answers.all()[0]
# Post a reply
self.client.login(username='jsocol', password='testpass')
post(self.client, 'questions.solution', args=[question.id, answer.id])
# Order of emails is not important.
attrs_eq(mail.outbox[0], to=['[email protected]'],
subject='Solution found to Firefox Help question')
starts_with(mail.outbox[0].body, SOLUTION_EMAIL % answer.id)
attrs_eq(mail.outbox[1], to=['[email protected]'],
subject='Solution found to Firefox Help question')
starts_with(mail.outbox[1].body,
SOLUTION_EMAIL_TO_ANONYMOUS % answer.id)
self._toggle_watch_question('solution', turn_on=False)
示例2: test_watch_solution_and_replies
# 需要导入模块: from questions.events import QuestionSolvedEvent [as 别名]
# 或者: from questions.events.QuestionSolvedEvent import notify [as 别名]
def test_watch_solution_and_replies(self):
"""User subscribes to solution and replies: page doesn't break"""
self.client.login(username="rrosario", password="testpass")
user = User.objects.get(username="rrosario")
QuestionReplyEvent.notify(user, self.question)
QuestionSolvedEvent.notify(user, self.question)
response = get(self.client, "questions.answers", args=[self.question.id])
eq_(200, response.status_code)
示例3: watch_question
# 需要导入模块: from questions.events import QuestionSolvedEvent [as 别名]
# 或者: from questions.events.QuestionSolvedEvent import notify [as 别名]
def watch_question(request, question_id):
"""Start watching a question for replies or solution."""
question = get_object_or_404(Question, pk=question_id)
form = WatchQuestionForm(request.user, request.POST)
# Process the form
msg = None
if form.is_valid():
user_or_email = (request.user if request.user.is_authenticated()
else form.cleaned_data['email'])
try:
if form.cleaned_data['event_type'] == 'reply':
QuestionReplyEvent.notify(user_or_email, question)
else:
QuestionSolvedEvent.notify(user_or_email, question)
except ActivationRequestFailed:
msg = _('Could not send message to that email address.')
# Respond to ajax request
if request.is_ajax():
if form.is_valid():
if not msg:
msg = (_('You will be notified of updates by email.') if
request.user.is_authenticated() else
_('You should receive an email shortly '
'to confirm your subscription.'))
return HttpResponse(json.dumps({'message': msg}))
if request.POST.get('from_vote'):
tmpl = 'questions/includes/question_vote_thanks.html'
else:
tmpl = 'questions/includes/email_subscribe.html'
html = jingo.render_to_string(request, tmpl, {'question': question,
'watch_form': form})
return HttpResponse(json.dumps({'html': html}))
# Respond to normal request
# TODO: show failure here if email fails to send.
if form.is_valid():
return HttpResponseRedirect(question.get_absolute_url())
return answers(request, question.id, watch_form=form)
示例4: watch_question
# 需要导入模块: from questions.events import QuestionSolvedEvent [as 别名]
# 或者: from questions.events.QuestionSolvedEvent import notify [as 别名]
def watch_question(request, question_id):
"""Start watching a question for replies or solution."""
question = get_object_or_404(Question, pk=question_id)
form = WatchQuestionForm(request.user, request.POST)
# Process the form
msg = None
if form.is_valid():
user_or_email = request.user if request.user.is_authenticated() else form.cleaned_data["email"]
try:
if form.cleaned_data["event_type"] == "reply":
QuestionReplyEvent.notify(user_or_email, question)
else:
QuestionSolvedEvent.notify(user_or_email, question)
statsd.incr("questions.watches.new")
except ActivationRequestFailed:
msg = _("Could not send a message to that email address.")
# Respond to ajax request
if request.is_ajax():
if form.is_valid():
msg = msg or (
_("You will be notified of updates by email.")
if request.user.is_authenticated()
else _("You should receive an email shortly " "to confirm your subscription.")
)
return HttpResponse(json.dumps({"message": msg}))
if request.POST.get("from_vote"):
tmpl = "questions/includes/question_vote_thanks.html"
else:
tmpl = "questions/includes/email_subscribe.html"
html = jingo.render_to_string(request, tmpl, {"question": question, "watch_form": form})
return HttpResponse(json.dumps({"html": html}))
if msg:
messages.add_message(request, messages.ERROR, msg)
return HttpResponseRedirect(question.get_absolute_url())
示例5: watch_question
# 需要导入模块: from questions.events import QuestionSolvedEvent [as 别名]
# 或者: from questions.events.QuestionSolvedEvent import notify [as 别名]
def watch_question(request, question_id):
"""Start watching a question for replies or solution."""
question = get_object_or_404(Question, pk=question_id)
form = WatchQuestionForm(request.user, request.POST)
# Process the form
msg = None
if form.is_valid():
user_or_email = (request.user if request.user.is_authenticated()
else form.cleaned_data['email'])
try:
QuestionSolvedEvent.notify(user_or_email, question)
statsd.incr('questions.watches.new')
except ActivationRequestFailed:
msg = _('Could not send a message to that email address.')
# Respond to ajax request
if request.is_ajax():
if form.is_valid():
msg = msg or (_('You will be notified of updates by email.') if
request.user.is_authenticated() else
_('You should receive an email shortly '
'to confirm your subscription.'))
return HttpResponse(json.dumps({'message': msg}))
html = jingo.render_to_string(
request,
'questions/includes/question_vote_thanks.html',
{'question': question, 'watch_form': form})
return HttpResponse(json.dumps({'html': html}))
if msg:
messages.add_message(request, messages.ERROR, msg)
return HttpResponseRedirect(question.get_absolute_url())
示例6: test_solution_notification_deleted
# 需要导入模块: from questions.events import QuestionSolvedEvent [as 别名]
# 或者: from questions.events.QuestionSolvedEvent import notify [as 别名]
def test_solution_notification_deleted(self, get_current):
"""Calling QuestionSolvedEvent.fire() should not query the
questions_question table.
This test attempts to simulate the replication lag presumed to cause
bug 585029.
"""
get_current.return_value.domain = 'testserver'
answer = Answer.objects.get(pk=1)
question = Question.objects.get(pk=1)
question.solution = answer
question.save()
a_user = User.objects.get(username='pcraciunoiu')
QuestionSolvedEvent.notify(a_user, question)
event = QuestionSolvedEvent(answer)
# Delete the question, pretend it hasn't been replicated yet
Question.objects.get(pk=question.pk).delete()
event.fire(exclude=question.creator)
eq_(1, len(mail.outbox))