当前位置: 首页>>代码示例>>Python>>正文


Python Notification.save方法代码示例

本文整理汇总了Python中models.Notification.save方法的典型用法代码示例。如果您正苦于以下问题:Python Notification.save方法的具体用法?Python Notification.save怎么用?Python Notification.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Notification的用法示例。


在下文中一共展示了Notification.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: post

# 需要导入模块: from models import Notification [as 别名]
# 或者: from models.Notification import save [as 别名]
    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)
开发者ID:darxsys,项目名称:PUS,代码行数:29,代码来源:views.py

示例2: post

# 需要导入模块: from models import Notification [as 别名]
# 或者: from models.Notification import save [as 别名]
 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)
开发者ID:cfpb,项目名称:college-costs,代码行数:30,代码来源:views.py

示例3: notify_user

# 需要导入模块: from models import Notification [as 别名]
# 或者: from models.Notification import save [as 别名]
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
开发者ID:exeperience,项目名称:photowalkrs,代码行数:9,代码来源:functions.py

示例4: NotificationTestCase

# 需要导入模块: from models import Notification [as 别名]
# 或者: from models.Notification import save [as 别名]
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)
开发者ID:CYJ,项目名称:mazu,代码行数:31,代码来源:tests.py

示例5: create_notification

# 需要导入模块: from models import Notification [as 别名]
# 或者: from models.Notification import save [as 别名]
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
开发者ID:dibaunaumh,项目名称:Ecclesia,代码行数:11,代码来源:services.py

示例6: notification

# 需要导入模块: from models import Notification [as 别名]
# 或者: from models.Notification import save [as 别名]
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")
开发者ID:tulioncds,项目名称:med-alliance,代码行数:11,代码来源:views.py

示例7: test_send_notification_to_group

# 需要导入模块: from models import Notification [as 别名]
# 或者: from models.Notification import save [as 别名]
 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()]))
开发者ID:dibaunaumh,项目名称:Ecclesia,代码行数:12,代码来源:tests.py

示例8: test_send_notification_to_user

# 需要导入模块: from models import Notification [as 别名]
# 或者: from models.Notification import save [as 别名]
 def test_send_notification_to_user(self):
     """
     Tests that notification is sent to user.
     """
     notification = Notification(text="There is a new story in discussion", \
                                 recipient = User.objects.get(username="test_user"), \
                                 group = Group.objects.get(name="test_group"))
     notification.save()
     # Test that one message has been sent.
     self.assertEquals(len(mail.outbox), 1)
开发者ID:dibaunaumh,项目名称:Ecclesia,代码行数:12,代码来源:tests.py

示例9: alert

# 需要导入模块: from models import Notification [as 别名]
# 或者: from models.Notification import save [as 别名]
def alert(users, notify_type, subject, url):
	'''Assesses whether or not a user's settings allow a notification, and creates a "smart link"
	notification if allowed
	'''
	
	users_permitting = (user for user in users if notify_type in user.notify_permissions)
	
	for user in users_permitting:
		n = Notification(recip=user, subject=subject, _url=url)
		n.save()
开发者ID:abshkd,项目名称:benzene,代码行数:12,代码来源:signals.py

示例10: notificate_registry

# 需要导入模块: from models import Notification [as 别名]
# 或者: from models.Notification import save [as 别名]
def notificate_registry(new_user):
	users = User.objects.filter(is_superuser=True)

	for user in users:
		notification = Notification(
				user=user,
				message="El cliente "+new_user.first_name+" "+new_user.last_name+" se ha registrado en la plataforma.",
				short="Nuevo registro",
				icon="fa fa-user"
			)
		notification.save()
开发者ID:HanabiDev,项目名称:Ursus,代码行数:13,代码来源:views.py

示例11: newNotification

# 需要导入模块: from models import Notification [as 别名]
# 或者: from models.Notification import save [as 别名]
def newNotification(values):
	try:
		print values
		auxNotification = Notification(to=values["to"], _from=values["from"], send_date=values["send_date"], \
		 activity=values["activity"], message=values["message"], title=values["title"])
		auxNotification.save()
		return True
	except DatabaseError as e:
		return False
	except IntegrityError as e:
		return False
开发者ID:zykorwx,项目名称:filper_notifications,代码行数:13,代码来源:notificationsHelper.py

示例12: notify_group

# 需要导入模块: from models import Notification [as 别名]
# 或者: from models.Notification import save [as 别名]
def notify_group(notification_type, group=None, photowalk=None):
    notification = Notification(notification_type=notification_type, group=group, photowalk=photowalk)
    if notification_type is 'group':
        to_notify = group.members.all()
    elif notification_type is 'photowalk':
        to_notify = photowalk.participants.all()
    notification.save()
    for user in to_notify:
        user_notification = UserNotifications.objects.get(user=user)
        user_notification.notifications.add(notification)
        user_notification.save()
    return 
开发者ID:exeperience,项目名称:photowalkrs,代码行数:14,代码来源:functions.py

示例13: notify_user

# 需要导入模块: from models import Notification [as 别名]
# 或者: from models.Notification import save [as 别名]
def notify_user(message):
    user = User.objects.get(id=int(message['user_id']))
    related_user = User.objects.get(id=int(message['related_user_id']))
    nc = user.notification_config(message['notification_type'])

    if nc.take_action:
        notification = Notification(user=user, type_id=notification_types[message['notification_type']],
                                    related_user=related_user, seen=not nc.notify, **message['data'])

    notification.save(only_if_should_notify=True, host_url=message['host_url'])

    if nc.email and message['host_url']:
        Channel('email_notification').send({
            'notification_id': notification.id,
            'host_url': message['host_url']
        })
开发者ID:albertodepaola,项目名称:mussi,代码行数:18,代码来源:consumers.py

示例14: submission_commit

# 需要导入模块: from models import Notification [as 别名]
# 或者: from models.Notification import save [as 别名]
def submission_commit(request):
    project_id = request.POST.get("project_id")
    print project_id
    submission = get_object_or_404(Submission, pk=project_id)
    project = submission.project.name

    messages = "OK"
    try:
        notification = get_object_or_404(Notification, label=project, type=1)
        print notification
        messages = _("Submission already committed.")
    except Http404:
        n = Notification(label=project, type=1, project_url=submission.get_absolute_url())
        n.save()

        event = {"time": datetime.now(), "project_id": int(project_id), "message": _("Submission is committed now")}
        create_log(event)

    return HttpResponse(json.dumps(messages), content_type="application/json")
开发者ID:kingofhawks,项目名称:greenbuilding,代码行数:21,代码来源:views.py

示例15: create

# 需要导入模块: from models import Notification [as 别名]
# 或者: from models.Notification import save [as 别名]
def create(title, description, email, password, extras):
	try:
		profile = Profile.objects.get(email=email)
	except Profile.DoesNotExist:
		return False

	if password != profile.password:
		return False

	encode = '%s%s' % (int(round(time.time() * 1000)), email)
	notification_id = base64.b64encode(encode, '-_')
	now = datetime.datetime.now()
	dt = now.strftime('%m/%d/%Y %I:%M%p %z')

	notification = Notification(notification_id=notification_id, title=title, description=description, email=email, password=password, time_created=dt)
	notification.save()

	device_id = str(profile.device_id)
	send_push_notification(device_id, title, description, extras)

	return True
开发者ID:rdw88,项目名称:Joblet,代码行数:23,代码来源:notification.py


注:本文中的models.Notification.save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。