Exemplo n.º 1
0
def config_settings_new_user(request):
    """The settings view for creating a new user
    """
    # get form
    if request.method == 'POST':
        user_form = UserForm(request.POST)
        profile_form = UserProfileForm(request.POST)
        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save()
            profile = profile_form.save(commit=False)
            profile.user = user
            profile.save()
            return HttpResponseRedirect(reverse('player:config_settings'))
        ctx = {
            'user_form': user_form,
            'profile_form': profile_form
        }
        return csrf_render(request, 'config/settings_new_user.html', ctx)
    else:
        user_form = UserForm()
        profile_form = UserProfileForm()   
        ctx = {
            'user_form': user_form,
            'profile_form': profile_form
        }
        return csrf_render(request, 'config/settings_new_user.html', ctx)
Exemplo n.º 2
0
def config_settings_edit_user(request, userid):
    """The settings view for editing a user
    
    Keyword arguments:
    userid -- The id of the user
    """
    # get form
    if request.method == 'POST':
        user = get_object_or_404(User, id=userid)
        user_profile = user.get_profile()
        user_form = UserForm(request.POST, instance=user)
        profile_form = UserProfileForm(request.POST, instance=user_profile)
        if user_form.is_valid() and profile_form.is_valid():
            user_form.save()
            profile_form.save()
            return HttpResponseRedirect(reverse('player:config_settings'))
        ctx = {
            'user_form': user_form,
            'profile_form': profile_form,
            'config_user': user
        }
        return csrf_render(request, 'config/settings_edit_user.html', ctx)
    else:
        user = get_object_or_404(User, id=userid)
        user_profile = user.get_profile()
        user_form = UserForm(instance=user)
        profile_form = UserProfileForm(instance=user_profile)    
        ctx = {
            'user_form': user_form,
            'profile_form': profile_form,
            'config_user': user
        }
        return csrf_render(request, 'config/settings_edit_user.html', ctx)