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


Python Group.is_member方法代碼示例

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


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

示例1: handle

# 需要導入模塊: from tendenci.apps.user_groups.models import Group [as 別名]
# 或者: from tendenci.apps.user_groups.models.Group import is_member [as 別名]
    def handle(self, *args, **kwargs):
        from tendenci.apps.site_settings.models import Setting
        from tendenci.apps.user_groups.models import Group, GroupMembership
        from tendenci.apps.corporate_memberships.models import CorpMembershipRep
        verbosity = int(kwargs['verbosity'])

        cmrg_setting, created = Setting.objects.get_or_create(
                        name='corpmembershiprepsgroupid')
        description = 'This Group is for all corporate membership representatives. ' + \
                    'Adding or deleting a representative will automatically ' + \
                    'add (or remove) the user to (or from) this group.'
        if created:
            cmrg_setting.label = 'Corporate Membership Representatives Group Id'
            cmrg_setting.description = description
            cmrg_setting.data_type = 'int'
            cmrg_setting.value = '0'
            cmrg_setting.default_value = '0'
            cmrg_setting.input_type = 'text'
            cmrg_setting.input_value = ''
            cmrg_setting.client_editable = False
            cmrg_setting.store = True
            cmrg_setting.scope = 'module'
            cmrg_setting.scope_category = 'corporate_memberships'
            cmrg_setting.save()

        group = None
        group_id = int(cmrg_setting.value)
        if group_id:
            [group] = Group.objects.filter(id=group_id)[:1] or [None]

        if not group:
            # first check if we have a default group. if not, create one
            # so that this reps group won't become the one with id=1
            Group.objects.get_or_create_default()

            group = Group(
                      name='Corporate Membership Representatives',
                      slug='corporate-membership-representatives',
                      label='Corporate Membership Representatives',
                      type='system_generated',
                      show_as_option=False,
                      allow_self_add=False,
                      allow_self_remove=False,
                      description=description,
                      allow_anonymous_view=False,
                      allow_user_view=False,
                      allow_member_view=False,
                      allow_user_edit=False,
                      allow_member_edit=False)
            group.save()
            cmrg_setting.value = str(group.id)
            cmrg_setting.save()
        else:
            # remove all non-reps from group
            for user in group.members.all():
                if not CorpMembershipRep.objects.filter(user=user).exists():
                    if verbosity >= 2:
                        print('Removing user "%s" from group' % user.username)
                    gm = GroupMembership.objects.get(group=group,
                                                 member=user)
                    gm.delete()

        # add reps to group
        for rep in CorpMembershipRep.objects.all():
            user = rep.user
            if not group.is_member(user):
                if verbosity >= 2:
                    print('Adding user "%s" to group' % user.username)
                group.add_user(user)
開發者ID:BIGGANI,項目名稱:tendenci,代碼行數:71,代碼來源:update_corp_reps_group.py


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