當前位置: 首頁>>代碼示例>>Python>>正文


Python Group.add方法代碼示例

本文整理匯總了Python中channels.Group.add方法的典型用法代碼示例。如果您正苦於以下問題:Python Group.add方法的具體用法?Python Group.add怎麽用?Python Group.add使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在channels.Group的用法示例。


在下文中一共展示了Group.add方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: connect_wait_page

# 需要導入模塊: from channels import Group [as 別名]
# 或者: from channels.Group import add [as 別名]
def connect_wait_page(message, params):
    session_pk, page_index, model_name, model_pk = params.split(',')
    session_pk = int(session_pk)
    page_index = int(page_index)
    model_pk = int(model_pk)

    group_name = channels_wait_page_group_name(
        session_pk, page_index, model_name, model_pk
    )
    group = Group(group_name)
    group.add(message.reply_channel)

    # in case message was sent before this web socket connects

    if model_name == 'group':
        ready = CompletedGroupWaitPage.objects.filter(
            page_index=page_index,
            group_pk=model_pk,
            session_pk=session_pk,
            after_all_players_arrive_run=True).exists()
    else: # subsession
        ready = CompletedSubsessionWaitPage.objects.filter(
            page_index=page_index,
            session_pk=session_pk,
            after_all_players_arrive_run=True).exists()
    if ready:
        message.reply_channel.send(
            {'text': json.dumps(
                {'status': 'ready'})})
開發者ID:jpg75,項目名稱:otree-core,代碼行數:31,代碼來源:consumers.py

示例2: ws_connect

# 需要導入模塊: from channels import Group [as 別名]
# 或者: from channels.Group import add [as 別名]
def ws_connect(message):
    """
    Channels connection setup.
    Register the current client on the related Group according to the language
    """
    prefix, language = message['path'].strip('/').split('/')
    gr = Group('knocker-{0}'.format(language))
    gr.add(message.reply_channel)
    message.channel_session['knocker'] = language
開發者ID:adamchainz,項目名稱:django-knocker,代碼行數:11,代碼來源:consumers.py

示例3: sign_in

# 需要導入模塊: from channels import Group [as 別名]
# 或者: from channels.Group import add [as 別名]
 def sign_in(self, request, data, *args, **kwargs):
     serializer = IsAuthenticatedSerializer(data=data)
     serializer.is_valid(raise_exception=True)
     band_id = kwargs.get("band_id")
     user = self.check_chat_perms(serializer, band_id)
     if user is not None:
         request.channel_session["user"] = user.id
         group = Group(self.CHAT_GROUP_TEMPLATE % band_id)
         group.add(request.reply_channel)
         messages = Message.objects.select_related("author").filter(band_id=band_id)[: self.MESSAGES_COUNT][::-1]
         self.route_send(request.reply_channel, MessagesSerializer({"messages": messages}).data)
     else:
         raise PermissionDenied
開發者ID:YetAnotherTeam,項目名稱:jatumba-backend,代碼行數:15,代碼來源:web_socket.py

示例4: connect_auto_advance

# 需要導入模塊: from channels import Group [as 別名]
# 或者: from channels.Group import add [as 別名]
def connect_auto_advance(message, params):
    participant_code, page_index = params.split(',')
    page_index = int(page_index)

    group = Group('auto-advance-{}'.format(participant_code))
    group.add(message.reply_channel)

    # in case message was sent before this web socket connects
    participant = Participant.objects.get(code=participant_code)
    if participant._index_in_pages > page_index:
        message.reply_channel.send(
            {'text': json.dumps(
                {'new_index_in_pages': participant._index_in_pages})}
        )
開發者ID:KeyangRU,項目名稱:otree-core,代碼行數:16,代碼來源:consumers.py

示例5: connect_wait_for_session

# 需要導入模塊: from channels import Group [as 別名]
# 或者: from channels.Group import add [as 別名]
def connect_wait_for_session(message, pre_create_id):
    group = Group(channels_create_session_group_name(pre_create_id))
    group.add(message.reply_channel)

    # in case message was sent before this web socket connects
    if Session.objects.filter(_pre_create_id=pre_create_id):
        group.send(
        {'text': json.dumps(
            {'status': 'ready'})}
        )
    elif FailedSessionCreation.objects.filter(
        pre_create_id=pre_create_id
    ).exists():
        group.send(
            {'text': json.dumps(
                {'error': 'Failed to create session. Check the server logs.'})}
        )
開發者ID:jpg75,項目名稱:otree-core,代碼行數:19,代碼來源:consumers.py

示例6: connect_wait_for_session

# 需要導入模塊: from channels import Group [as 別名]
# 或者: from channels.Group import add [as 別名]
def connect_wait_for_session(message, pre_create_id):
    group = Group(channels_create_session_group_name(pre_create_id))
    group.add(message.reply_channel)

    # in case message was sent before this web socket connects
    if Session.objects.filter(_pre_create_id=pre_create_id, ready=True):
        group.send(
            {'text': json.dumps(
                {'status': 'ready'})}
        )
    else:
        failure = FailedSessionCreation.objects.filter(
            pre_create_id=pre_create_id
        ).first()
        if failure:
            group.send(
                {'text': json.dumps(
                    {'error': failure.message,
                     'traceback': failure.traceback})}
            )
開發者ID:goakichang,項目名稱:otree-core,代碼行數:22,代碼來源:consumers.py

示例7: connect_auto_advance

# 需要導入模塊: from channels import Group [as 別名]
# 或者: from channels.Group import add [as 別名]
def connect_auto_advance(message, params):
    participant_code, page_index = params.split(',')
    page_index = int(page_index)

    group = Group('auto-advance-{}'.format(participant_code))
    group.add(message.reply_channel)

    # in case message was sent before this web socket connects

    try:
        participant = Participant.objects.get(code=participant_code)
    except Participant.DoesNotExist:
        message.reply_channel.send(
            {'text': json.dumps(
                # doesn't get shown because not yet localized
                {'error': 'Participant not found in database.'})})
        return
    if participant._index_in_pages > page_index:
        message.reply_channel.send(
            {'text': json.dumps(
                {'new_index_in_pages': participant._index_in_pages})})
開發者ID:goakichang,項目名稱:otree-core,代碼行數:23,代碼來源:consumers.py

示例8: connect_wait_page

# 需要導入模塊: from channels import Group [as 別名]
# 或者: from channels.Group import add [as 別名]
def connect_wait_page(message, params):
    app_label, page_index, model_name, model_pk = params.split(',')
    page_index = int(page_index)
    model_pk = int(model_pk)


    group_name = channels_wait_page_group_name(
        app_label, page_index, model_name, model_pk
    )
    group = Group(group_name)
    group.add(message.reply_channel)

    # in case message was sent before this web socket connects
    # fixme: app name or app label?
    models_module = common_internal.get_models_module(app_label)

    GroupOrSubsession = {
        'subsession': getattr(models_module, 'Subsession'),
        'group': getattr(models_module, 'Group')
    }[model_name]

    group_or_subsession = GroupOrSubsession.objects.get(pk=model_pk)

    participants_for_this_page = set(
        p.participant for p in group_or_subsession.player_set.all()
    )

    unvisited = set(
        p for p in participants_for_this_page if
        p._index_in_pages < page_index
    )

    if not unvisited:
        message.reply_channel.send(
            {'text': json.dumps(
                {'status': 'ready'})})
開發者ID:KeyangRU,項目名稱:otree-core,代碼行數:38,代碼來源:consumers.py

示例9: connect_auto_advance

# 需要導入模塊: from channels import Group [as 別名]
# 或者: from channels.Group import add [as 別名]
def connect_auto_advance(message, params):
    participant_code, page_index = params.split(',')
    page_index = int(page_index)

    group = Group('auto-advance-{}'.format(participant_code))
    group.add(message.reply_channel)

    # in case message was sent before this web socket connects

    result = Participant.objects.filter(
            code=participant_code).values_list(
        '_index_in_pages', flat=True)
    try:
        page_should_be_on = result[0]
    except IndexError:
        message.reply_channel.send(
            {'text': json.dumps(
                # doesn't get shown because not yet localized
                {'error': 'Participant not found in database.'})})
        return
    if page_should_be_on > page_index:
        message.reply_channel.send(
            {'text': json.dumps(
                {'auto_advanced': True})})
開發者ID:ross2604,項目名稱:otree-core,代碼行數:26,代碼來源:consumers.py

示例10: chat_connect

# 需要導入模塊: from channels import Group [as 別名]
# 或者: from channels.Group import add [as 別名]
def chat_connect(message):
    room = message.content['path'].strip('/')
    message.channel_session['room'] = room

    group = Group('chat-%s' % room)
    group.add(message.reply_channel)
開發者ID:bionikspoon,項目名稱:django_channels_chat,代碼行數:8,代碼來源:consumers.py

示例11: ws_connect

# 需要導入模塊: from channels import Group [as 別名]
# 或者: from channels.Group import add [as 別名]
def ws_connect(message, room):
    g = Group('chat:{}'.format(room))
    data = {'text': 'A new user connected', 'type': 'log'}
    g.send({'text': json.dumps(data)})
    g.add(message.reply_channel)
開發者ID:mediainteractiva,項目名稱:chan,代碼行數:7,代碼來源:consumers.py


注:本文中的channels.Group.add方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。