@login_required
@require_POST
def add_leader(request, group_slug):
 prof = get_object_or_404(GroupProfile, slug=group_slug)
 if (not _user_can_manage_leaders(request.user, prof)):
  raise PermissionDenied
 form = AddUserForm(request.POST)
 if form.is_valid():
  for user in form.cleaned_data['users']:
   if (prof.group not in user.groups.all()):
    user.groups.add(prof.group)
   prof.leaders.add(user)
  msg = _('{users} added to the group leaders successfully!').format(users=request.POST.get('users'))
  messages.add_message(request, messages.SUCCESS, msg)
  return HttpResponseRedirect(prof.get_absolute_url())
 msg = _('There were errors adding leaders to the group, see below.')
 messages.add_message(request, messages.ERROR, msg)
 return profile(request, group_slug, leader_form=form)

@ login_required @ require_POST def add_leader ( request , group_slug ) : prof = get_object_or_404 ( GroupProfile , slug = group_slug ) if ( not _user_can_manage_leaders ( request . user , prof ) ) : raise PermissionDenied form = AddUserForm ( request . POST ) if form . is_valid ( ) : for user in form . cleaned_data [ 'users' ] : if ( prof . group not in user . groups . all ( ) ) : user . groups . add ( prof . group ) prof . leaders . add ( user ) msg = _ ( '{users} added to the group leaders successfully!' ) . format ( users = request . POST . get ( 'users' ) ) messages . add_message ( request , messages . SUCCESS , msg ) return HttpResponseRedirect ( prof . get_absolute_url ( ) ) msg = _ ( 'There were errors adding leaders to the group, see below.' ) messages . add_message ( request , messages . ERROR , msg ) return profile ( request , group_slug , leader_form = form )
add a leader to the group .