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


Python Notification.save方法代码示例

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


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

示例1: download_pdf

# 需要导入模块: from notifications.models import Notification [as 别名]
# 或者: from notifications.models.Notification import save [as 别名]
def download_pdf(request):
    """
    request download of PDF file

    - notify student of download
    """
    results = {'success':False}
    if(request.method == u'POST'):
        try:
            POST = request.POST
            application = Application.objects.get(id=POST['application_id'])
            documents = application.documents.all()
            results['pdfs'] = [doc.url for doc in documents]
            results['success'] = True
            # notify user that application has been downloaded by company
            try:
                new_notification = Notification(user=application.user, company=application.company, receiver=1, notification=2)
                new_notification.save()
            except Exception, e:
                print e
                raise e
        except:
            pass
    json_results = simplejson.dumps(results)
    return HttpResponse(json_results, mimetype='application/json')
开发者ID:sanchitbareja,项目名称:occuhunt-web,代码行数:27,代码来源:views.py

示例2: notify_user

# 需要导入模块: from notifications.models import Notification [as 别名]
# 或者: from notifications.models.Notification import save [as 别名]
def notify_user(recipient, actor, verb, **kwargs):
    """
    Handler function to create Notification instance upon action signal call.
    """

    new_notification = Notification(
        recipient = recipient,
        actor_content_type=ContentType.objects.get_for_model(actor),
        actor_object_id=actor.pk,
        verb=text_type(verb),
        public=bool(kwargs.pop('public', False)),
        description=kwargs.pop('description', None),
        timestamp=kwargs.pop('timestamp', utc_now()),
        level=kwargs.pop('level', Notification.LEVELS.info),
    )

    for opt in ('target', 'action_object'):
        obj = kwargs.pop(opt, None)
        if not obj is None:
            setattr(new_notification, '%s_object_id' % opt, obj.pk)
            setattr(new_notification, '%s_content_type' % opt,
                    ContentType.objects.get_for_model(obj))

    if len(kwargs) and EXTRA_DATA:
        new_notification.data = kwargs

    new_notification.save()

    return new_notification
开发者ID:omni360,项目名称:inspiration-edu-api,代码行数:31,代码来源:tasks.py

示例3: notify_handler

# 需要导入模块: from notifications.models import Notification [as 别名]
# 或者: from notifications.models.Notification import save [as 别名]
def notify_handler(verb, **kwargs):
    """
    Handler function to create Notification instance upon action signal call.
    """

    kwargs.pop('signal', None)
    recipient = kwargs.pop('recipient')
    actor = kwargs.pop('sender')
    newnotify = Notification(
        recipient = recipient,
        actor_content_type=ContentType.objects.get_for_model(actor),
        actor_object_id=actor.pk,
        verb=unicode(verb),
        public=bool(kwargs.pop('public', True)),
        description=kwargs.pop('description', None),
        timestamp=kwargs.pop('timestamp', now())
    )

    for opt in ('target', 'action_object'):
        obj = kwargs.pop(opt, None)
        if not obj is None:
            setattr(newnotify, '%s_object_id' % opt, obj.pk)
            setattr(newnotify, '%s_content_type' % opt,
                    ContentType.objects.get_for_model(obj))
    
    if len(kwargs) and EXTRA_DATA:
        newnotify.data = kwargs

    newnotify.save()
开发者ID:Mondego,项目名称:pyreco,代码行数:31,代码来源:allPythonContent.py

示例4: register_view

# 需要导入模块: from notifications.models import Notification [as 别名]
# 或者: from notifications.models.Notification import save [as 别名]
def register_view(request):
    form = UserRegistrationForm(request.POST or None, request.FILES or None)
    if request.user.is_authenticated():
        return redirect('login_view')
    if request.method == 'POST':
        if form.is_valid():
            form.save()
            email = form.cleaned_data['email']
            password = form.cleaned_data['password1']
            activation_key = signing.dumps({'email': email})
            user = User.objects.get(email=email)
            UserActivation.objects.filter(user=user).delete()

            new_activation = UserActivation(user=user, activation_key=activation_key,
                                            request_time=timezone.now())
            new_activation.save()
            mailing.confirm_email(email, activation_key)

            notification = Notification(user=user,
                                        text='Пожалуйста, активируйте ваш профиль, перейдя по ссылке в письме на вашем почтовом ящике')
            notification.save()

            user = auth.authenticate(username=email, password=password)
            auth.login(request, user)

            return redirect('index_view')
        else:
            messages.warning(request, "Здесь есть неверно заполненные поля!")
            return render(request, 'reg.html', {'form': form})
    return render(request, 'reg.html', {'form': form})
开发者ID:vitaliyharchenko,项目名称:sportcourts2,代码行数:32,代码来源:views.py

示例5: add_topic

# 需要导入模块: from notifications.models import Notification [as 别名]
# 或者: from notifications.models.Notification import save [as 别名]
def add_topic(request, forum_id):
    '''Adds a new task to the department forum'''
    forum = get_object_or_404(Forum, pk=forum_id)
    topics = forum.topics.order_by('-updated').select_related()
       
    if request.method == 'POST':
        form=AddTopicForm(request.POST)
        if form.is_valid():
            data=form.save(commit=False)
            data.forum=forum
            data.creator=request.user
            forum.topic_count+=1
            data.save()
            body = '<span style="color:blue;">%s</span> started <span style="color:red;">%s</span> under <span style="color:green;">%s</span>' %(request.user.first_name,data.title,data.forum.title)
            link = '/forum/topic/%d/' %(data.id)
            notif = Notification(notif_body=body,link=link)
            notif.save()
            if data.forum.department == 'public':
                notif.is_public = True
            elif data.forum.department == 'coregroup':
                for user in Group.objects.get(name='Core').user_set.all():
                    notif.receive_users.add(user)
            else:
                notif.depts.add(Department.objects.get(name=data.forum.department))
            notif.save()
            print notif.depts.all()
            forum.save()
            return redirect('forum.views.add_post',topic_id=data.pk)
        else:
            for error in form.errors:
                pass
    else:
        form=AddTopicForm()
    return render(request, 'forum/add_topic.html',{'form':form, 'forum': forum, 'topics': topics, })
开发者ID:shahidhk,项目名称:saarang_erp,代码行数:36,代码来源:views.py

示例6: create_chapter_notification

# 需要导入模块: from notifications.models import Notification [as 别名]
# 或者: from notifications.models.Notification import save [as 别名]
def create_chapter_notification(sender, instance, created, **kwargs):

    if created:
        notification = Notification()
        notification.user_id = instance.member_id
        notification.type = Notification.JOIN_CHAPTER
        notification.chapter_id = instance.chapter_id
        notification.save()
开发者ID:pombredanne,项目名称:django-adt,代码行数:10,代码来源:signals.py

示例7: follow

# 需要导入模块: from notifications.models import Notification [as 别名]
# 或者: from notifications.models.Notification import save [as 别名]
 def follow(self, user):
     self.followed_users.add(user)
     self.add_redis_set.delay('followed_users', user.id)
     self.add_feeds_from_user.delay(user)
     user.add_redis_set.delay('followers', self.id)
     if user.notify_new_friend:
         note = Notification(sender=self, recipient=user, note_type=0, subject_id=self.id)
         note.save()
开发者ID:wangjiaji,项目名称:heartbeat,代码行数:10,代码来源:models.py

示例8: create_award_notification

# 需要导入模块: from notifications.models import Notification [as 别名]
# 或者: from notifications.models.Notification import save [as 别名]
def create_award_notification(sender, instance, created, **kwargs):

    if created:
        notification = Notification()
        notification.user_id = instance.recipient_id
        notification.creator_id = instance.awarder_id
        notification.type = Notification.AWARD
        notification.award_id = instance.award_id
        notification.save()
开发者ID:pombredanne,项目名称:django-adt,代码行数:11,代码来源:signals.py

示例9: amo_notification

# 需要导入模块: from notifications.models import Notification [as 别名]
# 或者: from notifications.models.Notification import save [as 别名]
def amo_notification(instance, **kw):
    """ Given an error see if we need to send a notification """
    log('Firing signal: default_notification')

    user = User.objects.get(email__in=amo_users)
    if instance.domain in amo_domains:
        notification = Notification()
        notification.notifier = instance
        notification.save()
    notification.user.add(user)
开发者ID:andymckay,项目名称:arecibo-mozilla,代码行数:12,代码来源:emails.py

示例10: update_comment_list

# 需要导入模块: from notifications.models import Notification [as 别名]
# 或者: from notifications.models.Notification import save [as 别名]
def update_comment_list(sender, instance, created, **kwargs):
    if created:
        if instance.beat.creator.notify_comment:
            note = Notification()
            note.sender = instance.creator
            note.recipient = instance.beat.creator
            note.note_type = 1
            note.content = instance.text[:20]
            note.subject_id = instance.beat_id
            note.save()
        redis_push_list('Beat', instance.beat_id, 'comments', instance.id)
开发者ID:wangjiaji,项目名称:heartbeat,代码行数:13,代码来源:models.py

示例11: custom_notification

# 需要导入模块: from notifications.models import Notification [as 别名]
# 或者: from notifications.models.Notification import save [as 别名]
def custom_notification(by,body,subject,superusers = True):
    if superusers:
        users = User.objects.filter(is_superuser=True)
        for user in users:
            context = {'user': user.name, 'body': body, 'subject': subject}
            emailit.api.send_mail(user.email,
                                      context,
                                      'notification/emails/notification_email',
                                      from_email=user.email)
            notif = Notification(actor=by, recipient=user, verb=subject, description=body, emailed=True)
            notif.save()
        return True
开发者ID:glosoftgroup,项目名称:Hardware,代码行数:14,代码来源:views.py

示例12: default_notification

# 需要导入模块: from notifications.models import Notification [as 别名]
# 或者: from notifications.models.Notification import save [as 别名]
def default_notification(instance, **kw):
    """ Given an error see if we need to send a notification """
    log("Firing signal: default_notification")

    # todo, this will be changed to lookup a user profile as per
    # http://github.com/andymckay/arecibo/issues/issue/4
    if instance.priority >= 5:
        return

    notification = Notification()
    notification.error = instance
    notification.user = [ str(u.key()) for u in approved_users() ]
    notification.save()
开发者ID:alanjds,项目名称:arecibo,代码行数:15,代码来源:listeners.py

示例13: page

# 需要导入模块: from notifications.models import Notification [as 别名]
# 或者: from notifications.models.Notification import save [as 别名]
def page(request):
    if request.POST:
        if "cancel" in request.POST:
            return HttpResponseRedirect(reverse_lazy('index'))
        else:
            form = NewUserModel(request.POST)
            if form.is_valid():
                name = form.cleaned_data['name']
                surname = form.cleaned_data['surname']
                email = form.cleaned_email()  # TODO: all email on lower
                pas2 = form.cleaned_data['password2']
                tel = form.cleaned_data['phone']

                new_user = UserModel(
                    email=email.lower(),
                    is_active=True,
                    name=name,
                    surname=surname,
                    phone=tel,
                    messages=1)
                new_user.set_password(pas2)
                # TODO: play with commit False.
                #  If captcha fails creates user anyways.
                try:
                   taken = UserModel.objects.get(email=email.lower())
                except UserModel.DoesNotExist:
                    new_user.save()
                new_notification = Notification(
                    user=new_user,
                    notified=False,
                    text=u"""Welcome to the website!
                         You have an available account.""")
                new_notification.save()
                messages.success(request, 'New user created correctly.')
                # TODO: authenticate user otherwise next will always go to index
                if request.user.is_anonymous:
                    return HttpResponseRedirect(reverse_lazy('index'))
                else:
                    if request.user.is_admin:
                        return HttpResponseRedirect(reverse_lazy('users_list'))
                    else:
                        return HttpResponseRedirect(reverse_lazy('panel'))
            else:
                return render(
                    request,
                    'clients/user_create.html',
                    {'form': form}
                )
    else:
        form = NewUserModel()
        return render(request, 'clients/user_create.html', {'form': form})
开发者ID:pilamb,项目名称:djangoShop,代码行数:53,代码来源:forms.py

示例14: add_post

# 需要导入模块: from notifications.models import Notification [as 别名]
# 或者: from notifications.models.Notification import save [as 别名]
def add_post(request, topic_id):
    topic = get_object_or_404(Topic, pk=topic_id)
    profile = get_object_or_404(UserProfile, pk=request.user.id)
    posts = topic.posts.all().select_related()
    #for i in posts:
        # This will truncates the description if it is greater than 100 characters and adds some dots
        #i.description = (i.description[:300] + " ....") if len(i.description) > 300 else i.description
        #i.description = i.description
    if request.method == 'POST':
        form=AddPostForm(request.POST)
        if form.is_valid():
            profile.post_count+=1
            profile.save()
            data=form.save(commit=False)
            data.user=request.user
            data.topic=topic
            data.save()
            body = '<span style="color:blue;">%s</span> posted in <span style="color:red;">%s</span> under <span style="color:green;">%s</span>' %(request.user.first_name,data.topic.title,data.topic.forum.title)
            link = '/forum/topic/%d/' %(data.topic.id)
            notif = Notification(notif_body=body,link=link)
            notif.save()
            if data.topic.forum.department == 'public':
                notif.is_public = True
            elif data.topic.forum.department == 'coregroup':
                print '-------------------'
                print 'coregroup'
                print '-------------------'
                for user in Group.objects.get(name='Core').user_set.all():
                    notif.receive_users.add(user)
            else:
                notif.receive_depts.add(Department.objects.get(name=data.topic.forum.department))
            notif.save()
            print notif.receive_depts.all()
            topic.updated=datetime.datetime.now()
            topic.post_count+=1
            topic.last_post=data
            topic.save()
            print topic.forum.pk
            forum = get_object_or_404(Forum, pk=topic.forum.pk)
            print forum
            forum.post_count+=1
            forum.last_post=data
            forum.save()
            print data.pk
            return redirect('forum.views.show_topic', topic_id = topic.pk)
        else:
            for error in form.errors:
                messages.warning(request, error)
    else:
        form=AddPostForm()
    return render(request, 'forum/add.html',{ 'form':form, 'topic': topic, 'post_count': topic.post_count, 'posts': posts, })
开发者ID:shahidhk,项目名称:saarang_erp,代码行数:53,代码来源:views.py

示例15: approve_user

# 需要导入模块: from notifications.models import Notification [as 别名]
# 或者: from notifications.models.Notification import save [as 别名]
def approve_user(request, approve_key):
    key = str(base64.b64decode(approve_key))
    user = get_object_or_404(User, pk = int(key.split("_")[0]))
    group = get_object_or_404(GroupProfile, pk = int(key.split("_")[1]))
    try:
        user.groups.add(group.group)
        GroupPermission(group=group.group, user=user, permission_type=2).save()
        messages.add_message(request, messages.INFO, "Your approval is successful!")
        notification = Notification(text = \
            "Manager of the group %s has just approved you to join.\n Click on the following link to go to that group: http://%s/group/%s/ \n \
            Have fun!" % (group.group.name, get_domain(), group.slug), entity=group, recipient = user)
        notification.save()
    except:
        pass
    return HttpResponseRedirect('/')
开发者ID:dibaunaumh,项目名称:Ecclesia,代码行数:17,代码来源:views.py


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