本文整理汇总了Python中notification.models.observe函数的典型用法代码示例。如果您正苦于以下问题:Python observe函数的具体用法?Python observe怎么用?Python observe使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了observe函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post_resource_save_handler
def post_resource_save_handler(sender, instance, created, user, **kwargs):
if settings.ENABLE_NOTICES:
resource = instance
project = resource.project
users = [
watch.user
for watch in notification.ObservedItem.objects.filter(
content_type__model="project", object_id=project.id, signal="project_changed"
).select_related("user")
]
for user in users:
try:
notification.ObservedItem.objects.get_for(resource.project, user, "project_changed")
if created:
for signal in resource_signals:
try:
notification.ObservedItem.objects.get_for(resource, user, signal)
except notification.ObservedItem.DoesNotExist:
notification.observe(resource, user, signal, signal)
nt = "project_resource_added"
else:
nt = "project_resource_changed"
project = resource.project
_notify_resourcewatchers(project, resource, nt)
except notification.ObservedItem.DoesNotExist, e:
logger.debug("Watches: %s" % unicode(e))
示例2: observe_toggle
def observe_toggle(request, content_type_id, object_id,
signal, notice_type_label):
success = False
observing = None
try:
content_type = ContentType.objects.get(pk=content_type_id)
observed = content_type.get_object_for_this_type(pk=object_id)
if not is_observing(observed=observed, observer=request.user,
signal=signal):
observe(observed=observed,
observer=request.user,
notice_type_label=notice_type_label,
signal=signal)
observing = True
else:
stop_observing(observed=observed,
observer=request.user,
signal=signal)
observing = False
success = True
except:
pass
return HttpResponse(
json.dumps({"success": success, "observing": observing, }),
mimetype='application/json; charset=utf-8',
status=200
)
示例3: object_comment
def object_comment(sender, instance, created, **kwargs):
if isinstance(instance.content_object, Post):
observed = instance.content_object
signal = notice_type_label = "blog_post_comment"
observer = user = instance.user
# Post.objects.filter(pk=observed.pk).update(updated_at=datetime.now()) # Don't send a signal
if notification and created:
if not notification.is_observing(observed, observer, signal):
notification.observe(observed, observer, notice_type_label, signal)
notice_uid = '{0}_{1}_{2}'.format(
notice_type_label,
Site.objects.get_current().pk,
instance.pk
)
notification.send_observation_notices_for(
observed, signal, extra_context={
"context_object": instance,
"notice_uid": notice_uid,
"user": user,
"post": observed,
"comment": instance
}
)
示例4: change_observers
def change_observers(watch, decision, watcher):
if watch:
if not notification.is_observing(decision, watcher):
notification.observe(decision, watcher, DECISION_CHANGE)
else:
if notification.is_observing(decision, watcher):
notification.stop_observing(decision, watcher)
示例5: comment_signal_handler
def comment_signal_handler(sender, **kwargs):
"""
All watchers of a decision will get a notification informing them of
new comment.
All watchers become observers of the comment.
"""
instance = kwargs.get('instance')
headers = {
'Message-ID': "comment-%[email protected]%s" % (instance.id, Site.objects.get_current().domain),
'In-Reply-To': instance.content_object.get_message_id(),
'References': ' '.join((
instance.content_object.decision.get_message_id(),
instance.content_object.get_message_id()))
}
headers.update(STANDARD_SENDING_HEADERS)
instance.content_object.decision.note_external_modification()
if kwargs.get('created', True):
# Creator gets notified if the comment is edited.
notification.observe(instance, instance.user, 'comment_change')
#All watchers of parent get notified of new comment.
all_observed_items_but_author = list(instance.content_object.decision.watchers.exclude(user=instance.user))
observer_list = [x.user for x in all_observed_items_but_author]
extra_context = dict({"observed": instance})
notification.send(observer_list, "comment_new", extra_context, headers, from_email=instance.content_object.decision.get_email())
else:
send_observation_notices_for(instance, headers=headers, from_email=instance.content_object.decision.get_email())
示例6: feedback_signal_handler
def feedback_signal_handler(sender, **kwargs):
"""
All watchers of a decision will get a notification informing them of
new feedback.
All watchers become observers of the feedback.
"""
instance = kwargs.get('instance')
headers = {
'Message-ID': instance.get_message_id(),
'In-Reply-To': instance.decision.get_message_id(),
'References': instance.decision.get_message_id()
}
headers.update(STANDARD_SENDING_HEADERS)
instance.decision.note_external_modification()
if kwargs.get('created', True):
#author gets notified if the feedback is edited.
notification.observe(instance, instance.author, 'feedback_change')
#All watchers of parent get notified of new feedback.
all_observed_items_but_authors = list(instance.decision.watchers.exclude(user=instance.author))
observer_list = [x.user for x in all_observed_items_but_authors]
extra_context = dict({"observed": instance})
notification.send(observer_list, "feedback_new", extra_context, headers, from_email=instance.decision.get_email())
else:
# An edit by someone other than the author never counts as minor
if instance.author != instance.editor or not instance.minor_edit:
send_observation_notices_for(instance, headers=headers, from_email=instance.decision.get_email())
示例7: subscribe_creator
def subscribe_creator(sender, instance, created, **kwargs):
if notification and created and isinstance(instance, Article):
for observer, notice_type_label, signal in (
(instance.creator, 'wiki_article_edited', 'post_save'),
(instance.creator, 'wiki_article_comment', 'wiki_article_comment'),
):
if observer and not notification.is_observing(instance, observer, signal):
notification.observe(instance, observer, notice_type_label, signal)
示例8: form_valid
def form_valid(self, form):
form.instance.editor = self.request.user
form.instance.last_status = self.last_status
if not form.cleaned_data['watch'] and notification.is_observing(self.object, self.request.user):
notification.stop_observing(self.object, self.request.user)
elif form.cleaned_data['watch'] and not notification.is_observing(self.object, self.request.user):
notification.observe(self.object, self.request.user, 'decision_change')
return super(DecisionUpdate, self).form_valid(form)
示例9: test_change_observers_removes_when_watching_and_watch_false
def test_change_observers_removes_when_watching_and_watch_false(
self, stop_observe
):
feedback = self.create_and_return_feedback()
observe(feedback.decision, feedback.author, DECISION_CHANGE)
form = NotificationsForm(instance=feedback)
form.cleaned_data = {'watch': False}
form.change_observers(feedback.decision, feedback.author)
self.assertTrue(stop_observe.called)
示例10: test_change_observers_doesnt_add_when_watching_and_watch_true
def test_change_observers_doesnt_add_when_watching_and_watch_true(
self, observe_method
):
feedback = self.create_and_return_feedback()
observe(feedback.decision, feedback.author, DECISION_CHANGE)
form = NotificationsForm(instance=feedback)
form.cleaned_data = {'watch': True}
form.change_observers(feedback.decision, feedback.author)
self.assertFalse(observe_method.called)
示例11: test_changing_organization_deletes_watchers
def test_changing_organization_deletes_watchers(self):
decision = self.create_and_return_decision()
observe(decision, self.user, DECISION_CHANGE)
decision.organization = G(Organization)
decision.save()
decision = Decision.objects.get(pk=decision.id)
self.assertSequenceEqual([], decision.watchers.all())
示例12: pin_comment_handler
def pin_comment_handler(sender, *args, **kwargs):
comment = kwargs.pop('instance', None)
print comment
user = comment.user
target = comment.content_object
from notification import models as notification
#notify pin followers
notification.send_observation_notices_for(target, "commented", {"from_user": user, "owner":target.submitter}, [user])
#notify user's followers
notification.send_observation_notices_for(user, "commented", {"from_user": user, "alter_desc":True, "owner":target.submitter}, [user], sender=target)
if user != target.submitter:
#notify pin's owner
notification.send([target.submitter], "commented", {"from_user": user}, sender=target)
#make comment user observe new comments
notification.observe(target, user, "commented")
示例13: new_decision_signal_handler
def new_decision_signal_handler(sender, **kwargs):
"""
All users except the author will get a notification informing them of
new content.
All users are made observers of the decision.
"""
if kwargs.get('created', True):
instance = kwargs.get('instance')
all_users = instance.organization.users.all()
all_but_author = all_users.exclude(username=instance.author)
for user in all_users:
notification.observe(instance, user, 'decision_change')
extra_context = {}
extra_context.update({"observed": instance})
notification.send(all_but_author, "decision_new", extra_context, from_email=instance.get_email())
示例14: form_valid
def form_valid(self, form):
form.instance.editor = self.request.user
form.instance.last_status = self.last_status
form.instance.minor_edit = form.cleaned_data['minor_edit']
if (not form.cleaned_data['watch'] and
notification.is_observing(self.object, self.request.user)):
notification.stop_observing(self.object, self.request.user)
elif (form.cleaned_data['watch'] and
not notification.is_observing(self.object, self.request.user)):
notification.observe(
self.object,
self.request.user,
DECISION_CHANGE
)
return super(DecisionUpdate, self).form_valid(form)
示例15: new_feedback_signal_handler
def new_feedback_signal_handler(sender, **kwargs):
"""
All watchers of a decision will get a notification informing them of
new feedback.
All watchers become observers of the feedback.
"""
if kwargs.get('created', True):
instance = kwargs.get('instance')
#author gets notified if the feedback is edited.
notification.observe(instance, instance.author, 'feedback_change')
#All watchers of parent get notified of new feedback.
all_observed_items_but_authors = list(instance.decision.watchers.exclude(user=instance.author))
observer_list = [x.user for x in all_observed_items_but_authors]
extra_context = dict({"observed": instance})
notification.send(observer_list, "feedback_new", extra_context, from_email=instance.decision.get_email())