Beispiel #1
0
def _add_one_user(request):
    af = forms.AddUserForm(request, data=request.REQUEST)

    if af.is_valid():
        create_user(**af.clean())
        request.session['users_added'] = "Succesfully added user"
        return redirect(reverse(add))

    return forms.AddMultipleUsersForm(request), af
Beispiel #2
0
def _add_multiple_users(request):
    amf = forms.AddMultipleUsersForm(request, data=request.REQUEST, files=request.FILES)

    if amf.is_valid():
        props = dict(
            affiliation=amf.cleaned_data['affiliation'],
            language=amf.cleaned_data['language'],
            role=amf.cleaned_data['role']
        )

        for user in amf.cleaned_data['csv']:
            create_user(**dict(itertools.chain(props.items(), user.items())))

        request.session['users_added'] = ("Succesfully added {} user(s)"
                                            .format(len(amf.cleaned_data['csv'])))

        # Users created
        return redirect(reverse(add))

    return amf, forms.AddUserForm(request)
Beispiel #3
0
def add(request):
    add_form = forms.AddUserForm(request)
    add_multiple_form = forms.AddMultipleUsersForm(request)

    message = session_pop(request.session, "users_added")
    return render(request, "user_add.html", locals())