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


Python GroupMembership.role方法代码示例

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


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

示例1: groupmembership_bulk_add

# 需要导入模块: from tendenci.apps.user_groups.models import GroupMembership [as 别名]
# 或者: from tendenci.apps.user_groups.models.GroupMembership import role [as 别名]
def groupmembership_bulk_add(request, group_slug,
                        form_class=GroupMembershipBulkForm,
                        template_name="user_groups/member_add.html"):
    group = get_object_or_404(Group, slug=group_slug)

    user_count = User.objects.all().count()
    if user_count > 1000:
        return HttpResponseRedirect(reverse('group.adduser_redirect'))

    if request.method == 'POST':
        form = form_class(group, request.POST)
        if form.is_valid():
            members = form.cleaned_data['members']

            old_members = GroupMembership.objects.filter(group=group)

            #delete removed groupmemberships
            if members:
                for old_m in old_members:
                    try:
                        members.get(pk=old_m.member.pk)
                    except User.DoesNotExist:
                        EventLog.objects.log(instance=old_m)
                        old_m.delete()
            else: #when members is None
                for old_m in old_members:
                    EventLog.objects.log(instance=old_m)
                    old_m.delete()

            for m in members:
                try:
                    group_membership = GroupMembership.objects.get(group=group, member=m)
                except GroupMembership.DoesNotExist:
                    group_membership = GroupMembership(group=group, member=m)
                    group_membership.creator_id = request.user.id
                    group_membership.creator_username = request.user.username

                group_membership.role=form.cleaned_data['role']
                group_membership.status=form.cleaned_data['status']
                group_membership.status_detail=form.cleaned_data['status_detail']
                group_membership.owner_id =  request.user.id
                group_membership.owner_username = request.user.username

                group_membership.save()

                EventLog.objects.log(instance=group_membership)
            return HttpResponseRedirect(group.get_absolute_url())
    else:
        member_label = request.GET.get('member_label', 'username')
        form = form_class(group, member_label=member_label)

    return render_to_response(template_name, locals(), context_instance=RequestContext(request))
开发者ID:jiwonlee777,项目名称:tendenci,代码行数:54,代码来源:views.py

示例2: execute_function

# 需要导入模块: from tendenci.apps.user_groups.models import GroupMembership [as 别名]
# 或者: from tendenci.apps.user_groups.models.GroupMembership import role [as 别名]
 def execute_function(self, entry, value, user=None):
     if self.field_function == "GroupSubscription":
         if value:
             for val in self.choices.split(","):
                 group = Group.objects.get(name=val.strip())
                 if user:
                     try:
                         group_membership = GroupMembership.objects.get(group=group, member=user)
                     except GroupMembership.DoesNotExist:
                         group_membership = GroupMembership(group=group, member=user)
                         group_membership.creator_id = user.id
                         group_membership.creator_username = user.username
                         group_membership.role = "subscriber"
                         group_membership.owner_id = user.id
                         group_membership.owner_username = user.username
                         group_membership.save()
开发者ID:bpotterschipul,项目名称:tendenci,代码行数:18,代码来源:models.py

示例3: execute_function

# 需要导入模块: from tendenci.apps.user_groups.models import GroupMembership [as 别名]
# 或者: from tendenci.apps.user_groups.models.GroupMembership import role [as 别名]
 def execute_function(self, entry, value, user=None):
     if self.field_function == "GroupSubscription":
         if value:
             for val in self.function_params.split(','):
                 group = Group.objects.get(name=val)
                 if user:
                     try:
                         group_membership = GroupMembership.objects.get(group=group, member=user)
                     except GroupMembership.DoesNotExist:
                         group_membership = GroupMembership(group=group, member=user)
                         group_membership.creator_id = user.id
                         group_membership.creator_username = user.username
                         group_membership.role = 'subscriber'
                         group_membership.owner_id = user.id
                         group_membership.owner_username = user.username
                         group_membership.save()
                 else:
                     entry.subscribe(group)  # subscribe form-entry to a group
开发者ID:Spacepoints,项目名称:tendenci,代码行数:20,代码来源:models.py

示例4: forwards

# 需要导入模块: from tendenci.apps.user_groups.models import GroupMembership [as 别名]
# 或者: from tendenci.apps.user_groups.models.GroupMembership import role [as 别名]
    def forwards(self, orm):
        from django.contrib.auth.models import User
        from tendenci.apps.profiles.models import Profile
        from tendenci.apps.subscribers.models import GroupSubscription, SubscriberData
        from tendenci.apps.user_groups.models import GroupMembership

        phone_labels = ["Phone", "phone", "Phone Number", "phone number", "Home Phone", "Cell Phone"]
        for sub in GroupSubscription.objects.all():
            sub_email = sub.email

            if sub_email:
                if sub.subscriber and sub.subscriber.creator:
                    user = sub.subscriber.creator
                else:
                    if User.objects.filter(email=sub_email).exists():
                        user = User.objects.filter(email=sub_email).order_by('last_login')[0]
                    elif User.objects.filter(username=sub_email).exists():
                        user = User.objects.filter(username=sub_email).order_by('last_login')[0]
                    else:
                        user = User(username=sub_email[:30], email=sub_email, is_active=False)
                        if SubscriberData.objects.filter(field_label="First Name", subscription=sub):
                            user.first_name = SubscriberData.objects.filter(field_label="First Name", subscription=sub)[0].value
                        if SubscriberData.objects.filter(field_label="Last Name", subscription=sub):
                            user.last_name = SubscriberData.objects.filter(field_label="Last Name", subscription=sub)[0].value
                        user.save()
                        profile = Profile(user=user, owner=user, creator=user)
                        if SubscriberData.objects.filter(field_label__in=phone_labels, subscription=sub):
                            profile.phone = SubscriberData.objects.filter(field_label__in=phone_labels, subscription=sub)[0].value
                        profile.save()
                try:
                    group_membership = GroupMembership.objects.get(group=sub.group, member=user)
                except GroupMembership.DoesNotExist:
                    group_membership = GroupMembership(group=sub.group, member=user)
                    group_membership.creator_id = user.id
                    group_membership.creator_username = user.username
                    group_membership.role = 'subscriber'
                    group_membership.owner_id = user.id
                    group_membership.owner_username = user.username
                    group_membership.save()
开发者ID:BillTheBest,项目名称:tendenci,代码行数:41,代码来源:0002_convert_subscribers.py


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