本文整理汇总了Python中questions.events.QuestionReplyEvent类的典型用法代码示例。如果您正苦于以下问题:Python QuestionReplyEvent类的具体用法?Python QuestionReplyEvent怎么用?Python QuestionReplyEvent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QuestionReplyEvent类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_watch_solution_and_replies
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)
开发者ID:Apokalyptica79,项目名称:kitsune,代码行数:8,代码来源:test_templates.py
示例2: test_no_notification_on_update
def test_no_notification_on_update(self):
"""Saving an existing question does not watch it."""
q = Question.objects.get(pk=1)
assert not QuestionReplyEvent.is_notifying(q.creator, q)
q.save()
assert not QuestionReplyEvent.is_notifying(q.creator, q)
开发者ID:Akamad007,项目名称:kitsune,代码行数:8,代码来源:test_models.py
示例3: unsubscribe_watch
def unsubscribe_watch(request, watch_id, secret):
"""Stop watching a question, for anonymous users."""
watch = get_object_or_404(Watch, pk=watch_id)
question = watch.content_object
success = False
if watch.secret == secret and isinstance(question, Question):
user_or_email = watch.user or watch.email
QuestionReplyEvent.stop_notifying(user_or_email, question)
QuestionSolvedEvent.stop_notifying(user_or_email, question)
success = True
return jingo.render(request, "questions/unsubscribe_watch.html", {"question": question, "success": success})
开发者ID:fox2mike,项目名称:kitsune,代码行数:12,代码来源:views.py
示例4: save
def save(self, no_update=False, *args, **kwargs):
"""Override save method to take care of updated."""
new = not self.id
if not new and not no_update:
self.updated = datetime.now()
super(Question, self).save(*args, **kwargs)
if new:
# Avoid circular import, events.py imports Question
from questions.events import QuestionReplyEvent
# Authors should automatically watch their own questions.
QuestionReplyEvent.notify(self.creator, self)
开发者ID:bowmasters,项目名称:kitsune,代码行数:14,代码来源:models.py
示例5: _answers_data
def _answers_data(request, question_id, form=None, watch_form=None,
answer_preview=None):
"""Return a map of the minimal info necessary to draw an answers page."""
question = get_object_or_404(Question, pk=question_id)
answers_ = question.answers.all()
if not request.MOBILE:
answers_ = paginate(request, answers_,
per_page=constants.ANSWERS_PER_PAGE)
feed_urls = ((reverse('questions.answers.feed',
kwargs={'question_id': question_id}),
AnswersFeed().title(question)),)
frequencies = dict(FREQUENCY_CHOICES)
is_watching_question = (
request.user.is_authenticated() and (
QuestionReplyEvent.is_notifying(request.user, question) or
QuestionSolvedEvent.is_notifying(request.user, question)))
return {'question': question,
'answers': answers_,
'form': form or AnswerForm(),
'answer_preview': answer_preview,
'watch_form': watch_form or _init_watch_form(request, 'reply'),
'feeds': feed_urls,
'frequencies': frequencies,
'is_watching_question': is_watching_question,
'can_tag': request.user.has_perm('questions.tag_question'),
'can_create_tags': request.user.has_perm('taggit.add_tag')}
开发者ID:victorneo,项目名称:kitsune,代码行数:27,代码来源:views.py
示例6: _answers_data
def _answers_data(request, question_id, form=None, watch_form=None, answer_preview=None):
"""Return a map of the minimal info necessary to draw an answers page."""
question = get_object_or_404(Question, pk=question_id)
answers_ = paginate(request, question.answers.all(), per_page=constants.ANSWERS_PER_PAGE)
vocab = [t.name for t in Tag.objects.all()] # TODO: Fetch only name.
feed_urls = (
(reverse("questions.answers.feed", kwargs={"question_id": question_id}), AnswersFeed().title(question)),
)
frequencies = dict(FREQUENCY_CHOICES)
is_watching_question = request.user.is_authenticated() and (
QuestionReplyEvent.is_notifying(request.user, question)
or QuestionSolvedEvent.is_notifying(request.user, question)
)
return {
"question": question,
"answers": answers_,
"form": form or AnswerForm(),
"answer_preview": answer_preview,
"watch_form": watch_form or _init_watch_form(request, "reply"),
"feeds": feed_urls,
"tag_vocab": json.dumps(vocab),
"frequencies": frequencies,
"is_watching_question": is_watching_question,
"can_tag": request.user.has_perm("questions.tag_question"),
"can_create_tags": request.user.has_perm("taggit.add_tag"),
}
开发者ID:fox2mike,项目名称:kitsune,代码行数:27,代码来源:views.py
示例7: test_notification_created
def test_notification_created(self):
"""Creating a new question auto-watches it for answers."""
u = User.objects.get(pk=118533)
q = Question(creator=u, title='foo', content='bar')
q.save()
assert QuestionReplyEvent.is_notifying(u, q)
开发者ID:Akamad007,项目名称:kitsune,代码行数:8,代码来源:test_models.py
示例8: test_watch_replies_logged_in
def test_watch_replies_logged_in(self):
"""Watch a question for replies (logged in)."""
self.client.login(username='rrosario', password='testpass')
user = User.objects.get(username='rrosario')
post(self.client, 'questions.watch',
{'event_type': 'reply'},
args=[self.question.id])
assert QuestionReplyEvent.is_notifying(user, self.question), (
'Watch was not created')
开发者ID:jledbetter,项目名称:kitsune,代码行数:9,代码来源:test_templates.py
示例9: test_unwatch
def test_unwatch(self):
"""Unwatch a question."""
# First watch question.
self.test_watch_replies_logged_in()
# Then unwatch it.
self.client.login(username="rrosario", password="testpass")
user = User.objects.get(username="rrosario")
post(self.client, "questions.unwatch", args=[self.question.id])
assert not QuestionReplyEvent.is_notifying(user, self.question), "Watch was not destroyed"
开发者ID:Apokalyptica79,项目名称:kitsune,代码行数:9,代码来源:test_templates.py
示例10: test_watch_replies_smtp_error
def test_watch_replies_smtp_error(self, emailmessage_send):
"""Watch a question for replies and fail to send email."""
emailmessage_send.side_effect = emailmessage_raise_smtp
self.client.logout()
r = post(
self.client, "questions.watch", {"email": "[email protected]", "event_type": "reply"}, args=[self.question.id]
)
assert not QuestionReplyEvent.is_notifying("[email protected]", self.question), "Watch was created"
self.assertContains(r, "Could not send a message to that email")
开发者ID:Apokalyptica79,项目名称:kitsune,代码行数:10,代码来源:test_templates.py
示例11: test_answer_notification
def test_answer_notification(self, get_current):
"""Assert that hitting the watch toggle toggles and that proper mails
are sent to anonymous users, registered users, and the question
asker."""
# TODO: This test is way too monolithic, and the fixtures encode
# assumptions that aren't obvious here. Split this test into about 5,
# each of which tests just 1 thing. Consider using instantiation
# helpers.
get_current.return_value.domain = 'testserver'
# An arbitrary registered user (pcraciunoiu) watches:
question = self._toggle_watch_question('reply', turn_on=True)
# An anonymous user watches:
QuestionReplyEvent.notify('[email protected]', question)
# The question asker (jsocol) watches:
QuestionReplyEvent.notify(question.creator, question)
# Post a reply
self.client.login(username='rrosario', password='testpass')
post(self.client, 'questions.reply', {'content': 'an answer'},
args=[question.id])
answer = Answer.uncached.filter().order_by('-id')[0]
# Order of emails is not important.
attrs_eq(mail.outbox[0], to=['[email protected]'],
subject='%s commented on a Firefox question '
"you're watching" % answer.creator.username)
starts_with(mail.outbox[0].body, ANSWER_EMAIL.format(answer=answer.id))
attrs_eq(mail.outbox[1], to=[question.creator.email],
subject='%s posted an answer to your question "%s"' %
(answer.creator.username, question.title))
starts_with(mail.outbox[1].body, ANSWER_EMAIL_TO_ASKER.format(
answer=answer.id))
attrs_eq(mail.outbox[2], to=['[email protected]'],
subject="%s commented on a Firefox question you're watching" %
answer.creator.username)
starts_with(mail.outbox[2].body, ANSWER_EMAIL_TO_ANONYMOUS.format(
answer=answer.id))
self._toggle_watch_question('reply', turn_on=False)
开发者ID:DWDRAEGER,项目名称:kitsune,代码行数:43,代码来源:test_notifications.py
示例12: test_autowatch_reply
def test_autowatch_reply(self, get_current):
get_current.return_value.domain = 'testserver'
user = User.objects.get(username='timw')
t1, t2 = Question.objects.filter(is_locked=False)[0:2]
assert not QuestionReplyEvent.is_notifying(user, t1)
assert not QuestionReplyEvent.is_notifying(user, t2)
self.client.login(username='timw', password='testpass')
s = Setting.objects.create(user=user, name='questions_watch_after_reply',
value='True')
data = {'content': 'some content'}
post(self.client, 'questions.reply', data, args=[t1.id])
assert QuestionReplyEvent.is_notifying(user, t1)
s.value = 'False'
s.save()
post(self.client, 'questions.reply', data, args=[t2.id])
assert not QuestionReplyEvent.is_notifying(user, t2)
开发者ID:readevalprint,项目名称:kitsune,代码行数:19,代码来源:test_notifications.py
示例13: save
def save(self, no_update=False, *args, **kwargs):
"""Override save method to take care of updated."""
new = not self.id
if not new and not no_update:
self.updated = datetime.now()
# Generate a confirmation_id if necessary
if new and not self.confirmation_id:
chars = [random.choice(string.ascii_letters) for x in xrange(10)]
self.confirmation_id = "".join(chars)
super(Question, self).save(*args, **kwargs)
if new:
# Avoid circular import, events.py imports Question
from questions.events import QuestionReplyEvent
# Authors should automatically watch their own questions.
QuestionReplyEvent.notify(self.creator, self)
开发者ID:Akamad007,项目名称:kitsune,代码行数:19,代码来源:models.py
示例14: reply
def reply(request, question_id):
"""Post a new answer to a question."""
question = get_object_or_404(Question, pk=question_id)
answer_preview = None
if question.is_locked:
raise PermissionDenied
form = AnswerForm(request.POST)
# NOJS: delete images
if 'delete_images' in request.POST:
for image_id in request.POST.getlist('delete_image'):
ImageAttachment.objects.get(pk=image_id).delete()
return answers(request, question_id=question_id, form=form)
# NOJS: upload image
if 'upload_image' in request.POST:
upload_imageattachment(request, question)
return answers(request, question_id=question_id, form=form)
if form.is_valid():
answer = Answer(question=question, creator=request.user,
content=form.cleaned_data['content'])
if 'preview' in request.POST:
answer_preview = answer
else:
answer.save()
ct = ContentType.objects.get_for_model(answer)
# Move over to the answer all of the images I added to the
# reply form
up_images = question.images.filter(creator=request.user)
up_images.update(content_type=ct, object_id=answer.id)
statsd.incr('questions.answer')
if Setting.get_for_user(request.user,
'questions_watch_after_reply'):
QuestionReplyEvent.notify(request.user, question)
return HttpResponseRedirect(answer.get_absolute_url())
return answers(request, question_id=question_id, form=form,
answer_preview=answer_preview)
开发者ID:lonnen,项目名称:kitsune,代码行数:43,代码来源:views.py
示例15: watch_question
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)
开发者ID:GPHemsley,项目名称:kuma,代码行数:43,代码来源:views.py
示例16: test_watch_replies_smtp_error
def test_watch_replies_smtp_error(self, emailmessage_send):
"""Watch a question for replies and fail to send email."""
emailmessage_send.side_effect = emailmessage_raise_smtp
self.client.logout()
r = post(self.client, 'questions.watch',
{'email': '[email protected]', 'event_type': 'reply'},
args=[self.question.id])
assert not QuestionReplyEvent.is_notifying(
'[email protected]', self.question), 'Watch was created'
self.assertContains(r, 'Could not send a message to that email')
开发者ID:jledbetter,项目名称:kitsune,代码行数:11,代码来源:test_templates.py
示例17: watch_question
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())
开发者ID:fox2mike,项目名称:kitsune,代码行数:41,代码来源:views.py
示例18: test_watch_replies
def test_watch_replies(self, get_current):
"""Watch a question for replies."""
get_current.return_value.domain = "testserver"
self.client.logout()
post(self.client, "questions.watch", {"email": "[email protected]", "event_type": "reply"}, args=[self.question.id])
assert QuestionReplyEvent.is_notifying("[email protected]", self.question), "Watch was not created"
attrs_eq(mail.outbox[0], to=["[email protected]"], subject="Please confirm your email address")
assert "questions/confirm/" in mail.outbox[0].body
assert "New answers" in mail.outbox[0].body
# Now activate the watch.
w = Watch.objects.get()
get(self.client, "questions.activate_watch", args=[w.id, w.secret])
assert Watch.objects.get().is_active
开发者ID:Apokalyptica79,项目名称:kitsune,代码行数:16,代码来源:test_templates.py
示例19: test_watch_replies
def test_watch_replies(self, get_current):
"""Watch a question for replies."""
get_current.return_value.domain = 'testserver'
self.client.logout()
post(self.client, 'questions.watch',
{'email': '[email protected]', 'event_type': 'reply'},
args=[self.question.id])
assert QuestionReplyEvent.is_notifying('[email protected]', self.question), (
'Watch was not created')
attrs_eq(mail.outbox[0], to=['[email protected]'],
subject='Please confirm your email address')
assert 'questions/confirm/' in mail.outbox[0].body
assert 'New answers' in mail.outbox[0].body
# Now activate the watch.
w = Watch.objects.get()
get(self.client, 'questions.activate_watch', args=[w.id, w.secret])
assert Watch.objects.get().is_active
开发者ID:jledbetter,项目名称:kitsune,代码行数:20,代码来源:test_templates.py
示例20: unwatch_question
def unwatch_question(request, question_id):
"""Stop watching a question."""
question = get_object_or_404(Question, pk=question_id)
QuestionReplyEvent.stop_notifying(request.user, question)
QuestionSolvedEvent.stop_notifying(request.user, question)
return HttpResponseRedirect(question.get_absolute_url())
开发者ID:victorneo,项目名称:kitsune,代码行数:6,代码来源:views.py
注:本文中的questions.events.QuestionReplyEvent类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论