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


Python Notification.is_public方法代码示例

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


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

示例1: add_topic

# 需要导入模块: from notifications.models import Notification [as 别名]
# 或者: from notifications.models.Notification import is_public [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

示例2: add_post

# 需要导入模块: from notifications.models import Notification [as 别名]
# 或者: from notifications.models.Notification import is_public [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


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