예제 #1
0
def add_to_locale(request, locale_code, role):
    """Add a user to the locale role."""
    locale = get_object_or_404(Locale, locale=locale_code)

    if not _user_can_edit(request.user, locale):
        raise PermissionDenied

    form = AddUserForm(request.POST)
    if form.is_valid():
        for user in form.cleaned_data['users']:
            getattr(locale, ROLE_ATTRS[role]).add(user)
        msg = _('{users} added successfully!').format(
            users=request.POST.get('users'))
        messages.add_message(request, messages.SUCCESS, msg)
        return HttpResponseRedirect(locale.get_absolute_url())

    msg = _('There were errors adding users, see below.')
    messages.add_message(request, messages.ERROR, msg)
    return locale_details(request, locale_code, **{role + '_form': form})
예제 #2
0
def add_member(request, group_slug):
    """Add a member to the group."""
    prof = get_object_or_404(GroupProfile, slug=group_slug)

    if not _user_can_edit(request.user, prof):
        raise PermissionDenied

    form = AddUserForm(request.POST)
    if form.is_valid():
        for user in form.cleaned_data['users']:
            user.groups.add(prof.group)
        msg = _('{users} added to the group 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 members to the group, see below.')
    messages.add_message(request, messages.ERROR, msg)
    return profile(request, group_slug, member_form=form)
예제 #3
0
파일: views.py 프로젝트: bajubullet/kitsune
def add_member(request, group_slug):
    """Add a member to the group."""
    prof = get_object_or_404(GroupProfile, slug=group_slug)

    if not _user_can_edit(request.user, prof):
        raise PermissionDenied

    form = AddUserForm(request.POST)
    if form.is_valid():
        for user in form.cleaned_data['users']:
            user.groups.add(prof.group)
        msg = _('{users} added to the group 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 members to the group, see below.')
    messages.add_message(request, messages.ERROR, msg)
    return profile(request, group_slug, member_form=form)
예제 #4
0
def add_to_locale(request, locale_code, role):
    """Add a user to the locale role."""
    locale = get_object_or_404(Locale, locale=locale_code)

    if not _user_can_edit(request.user, locale):
        raise PermissionDenied

    form = AddUserForm(request.POST)
    if form.is_valid():
        for user in form.cleaned_data['users']:
            getattr(locale, ROLE_ATTRS[role]).add(user)
        msg = _('{users} added successfully!').format(
            users=request.POST.get('users'))
        messages.add_message(request, messages.SUCCESS, msg)
        return HttpResponseRedirect(locale.get_absolute_url())

    msg = _('There were errors adding users, see below.')
    messages.add_message(request, messages.ERROR, msg)
    return locale_details(request, locale_code, **{role + '_form': form})