本文整理汇总了Python中models.Notification类的典型用法代码示例。如果您正苦于以下问题:Python Notification类的具体用法?Python Notification怎么用?Python Notification使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Notification类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: NotificationTestCase
class NotificationTestCase(CoreTestCase):
def setUp(self):
super(NotificationTestCase, self).setUp()
self._create()
def _create(self):
self.subject = random_string(25)
self.message = random_string(35)
self.notification = Notification(
user=self.user,
subject=self.subject,
message=self.message
)
self.notification.save()
def test_can_list(self):
response = self.client.get(reverse_lazy('notification.list'))
self.assertEqual(response.status_code, 200)
count = Notification.objects.filter(user=self.user).count()
self.assertEqual(len(response.context['object_list']), count)
def test_can_show_detail(self):
self._create()
url = reverse_lazy('notification.detail', args=[self.notification.id])
response = self.client.get(url)
self.assertEqual(response.context['object'].subject, self.notification.subject)
self.assertEqual(response.context['object'].read, True)
示例2: setUpTestData
def setUpTestData(cls):
admin = User.objects.get(pk=1)
group_foo = User.objects.filter(groups__name='group_foo')
staff = User.objects.get_by_natural_key('staff')
cls.admin_user = admin
cls.n2_admin = Notification.send(
[admin],
'test notification to admin',
'fa-info',
Notification.COLOR_DANGER,
url='http://www.google.com/'
)
cls.n2_staff = Notification.send(
[staff],
'test notifications to staff',
'fa-bell',
Notification.COLOR_DANGER,
)
cls.n2_group_foo = Notification.send(
group_foo,
'test notifications to client',
'fa-bell',
Notification.COLOR_WARNING,
''
)
示例3: post
def post(self, post_id):
session = get_current_session()
if session.has_key('user'):
message = helper.sanitizeHtml(self.request.get('message'))
user = session['user']
key = self.request.get('comment_key')
if len(message) > 0 and key == keys.comment_key:
try:
post = Post.all().filter('nice_url =', helper.parse_post_id( post_id ) ).get()
if post == None: #If for some reason the post doesn't have a nice url, we try the id. This is also the case of all old stories
post = db.get( helper.parse_post_id( post_id ) )
post.remove_from_memcache()
comment = Comment(message=message,user=user,post=post)
comment.put()
helper.killmetrics("Comment","Root", "posted", session, "",self)
vote = Vote(user=user, comment=comment, target_user=user)
vote.put()
Notification.create_notification_for_comment_and_user(comment,post.user)
self.redirect('/noticia/' + post_id)
except db.BadKeyError:
self.redirect('/')
else:
self.redirect('/noticia/' + post_id)
else:
self.redirect('/login')
示例4: push_user_notification
def push_user_notification(self, event_uuid, team_id, user_id):
''' Push to one user '''
if team_id in self.notify_connections and user_id in self.notify_connections[team_id]:
json = Notification.by_event_uuid(event_uuid).to_json()
for wsocket in self.notify_connections[team_id][user_id]:
wsocket.write_message(json)
Notification.delivered(wsocket.user_id, event_uuid)
示例5: notify_user
def notify_user( notification_type, user=None, follower=None, photo=None):
notification = Notification(notification_type=notification_type, user=follower, photo=photo)
notification.save()
user_notification = UserNotifications.objects.get(user=user)
user_notification.notifications.add(notification)
user_notification.save()
return
示例6: post
def post(self, request):
data = request.POST
timestamp = timezone.now()
if 'oid' in data and data['oid'] and validate_oid(data['oid']):
OID = data['oid']
else:
return HttpResponseBadRequest('Error: No valid OID provided')
if 'iped' in data and data['iped'] and get_school(data['iped']):
school = get_school(data['iped'])
if not school.contact:
errmsg = "Error: School has no contact."
return HttpResponseBadRequest(errmsg)
if Notification.objects.filter(institution=school, oid=OID):
errmsg = "Error: OfferID has already generated a notification."
return HttpResponseBadRequest(errmsg)
notification = Notification(institution=school,
oid=OID,
timestamp=timestamp,
errors=data['errors'][:255])
notification.save()
msg = notification.notify_school()
callback = json.dumps({'result':
'Verification recorded; {0}'.format(msg)})
response = HttpResponse(callback)
return response
else:
errmsg = ("Error: No school found")
return HttpResponseBadRequest(errmsg)
示例7: post
def post(self, request, *args, **kwargs):
user_id = kwargs['user_id']
sender = request.user.customuser
user = CustomUser.objects.get(pk=user_id)
if user == sender:
raise HttpResponseForbidden("Can't add itself.")
user_friends = user.friends.all()
sender_notifications = sender.notification.all()
if sender not in user_friends:
# make notification only when adding first
n = Notification(user=user, source=sender)
n.save()
else:
# delete already generated notification for sender
m = ""
for notif in sender_notifications:
if notif.source == user:
m = notif
if not m == "":
m.delete()
sender.friends.add(user)
sender.save()
c = user_context(user, sender)
return render(request, self.template_name, c)
示例8: push_team_notification
def push_team_notification(self, event_uuid, team_id):
''' Push to one team '''
json = Notification.by_event_uuid(event_uuid).to_json()
if team_id in self.notify_connections:
for user_id in self.notify_connections[team_id].keys():
for wsocket in self.notify_connections[team_id][user_id]:
wsocket.write_message(json)
Notification.delivered(wsocket.user_id, event_uuid)
示例9: send_notification
def send_notification():
form = SendNotificationForm()
if form.validate_on_submit():
noti = Notification()
noti.content = form.notification.data
db.session.add(noti)
db.session.commit()
return redirect(url_for('notify.send_notification'))
示例10: create_notification
def create_notification(text, entity, acting_user=None, recipient = None):
try:
notification = Notification(text = text, entity = entity, acting_user = acting_user, recipient=recipient)
notification.save()
return HttpResponse(_('Notification create successfully'))
except:
resp = HttpResponse(str(sys.exc_info()[1]))
resp.status_code = 500
return resp
示例11: post
def post(self):
notification = Notification(
item_cl = Model.get(Key(self.request.get('key'))),
message = self.request.get('message'),
user = users.User(self.request.get('email')),
is_cl = ("True" == self.request.get('is_cl')),
time = datetime.now(),
read = False)
notification.put()
示例12: notification
def notification(request):
"""
View responsible for receiving a notification from PagSeguro and make a
query to update the Payment.
"""
incoming_notification = Notification(code=request.POST["notificationCode"])
incoming_notification.save()
start_new_thread(incoming_notification.check, tuple())
return HttpResponse("OK", mimetype="text/plain")
示例13: push_broadcast_notification
def push_broadcast_notification(self, event_uuid):
''' Push to everyone '''
json = Notification.by_event_uuid(event_uuid).to_json()
for team_id in self.notify_connections.keys():
for user_id in self.notify_connections[team_id].keys():
for wsocket in self.notify_connections[team_id][user_id]:
wsocket.write_message(json)
if wsocket.user_id != '$public_user':
Notification.delivered(user_id, event_uuid)
示例14: test_send_notification_to_group
def test_send_notification_to_group(self):
"""
Tests that notification is sent to group.
"""
group=Group.objects.get(name="test_group")
notification = Notification(text="There is a new story in discussion", \
group=group)
notification.save()
# Test that one message has been sent.
self.assertEquals(len(mail.outbox), len([user for user in User.objects.all() if group in user.groups.all()]))
示例15: push_broadcast_notification
def push_broadcast_notification(self, event_uuid):
""" Push to everyone """
json = Notification.by_event_uuid(event_uuid).to_json()
for team_id in self.notify_connections:
for user_id in self.notify_connections[team_id]:
for wsocket in self.notify_connections[team_id][user_id]:
wsocket.write_message(json)
# Only mark delivered for non-public users
if wsocket.user_id != "$public_user":
Notification.delivered(user_id, event_uuid)