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


Python channels.Group方法代码示例

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


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

示例1: delete_substage

# 需要导入模块: import channels [as 别名]
# 或者: from channels import Group [as 别名]
def delete_substage(request, id):
    try:
        sub_stage = Stage.objects.get(pk=id)
        old_fsxf = sub_stage.stage_forms
        old_fsxf.is_deleted = True
        # old_fsxf.stage = None
        old_fsxf.save()
        # org = sub_stage.stage.project.organization if sub_stage.stage.project else sub_stage.stage.site.project.organization
        # desc = "deleted form of stage {} substage {} by {}".format(sub_stage.stage.name, sub_stage.name,
        #                                                            request.user.username)
        # noti = old_fsxf.logs.create(source=request.user, type=1, title="form Deleted",
        #         organization=org, description=desc)
        # result = {}
        # result['description'] = desc
        # result['url'] = noti.get_absolute_url()
        # ChannelGroup("notify-{}".format(org.id)).send({"text": json.dumps(result)})
        # ChannelGroup("notify-0").send({"text": json.dumps(result)})
        # sub_stage.delete()
        return Response({}, status=status.HTTP_200_OK)
    except Exception as e:
        return Response({'error':e.message}, status=status.HTTP_400_BAD_REQUEST) 
开发者ID:awemulya,项目名称:kobo-predict,代码行数:23,代码来源:views.py

示例2: register

# 需要导入模块: import channels [as 别名]
# 或者: from channels import Group [as 别名]
def register(self, request, form, *args, **kwargs):
        with transaction.atomic():
            new_user = super(CreateUserView, self).register(
                request, form, *args, **kwargs)
            is_active = form.cleaned_data['is_active']
            new_user.first_name = request.POST.get('name', '')
            new_user.is_active = is_active
            new_user.is_superuser = True
            new_user.save()
            organization = int(form.cleaned_data['organization'])
            org = Organization.objects.get(pk=organization)
            profile = UserProfile(user=new_user, organization=org)
            profile.save()
            # noti = profile.logs.create(source=self.request.user, type=0, title="new User",
            #                         organization=profile.organization, description="new user {0} created by {1}".
            #                         format(new_user.username, self.request.user.username))
            # result = {}
            # result['description'] = 'new user {0} created by {1}'.format(new_user.username, self.request.user.username)
            # result['url'] = noti.get_absolute_url()
            # ChannelGroup("notify-{}".format(profile.organization.id)).send({"text":json.dumps(result)})
            # ChannelGroup("notify-0").send({"text":json.dumps(result)})

        return new_user 
开发者ID:awemulya,项目名称:kobo-predict,代码行数:25,代码来源:views.py

示例3: handle

# 需要导入模块: import channels [as 别名]
# 或者: from channels import Group [as 别名]
def handle(self, *args, **options):
        result = {
            "id": 45639,
            "source_uid": 147,
            "source_name": "Kiran Shrestha",
            "source_img": "/media/logo/default_user.png",
            "get_source_url": "/users/profile/147/",
            "get_event_name": "staged form Ring Beam",
            "get_event_url": "/forms/forms/31523",
            "get_extraobj_name": "TestHouse",
            "get_extraobj_url": "/fieldsight/site-dashboard/4119/",
            "get_absolute_url": "/events/notification/45639/",
            "extra_json": '',
            "type": 16,
            "title": "new Site level Submission",
            "date": "2018-07-17T11:13:41.440880Z",
            "extra_message": '',
            "recipient": '',
            "seen_by": []
        },
        # ChannelGroup("notify-{}".format(1)).send({"text": json.dumps(result)})
        ChannelGroup("user-notify-{}".format(1)).send({"text": json.dumps(result)})
        ChannelGroup("org-notify-{}".format(1)).send({"text": json.dumps(result)})
        ChannelGroup("project-notify-{}".format(1)).send({"text": json.dumps(result)})
        self.stdout.write('Successfully created Notification') 
开发者ID:awemulya,项目名称:kobo-predict,代码行数:27,代码来源:notifications.py

示例4: sendNotification

# 需要导入模块: import channels [as 别名]
# 或者: from channels import Group [as 别名]
def sendNotification(notification, recipient):
    result={}
    result['id']= noti.id,
    result['source_uid']= source_user.id,
    result['source_name']= source_user.username,
    result['source_img']= source_user.user_profile.profile_picture.url,
    result['get_source_url']= noti.get_source_url(),
    result['get_event_name']= project.name,
    result['get_event_url']= noti.get_event_url(),
    result['get_extraobj_name']= None,
    result['get_extraobj_url']= None,
    result['get_absolute_url']= noti.get_absolute_url(),
    result['type']= 412,
    result['date']= str(noti.date),
    result['extra_message']= str(count) + " Sites @error " + u'{}'.format(e.message),
    result['seen_by']= [],
    ChannelGroup("notif-user-{}".format(recipient.id)).send({"text": json.dumps(result)}) 
开发者ID:awemulya,项目名称:kobo-predict,代码行数:19,代码来源:tasks.py

示例5: notify_subscribers

# 需要导入模块: import channels [as 别名]
# 或者: from channels import Group [as 别名]
def notify_subscribers(notifications, key):
    """
    Notify all open channels about new notifications
    """

    logger.debug("Broadcasting to subscribers")

    notification_type_ids = models.NotificationType.objects.values('key').filter(key=key)

    for notification_type in notification_type_ids:
        g = Group(
            settings.NOTIFICATION_CHANNEL.format(
                notification_key=notification_type['key']
            )
        )
        g.send(
            {'text': 'new-notification'}
        ) 
开发者ID:django-wiki,项目名称:django-nyt,代码行数:20,代码来源:subscribers.py

示例6: delete_mainstage

# 需要导入模块: import channels [as 别名]
# 或者: from channels import Group [as 别名]
def delete_mainstage(request, id):
    try:
        with transaction.atomic():
            stage = Stage.objects.get(pk=id)
            org = stage.site.project.organization if stage.site else stage.project.organization
            substages = Stage.objects.filter(stage=stage)
            for sub_stage in substages:
                if hasattr(sub_stage, 'stage_forms'):
                    old_fsxf = sub_stage.stage_forms
                    old_fsxf.is_deleted = True
                    old_fsxf.stage = None
                    old_fsxf.save()
                    # desc = "deleted form of stage {} substage {} by {}".format(sub_stage.stage.name, sub_stage.name,
                    #                                                            request.user.username)
                    # noti = old_fsxf.logs.create(source=request.user, type=1, title="form Deleted",
                    #         organization=org, description=desc)
                    # result = {}
                    # result['description'] = desc
                    # result['url'] = noti.get_absolute_url()
                    # ChannelGroup("notify-{}".format(org.id)).send({"text": json.dumps(result)})
                    # ChannelGroup("notify-0").send({"text": json.dumps(result)})
                sub_stage.delete()
            stage.delete()
        return Response({}, status=status.HTTP_200_OK)
    except Exception as e:
        return Response({'error':e.message}, status=status.HTTP_400_BAD_REQUEST) 
开发者ID:awemulya,项目名称:kobo-predict,代码行数:28,代码来源:views.py

示例7: all_notification

# 需要导入模块: import channels [as 别名]
# 或者: from channels import Group [as 别名]
def all_notification(user, message):
        ChannelGroup("%s" % user).send({
            "text": json.dumps({
                "msg": message
            })
        }) 
开发者ID:awemulya,项目名称:kobo-predict,代码行数:8,代码来源:UserRoleViewsets.py

示例8: form_valid

# 需要导入模块: import channels [as 别名]
# 或者: from channels import Group [as 别名]
def form_valid(self, form):
        self.object = form.save()
        noti = self.object.logs.create(source=self.request.user, type=6, title="new Role",
                                       organization=self.object.role.organization,
                                       description="new role {0} updated by {1}".
                                       format(self.object.name, self.request.user.username))
        result = {}
        result['description'] = 'new role {0} update by {1}'.format(self.object.name, self.request.user.username)
        result['url'] = noti.get_absolute_url()
        ChannelGroup("notify-{}".format(self.object.organization.id)).send({"text": json.dumps(result)})
        ChannelGroup("notify-0").send({"text": json.dumps(result)})

        return HttpResponseRedirect(self.get_success_url()) 
开发者ID:awemulya,项目名称:kobo-predict,代码行数:15,代码来源:views.py

示例9: delete

# 需要导入模块: import channels [as 别名]
# 或者: from channels import Group [as 别名]
def delete(self,*args, **kwargs):
        self.object = self.get_object()
        noti = self.object.logs.create(source=self.request.user, type=6, title="new Site",
                                       organization=self.object.project.organization,
                                       description="new role {0} deleted by {1}".
                                       format(self.object.name, self.request.user.username))
        result = {}

        result['description'] = 'new role {0} deleted by {1}'.format(self.object.name, self.request.user.username)

        result['url'] = noti.get_absolute_url()
        ChannelGroup("notify-{}".format(self.object.project.organization.id)).send({"text": json.dumps(result)})
        ChannelGroup("notify-0").send({"text": json.dumps(result)})
        return HttpResponseRedirect(self.get_success_url()) 
开发者ID:awemulya,项目名称:kobo-predict,代码行数:16,代码来源:views.py

示例10: form_valid

# 需要导入模块: import channels [as 别名]
# 或者: from channels import Group [as 别名]
def form_valid(self, form):
        self.object = form.save()
        noti = self.object.logs.create(source=self.request.user, type=9, title="new Organization",
                                       organization=self.object, content_object=self.object,
                                       description="{0} created a new organization named {1}".
                                       format(self.request.user, self.object.name))
        # result = {}
        # result['description'] = '{0} created a new organization named {1} '.format(noti.source.get_full_name(), self.object.name)
        # result['url'] = noti.get_absolute_url()
        # ChannelGroup("notify-{}".format(self.object.id)).send({"text": json.dumps(result)})
        # ChannelGroup("notify-0").send({"text": json.dumps(result)})

        return HttpResponseRedirect(self.get_success_url()) 
开发者ID:awemulya,项目名称:kobo-predict,代码行数:15,代码来源:views.py

示例11: get

# 需要导入模块: import channels [as 别名]
# 或者: from channels import Group [as 别名]
def get(self, *args, **kwargs):
        site = get_object_or_404(Site, pk=self.kwargs.get('pk'), is_active=True)
        site.is_active = False
        site.save()
        task_obj=CeleryTaskProgress.objects.create(user=self.request.user, description="Removal of UserRoles After Site delete", task_type=7, content_object = site)
        if task_obj:
            task = UnassignAllSiteRoles.delay(task_obj.id, site.id)
            task_obj.task_id = task.id
            task_obj.save()
        
        noti = task_obj.logs.create(source=self.request.user, type=36, title="Delete Site",
                               organization=site.project.organization, extra_object=site.project,
                               project=site.project, extra_message="site", site=site, content_object=site,
                               description='{0} deleted of site named {1}'.format(
                                   self.request.user.get_full_name(), site.name))
        return HttpResponseRedirect(reverse('fieldsight:proj-site-list', kwargs={'pk': site.project_id}))

    # def delete(self,*args, **kwargs):
    #     self.kwargs['pk'] = self.get_object().pk
    #     self.object = self.get_object().delete()
    #     # noti = self.object.logs.create(source=self.request.user, type=4, title="new Site",
    #     #                                organization=self.object.organization,
    #     #                                description="new project {0} deleted by {1}".
    #     #                                format(self.object.name, self.request.user.username))
    #     # result = {}
    #     # result['description'] = 'new project {0} deleted by {1}'.format(self.object.name, self.request.user.username)
    #     # result['url'] = noti.get_absolute_url()
    #     # ChannelGroup("notify-{}".format(self.object.organization.id)).send({"text": json.dumps(result)})
    #     # ChannelGroup("notify-0").send({"text": json.dumps(result)})
    #     return HttpResponseRedirect(self.get_success_url())
    # 
开发者ID:awemulya,项目名称:kobo-predict,代码行数:33,代码来源:views.py

示例12: ajax_upload_sites

# 需要导入模块: import channels [as 别名]
# 或者: from channels import Group [as 别名]
def ajax_upload_sites(request, pk):
    form = UploadFileForm(request.POST, request.FILES)
    if form.is_valid():
        count = 0
        project = Project(pk=pk)
        try:
            sites = request.FILES['file'].get_records()
            count = len(sites)
            with transaction.atomic():
                for site in sites:
                    site = dict((k,v) for k,v in site.iteritems() if v is not '')
                    lat = site.get("longitude", 85.3240)
                    long = site.get("latitude", 27.7172)
                    location = Point(lat, long, srid=4326)
                    type_id = int(site.get("type", "0"))
                    _site, created = Site.objects.get_or_create(identifier=str(site.get("id")), name=site.get("name"),
                                                                project=project, type_id=type_id)
                    _site.phone = site.get("phone")
                    _site.address = site.get("address")
                    _site.public_desc = site.get("public_desc"),
                    _site.additional_desc = site.get("additional_desc")
                    _site.location=location
                    if type_id:
                        _site.type = SiteType.objects.get(pk=type_id)
                    _site.save()
            if count:
                noti = project.logs.create(source=request.user, type=12, title="Bulk Sites",
                                       organization=project.organization,
                                       project=project, content_object=project,
                                       extra_message=count + "Sites",
                                       description='{0} created a {1} sites in {2}'.
                                           format(request.user.get_full_name(), count, project.name))
                result = {}
                result['description'] = noti.description
                result['url'] = noti.get_absolute_url()
                ChannelGroup("project-{}".format(project.id)).send({"text": json.dumps(result)})
            return Response({'msg': 'ok'}, status=status.HTTP_200_OK)
        except Exception as e:
            return Response({'file':e.message}, status=status.HTTP_400_BAD_REQUEST)
    return Response(form.errors, status=status.HTTP_400_BAD_REQUEST) 
开发者ID:awemulya,项目名称:kobo-predict,代码行数:42,代码来源:views.py

示例13: ws_paramiko_proxy_c

# 需要导入模块: import channels [as 别名]
# 或者: from channels import Group [as 别名]
def ws_paramiko_proxy_c(message):
    # print(dir(Group('paramiko')))
    Group('paramiko').add(message.reply_channel)
    message.reply_channel.send({'accept':True}) 
开发者ID:ryanrain2016,项目名称:DShell,代码行数:6,代码来源:consumers.py

示例14: ws_paramiko_proxy_d

# 需要导入模块: import channels [as 别名]
# 或者: from channels import Group [as 别名]
def ws_paramiko_proxy_d(message):
    Group('paramiko').discard(message.reply_channel) 
开发者ID:ryanrain2016,项目名称:DShell,代码行数:4,代码来源:consumers.py

示例15: ws_webshell

# 需要导入模块: import channels [as 别名]
# 或者: from channels import Group [as 别名]
def ws_webshell(message,id):
    content = json.loads(message.content['text'])
    msg = dict(cmd='stream',data=content['cmd'],id=id,reply_channel=message.reply_channel.name)
    Group('paramiko').send({'text':json.dumps(msg)}) 
开发者ID:ryanrain2016,项目名称:DShell,代码行数:6,代码来源:consumers.py


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