本文整理汇总了Python中tendenci.apps.user_groups.models.GroupMembership.status方法的典型用法代码示例。如果您正苦于以下问题:Python GroupMembership.status方法的具体用法?Python GroupMembership.status怎么用?Python GroupMembership.status使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tendenci.apps.user_groups.models.GroupMembership
的用法示例。
在下文中一共展示了GroupMembership.status方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: groupmembership_bulk_add
# 需要导入模块: from tendenci.apps.user_groups.models import GroupMembership [as 别名]
# 或者: from tendenci.apps.user_groups.models.GroupMembership import status [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))
示例2: do_user_import
# 需要导入模块: from tendenci.apps.user_groups.models import GroupMembership [as 别名]
# 或者: from tendenci.apps.user_groups.models.GroupMembership import status [as 别名]
def do_user_import(request, user, user_object_dict, setting_dict):
"""
the real work is here - do the insert or update
"""
insert = not bool(user) # insert or update
user = user or User() # existing or new user
override = setting_dict['override'] # update ALL fields
# insert/update user
for field in user_field_names:
if field == 'password' or field == 'username' or \
(not insert and field in setting_dict['key']):
continue
if field in user_object_dict:
if override:
setattr(user, field, user_object_dict[field])
else:
# fill out the blank field only
if getattr(user, field) == '':
setattr(user, field, user_object_dict[field])
if insert:
if 'username' in user_object_dict: # set username
user.username = user_object_dict['username']
# generate if not username
user.username = get_unique_username(user)
if 'password' in user_object_dict and (insert or override):
user.set_password(user_object_dict['password'])
if not user.password:
user.set_password(User.objects.make_random_password(length=8))
user.is_active = bool(setting_dict['interactive'])
if not bool(validate_email(user.email)):
user.email = '' # if not valid; empty it out
# loop through user properties; truncate at max_length
for key, value in user.__dict__.items():
max_length = 90
try:
max_length = User._meta.get_field(key).max_length
except FieldDoesNotExist:
max_length = None
if max_length: # truncate per max_length field attribute
setattr(user, key, value[:max_length])
# username and email required
if user.username and user.email:
# insert/update record
if insert:
user.save(force_insert=True)
else:
user.save(force_update=True)
try: # get or create
profile = user.profile
except Profile.DoesNotExist:
profile = Profile.objects.create(user=user,
creator=request.user,
creator_username=request.user.username,
owner=request.user,
owner_username=request.user.username,
)
for field in profile_field_names:
if field in user_object_dict:
if override:
setattr(profile, field, user_object_dict[field])
else:
# fill out the blank field only
if getattr(profile, field) == '':
setattr(profile, field, user_object_dict[field])
profile.save()
# add to group
if setting_dict['group']:
try:
gm = GroupMembership.objects.get(group=setting_dict['group'],
member=user)
except GroupMembership.DoesNotExist:
gm = GroupMembership()
gm.member = user
gm.group = setting_dict['group']
gm.creator_id = request.user.id
gm.creator_username = request.user.username
gm.owner_id = request.user.id
gm.owner_username = request.user.username
gm.status = 1
gm.status_detail = 'active'
gm.save()
return user