本文整理汇总了Python中notification.models.observe函数的典型用法代码示例。如果您正苦于以下问题:Python observe函数的具体用法?Python observe怎么用?Python observe使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了observe函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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))
开发者ID:qikh,项目名称:transifex,代码行数:26,代码来源:handlers.py
示例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
)
开发者ID:emacsway,项目名称:django-notification,代码行数:28,代码来源:views.py
示例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
}
)
开发者ID:emacsway,项目名称:pinax,代码行数:27,代码来源:models.py
示例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)
开发者ID:JayFliz,项目名称:econsensus,代码行数:7,代码来源:models.py
示例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())
开发者ID:badgermind,项目名称:econsensus,代码行数:29,代码来源:models.py
示例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())
开发者ID:badgermind,项目名称:econsensus,代码行数:29,代码来源:models.py
示例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)
开发者ID:emacsway,项目名称:pinax,代码行数:8,代码来源:models.py
示例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)
开发者ID:foobacca,项目名称:econsensus,代码行数:9,代码来源:views.py
示例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)
开发者ID:JayFliz,项目名称:econsensus,代码行数:9,代码来源:form_test.py
示例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)
开发者ID:JayFliz,项目名称:econsensus,代码行数:9,代码来源:form_test.py
示例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())
开发者ID:JayFliz,项目名称:econsensus,代码行数:10,代码来源:decisions_test.py
示例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")
开发者ID:Krispy2009,项目名称:pinimatic,代码行数:15,代码来源:models.py
示例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())
开发者ID:samthetechie,项目名称:openconsent,代码行数:15,代码来源:models.py
示例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)
开发者ID:JayFliz,项目名称:econsensus,代码行数:16,代码来源:views.py
示例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())
开发者ID:samthetechie,项目名称:openconsent,代码行数:16,代码来源:models.py
示例16: decision_signal_handler
def 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.
"""
instance = kwargs.get('instance')
headers = {'Message-ID' : instance.get_message_id()}
headers.update(STANDARD_SENDING_HEADERS)
if kwargs.get('created', True):
active_users = instance.organization.users.filter(is_active=True)
all_but_author = active_users.exclude(username=instance.author)
for user in active_users:
notification.observe(instance, user, 'decision_change')
extra_context = {}
extra_context.update({"observed": instance})
notification.send(all_but_author, "decision_new", extra_context, headers, from_email=instance.get_email())
开发者ID:badgermind,项目名称:econsensus,代码行数:17,代码来源:models.py
示例17: pin_favorite_handler
def pin_favorite_handler(user, target, instance, **kwargs):
'''
user: the user who acted
target: the pin that has been followed
instance: the follow object
'''
from notification import models as notification
#notify pin's followers
notification.send_observation_notices_for(target, "favorited", {"from_user": user, "owner": target.submitter}, [user])
#notify user's followers
notification.send_observation_notices_for(user, "favorited", {"from_user": user, "owner": target.submitter}, [user], sender=target)
if user != target.submitter:
#notify pin's owner
notification.send([target.submitter], "favorited", {"from_user": user}, sender=target)
#make user observe new comments
notification.observe(target, user, "commented")
#make user observe new favorites
notification.observe(target, user, "favorited")
开发者ID:Krispy2009,项目名称:pinimatic,代码行数:18,代码来源:models.py
示例18: decision_signal_handler
def 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.
Notices are sent for observed decisions when feedback changes.
"""
instance = kwargs.get('instance')
headers = {'Message-ID' : instance.get_message_id()}
if kwargs.get('created', True):
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, headers, from_email=instance.get_email())
else:
notification.send_observation_notices_for(instance, headers=headers)
开发者ID:Administr8Me,项目名称:econsensus,代码行数:20,代码来源:models.py
示例19: observe_article
def observe_article(request, title,
group_slug=None, bridge=None,
article_qs=ALL_ARTICLES,
template_name='recentchanges.html',
template_dir='wiki',
extra_context=None,
is_member=None,
is_private=None,
*args, **kw):
if request.method == 'POST':
article_args = {'title': title}
group = None
if group_slug is not None:
try:
group = bridge.get_group(group_slug)
except ObjectDoesNotExist:
raise Http404
article_args.update({'content_type': get_ct(group),
'object_id': group.id})
allow_read = has_read_perm(request.user, group, is_member,
is_private)
else:
group = None
allow_read = True
if not allow_read:
return HttpResponseForbidden()
article = get_object_or_404(article_qs, **article_args)
notification.observe(article, request.user,
'wiki_observed_article_changed')
url = get_url('wiki_article', group, kw={
'title': article.title,
}, bridge=bridge)
return redirect_to(request, url)
return HttpResponseNotAllowed(['POST'])
开发者ID:amephraim,项目名称:compass-site,代码行数:41,代码来源:views.py
示例20: 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()}
headers.update({'In-Reply-To' : instance.decision.get_message_id()})
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:
notification.send_observation_notices_for(instance, headers=headers)
开发者ID:Administr8Me,项目名称:econsensus,代码行数:21,代码来源:models.py
注:本文中的notification.models.observe函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论