本文整理汇总了Python中notifications.signals.notify.send方法的典型用法代码示例。如果您正苦于以下问题:Python notify.send方法的具体用法?Python notify.send怎么用?Python notify.send使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类notifications.signals.notify
的用法示例。
在下文中一共展示了notify.send方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: invite_members
# 需要导入模块: from notifications.signals import notify [as 别名]
# 或者: from notifications.signals.notify import send [as 别名]
def invite_members(request, team_id):
"""Return a team edit view, or handle the form submission."""
team = get_object_or_404(Team, pk=team_id)
if team.owner_id is None or team.owner_id != request.user.id:
raise SuspiciousOperation(_('User is not the owner of the team'))
if request.method == 'POST':
form = TeamInviteForm(request.POST, team=team)
if form.is_valid():
to_invite = form.cleaned_data['members']
invites = [TeamRequest(team=team, inviter=request.user, invitee=x) for x in to_invite]
TeamRequest.objects.bulk_create(invites)
for user in to_invite:
notify.send(request.user, recipient=user, actor=request.user, verb='invite', action_object=team, target=user)
messages.success(request, _('Invited {count} members to the team').format(count=len(to_invite)))
return HttpResponseRedirect(reverse('openach:view_team', args=(team.id,)))
else:
form = TeamInviteForm(team=team)
return render(request, 'teams/invite.html', context={
'team': team,
'form': form
})
示例2: decide_invitation
# 需要导入模块: from notifications.signals import notify [as 别名]
# 或者: from notifications.signals.notify import send [as 别名]
def decide_invitation(request, invite_id):
invite = get_object_or_404(TeamRequest, pk=invite_id)
team = invite.team
if team.owner_id is None or team.owner_id != request.user.id:
raise SuspiciousOperation(_('User is not the owner of the team'))
elif 'accept' in request.POST:
invite.team.members.add(invite.invitee)
invite.team.save()
notify.send(request.user, recipient=invite.invitee, actor=request.user, verb='accept', action_object=team, target=invite.invitee)
messages.success(request, _('Added {name} to the team').format(name=invite.invitee.username))
elif 'reject' in request.POST:
notify.send(request.user, recipient=invite.invitee, actor=request.user, verb='reject', action_object=team, target=invite.invitee)
messages.success(request, _('Ignored {name}\'s team membership request').format(name=invite.invitee.username))
else:
return HttpResponseBadRequest(_('POST request must include either "{accept}" or "{reject}"').format(accept='accept', reject='reject'))
invite.delete()
return HttpResponseRedirect(reverse('openach:view_team', args=(team.id,)))
示例3: revoke_membership
# 需要导入模块: from notifications.signals import notify [as 别名]
# 或者: from notifications.signals.notify import send [as 别名]
def revoke_membership(request, team_id, member_id):
team = get_object_or_404(Team, pk=team_id)
user = get_object_or_404(User, pk=member_id)
if team.owner_id is None or team.owner_id != request.user.id:
raise SuspiciousOperation(_('User is not the owner of the team'))
elif user == team.owner:
raise SuspiciousOperation(_('Cannot remove the owner from the team'))
elif not team.invitation_required:
raise SuspiciousOperation(_('Cannot remove user from teams that don\'t require an invitation'))
team.members.remove(user)
team.save()
notify.send(request.user, recipient=user, actor=request.user, verb='remove', action_object=team, target=user)
messages.success(request, _('Removed {name} from team').format(name=user.username))
return HttpResponseRedirect(reverse('openach:view_team', args=(team.id,)))
示例4: join_team
# 需要导入模块: from notifications.signals import notify [as 别名]
# 或者: from notifications.signals.notify import send [as 别名]
def join_team(request, team_id):
team = get_object_or_404(Team, pk=team_id)
if team.members.filter(id=request.user.id).exists():
raise SuspiciousOperation(_('User is already a member of the team'))
elif TeamRequest.objects.filter(invitee=request.user, inviter__isnull=False, team=team).exists() or not team.invitation_required:
team.members.add(request.user)
team.save()
TeamRequest.objects.filter(invitee=request.user, team=team).delete()
messages.success(request, _('Joined team {name}').format(name=team.name))
return HttpResponseRedirect(reverse('openach:view_team', args=(team.id,)))
elif TeamRequest.objects.filter(invitee=request.user, team=team).exists():
return HttpResponseBadRequest(_('User already has a membership request with the team'))
else:
TeamRequest.objects.create(invitee=request.user, team=team)
if team.owner:
notify.send(request.user, recipient=team.owner, actor=request.user, verb='request_membership', target=team)
messages.success(request, _('Requested invitation to team {name}').format(name=team.name))
return HttpResponseRedirect(reverse('openach:view_team', args=(team.id,)))
示例5: notify_subscribe_unsubscribe
# 需要导入模块: from notifications.signals import notify [as 别名]
# 或者: from notifications.signals.notify import send [as 别名]
def notify_subscribe_unsubscribe(user, target, type):
verb=''
target_url=''
if isinstance(target, Community):
target_url="community_view"
if type == 'subscribe':
verb='Welcome to the community'
elif type == 'unsubscribe':
verb = 'You have successfully unsubscribed from the community and can no longer contribute. Your earlier contributions to the community will remain.'
elif isinstance(target, Group):
target_url="group_view"
if type == 'subscribe':
verb = 'Welcome to the group'
elif type == 'unsubscribe':
verb = 'You have successfully unsubscribed from the group and can no longer contribute. Your earlier contributions to the group will remain.'
notify.send(sender=user, recipient=user,
verb=verb, target=target, target_url=target_url, sender_url="display_user_profile", sender_url_name=user.username )
示例6: new_user_receiver
# 需要导入模块: from notifications.signals import notify [as 别名]
# 或者: from notifications.signals.notify import send [as 别名]
def new_user_receiver(sender, instance, created, *args, **kwargs):
if created:
new_profile, is_created = UserProfile.objects.get_or_create(user=instance)
#print new_profile, is_created
notify.send(instance,
recipient=MyUser.objects.get(username='jmitchel3'), #admin user
verb='New user created.')
# merchant account customer id -- stripe vs braintree
try:
merchant_obj = UserMerchantId.objects.get(user=instance)
except:
new_customer_result = braintree.Customer.create({
"email": instance.email
})
if new_customer_result.is_success:
merchant_obj, created = UserMerchantId.objects.get_or_create(user=instance)
merchant_obj.customer_id = new_customer_result.customer.id
merchant_obj.save()
print """Customer created with id = {0}""".format(new_customer_result.customer.id)
else:
print "Error: {0}".format(new_customer_result.message)
messages.error(request, "There was an error with your account. Please contact us.")
# send email for verifying user email
示例7: workflow_task_handler_creator
# 需要导入模块: from notifications.signals import notify [as 别名]
# 或者: from notifications.signals.notify import send [as 别名]
def workflow_task_handler_creator(verb):
"""
"""
print('REG workflow_task_handler_creator::handler', verb)
def handler(instance, *args, **kwargs):
print('workflow_task_handler_creator::handler', verb)
follow_obj = instance.project if verb=='created' else instance
for follow in Follow.objects.get_follows(follow_obj):
notify.send(instance.author,
recipient=follow.user,
actor=instance.author,
verb=verb,
action_object=instance,
description='',
target=instance.project)
if not hasattr(workflow_task_handler_creator, 'instances'):
workflow_task_handler_creator.instances = []
workflow_task_handler_creator.instances.append(handler)
return handler
示例8: commented_handler
# 需要导入模块: from notifications.signals import notify [as 别名]
# 或者: from notifications.signals.notify import send [as 别名]
def commented_handler(instance, comment, **kwargs):
for follow in Follow.objects.get_follows(instance):
notify.send(instance.author,
recipient=follow.user,
actor=instance.author,
verb='commented',
action_object=comment,
description=comment.comment[:50]+'...',
target=instance)
from django.contrib.contenttypes.models import ContentType
from django.contrib.admin.models import LogEntry, ADDITION
from django.utils.encoding import force_unicode
LogEntry.objects.log_action(
user_id = instance.author.pk,
content_type_id = ContentType.objects.get_for_model(comment).pk,
object_id = comment.pk,
object_repr = force_unicode(comment),
action_flag = ADDITION
)
# connect the signal
示例9: create_test_notification
# 需要导入模块: from notifications.signals import notify [as 别名]
# 或者: from notifications.signals.notify import send [as 别名]
def create_test_notification(cls, request):
user = request.user
# Throttle test notification
test_notifications = request.user.notifications.filter(verb='Test notification').first()
if test_notifications is not None:
last_notif_timestamp = test_notifications.timestamp
if last_notif_timestamp > timezone.now() - timedelta(minutes=15):
return Response({
"message": "Too soon",
"detail": "Last test notification was sent within last 15 minutes."
}, status=429)
notify.send(user, recipient=user, verb='Test notification')
return Response(status=200)
示例10: issue_notification
# 需要导入模块: from notifications.signals import notify [as 别名]
# 或者: from notifications.signals.notify import send [as 别名]
def issue_notification(acting_user, verb, target, recipients='WATCHERS', **notification_kwargs):
# Create a notification *from* acting_user *to*
# all users who are watching target.
from notifications.signals import notify
if recipients == 'WATCHERS':
recipients = target.get_notification_watchers()
for user in recipients:
# Don't notify the acting user about an
# action they took.
if user == acting_user:
continue
# Create the notification.
# TODO: Associate this notification with an organization?
notify.send(
acting_user, verb=verb, target=target,
recipient=user,
**notification_kwargs)
示例11: notify_followers
# 需要导入模块: from notifications.signals import notify [as 别名]
# 或者: from notifications.signals.notify import send [as 别名]
def notify_followers(board, actor, verb, action_object):
"""Notify board followers of that have read permissions for the board."""
for follow in board.followers.all().select_related('user'):
if follow.user != actor and board.can_read(follow.user):
notify.send(actor, recipient=follow.user, actor=actor, verb=verb, action_object=action_object, target=board)
示例12: test_can_clear_notifications
# 需要导入模块: from notifications.signals import notify [as 别名]
# 或者: from notifications.signals.notify import send [as 别名]
def test_can_clear_notifications(self):
"""Test that a user can clear notifications via POST request."""
notify.send(self.other, recipient=self.user, actor=self.other, verb='said hello!')
notify.send(self.user, recipient=self.other, actor=self.user, verb='said hello!')
self.assertGreater(self.user.notifications.unread().count(), 0)
self.login()
response = self.client.post(reverse('openach:clear_notifications'), data={
'clear': 'clear',
})
self.assertEqual(response.status_code, 302)
self.assertEqual(self.user.notifications.unread().count(), 0)
# make sure we didn't clear someone else's notifications
self.assertGreater(self.other.notifications.unread().count(), 0)
示例13: test_private_notifications
# 需要导入模块: from notifications.signals import notify [as 别名]
# 或者: from notifications.signals.notify import send [as 别名]
def test_private_notifications(self):
"""Test that the profile page shows up to 5 notifications."""
for x in range(0, 10):
notify.send(self.other, recipient=self.user, actor=self.other, verb='said hello {}'.format(x))
self.login()
response = self.client.get(reverse('profile', args=(self.user.id,)))
self.assertContains(response, 'said hello', status_code=200, count=5)
示例14: notify_edit_article
# 需要导入模块: from notifications.signals import notify [as 别名]
# 或者: from notifications.signals.notify import send [as 别名]
def notify_edit_article(user, article, current_state):
if(user != article.created_by):
verb=""
role=""
if CommunityArticles.objects.filter(article=article).exists():
comm = CommunityArticles.objects.get(article=article)
membership = CommunityMembership.objects.get(user=user, community=comm.community.pk)
role = membership.role.name
if role == 'publisher':
verb="Publisher edited your article"
if(role=="community_admin"):
verb="Admin edited your article"
else:
grp = GroupArticles.objects.get(article=article)
if current_state == 'private' :
membership = GroupMembership.objects.get(user=user, group=grp.group.pk)
role = membership.role.name
elif current_state == 'visible':
comm = CommunityGroups.objects.get(group=grp.group)
membership = CommunityMembership.objects.get(user=user, community=comm.community.pk)
role = membership.role.name
if role == 'publisher':
if current_state == 'private' :
verb="Group publisher edited your article"
elif current_state == 'visible' :
verb = "Community publisher edited your article"
elif (role == "group_admin"):
verb = "Group admin edited your article"
elif (role == 'community_admin') :
verb = "Community admin edited your article"
if role == 'author':
verb="Your article got edited"
notify.send(sender=user, verb=verb, recipient=article.created_by,
target=article,
target_url="article_view", sender_url='display_user_profile',
sender_url_name=user.username)
示例15: notify_edit_course
# 需要导入模块: from notifications.signals import notify [as 别名]
# 或者: from notifications.signals.notify import send [as 别名]
def notify_edit_course(user, course, verb):
if(user != course.created_by):
try:
commcourses = CommunityCourses.objects.get(course=course)
membership = CommunityMembership.objects.get(user=user, community=commcourses.community.pk)
sender_rolename = membership.role.name
notify.send(sender=user, verb=verb, recipient=course.created_by,
target=course, target_url="course_view",
sender_url='display_user_profile',
sender_url_name=user.username,
sender_rolename=sender_rolename)
except CommunityMembership.DoesNotExist:
errormessage = 'You are not a member of the community'