def edit_profile(request):
    if request.method == 'POST':
        form = EditProfileForm(request.POST, instance=request.user)
        if form.is_valid():
            form.save()
            return redirect('view_profile')
    else:
            form = EditProfileForm(instance=request.user)
            return render(request, 'edit_profile.html', {'form': form})
Beispiel #2
0
def edit_profile(request):
    if request.method == 'POST':
        form = EditProfileForm(request.POST, instance=request.user)

        if form.is_valid():
            form.save()
            return redirect('accounts/profile')
    else:
        form = EditProfileForm(instance=request.user)
        args = {'form': form}
        return render(request, 'user_view.html', args)
Beispiel #3
0
def pythonista_change_info(request):
    profile = Profile.objects.filter(user=request.user).first()
    form = EditProfileForm(instance=profile)
    if request.method == 'POST':
        form = EditProfileForm(instance=profile, data=request.POST)
        if form.is_valid():
            user = form.save()
            return render(
                request, 'pythonistas-area-password-change.html', {
                    'form': form,
                    'message':
                    'Suas informações foram atualizadas com sucesso!'
                })
        else:
            messages.error(request, 'Por favor, corrija os erros abaixo.')
    else:
        form = EditProfileForm(instance=profile)
    return render(request, 'pythonistas-area-info-change.html', {'form': form})
Beispiel #4
0
def edit_profile(request):
    user = request.user
    initial_values = {
        'username': user.username,
        'driver_license': user.profile.driver_license,
        'driver_license_state': user.profile.driver_license_state,
        'license_plate': user.profile.car_license_plate,
        'license_plate_state': user.profile.car_license_state,
        'photo': user.profile.photo,
        'home_address': user.profile.home_address,
        'home_city': user.profile.home_city,
        'home_state': user.profile.home_state,
        'home_zipcode': user.profile.home_zipcode
    }
    form = EditProfileForm(request.POST or None,
                           request.FILES or None,
                           instance=request.user,
                           initial=initial_values)
    if form.is_valid():
        user = form.save()
        user.refresh_from_db(
        )  # load the profile instance created by the signal
        user.first_name = form.cleaned_data.get('first_name')
        user.last_name = form.cleaned_data.get('last_name')
        user.profile.birth_date = form.cleaned_data.get('birth_date')
        user.profile.driver_license = form.cleaned_data.get('driver_license')
        user.profile.driver_license_state = form.cleaned_data.get(
            'driver_license_state')
        user.profile.car_license_plate = form.cleaned_data.get('license_plate')
        user.profile.car_license_state = form.cleaned_data.get(
            'license_plate_state')
        user.profile.home_address = form.cleaned_data.get('home_address')
        user.profile.home_city = form.cleaned_data.get('home_city')
        user.profile.home_state = form.cleaned_data.get('home_state')
        user.profile.home_zipcode = form.cleaned_data.get('home_zipcode')
        user.save()
        return redirect('home')

    return render(request, 'edit_profile.html', {'form': form})