Esempio n. 1
0
def leave(request, group, context_dict):
    if group.data is None:
        return (403, 'Can\'t leave your private user-group.')

    if not context_dict['is_member']:
        return (403, 'You are not a member of this group.')

    if request.method == 'POST':
        if request.POST.get('confirm') == u'1':
            request.user.groups.remove(group)

            user_refresh_group_cache([request.user.id])
            group.data.cache_member_count = group.data.get_members().count()
            group.data.save(force_update=True)
            _action.add(request.user, _action.GROUP_LEAVE,
                action_object=request.user, target=group, group=group)
            return ('/usergroup/', )

    return context_dict
Esempio n. 2
0
def members(request, group, context_dict):
    if context_dict['can_add_members'] and request.method == 'POST':
        form = UserEntryForm(request.POST)
        if form.is_valid():
            created_user_ids = []
            users = form.cleaned_data['list']
            for user in users:
                #user.groups.add(group)
                dummy, created = User.groups.through.objects.get_or_create(
                        user=user, group=group)
                if created:
                    created_user_ids.append(user.id)
                    _action.add(request.user, _action.GROUP_ADD,
                        action_object=user, target=group, group=group)
            # TODO: manually create function like 'group_members_update'
            user_refresh_group_cache(created_user_ids)
            group.data.cache_member_count = group.data.get_members().count()
            group.data.save()
            form = UserEntryForm()
    else:
        form = UserEntryForm()

    context_dict['form'] = form
    return context_dict
Esempio n. 3
0
 def refresh_group_cache(self, request, queryset):
     user_ids = list(queryset.values_list('user_id', flat=True))
     user_refresh_group_cache(user_ids)