Ejemplo n.º 1
0
def edit_profile():
    form = EditProfileForm()
    if form.validate_on_submit():
        current_user.username = form.username.data
        current_user.about_me = form.about_me.data
        db.session.commit()
        flash('Your changes have been saved.')
        return redirect(url_for('edit_profile'))
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.about_me.data = current_user.about_me
    return render_template('edit_profile.html',
                           title='Edit Profile',
                           form=form)
Ejemplo n.º 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('view_profile')
    else:
            form = EditProfileForm(instance=request.user)
            return render(request, 'edit_profile.html', {'form': form})
Ejemplo n.º 3
0
def edit_profile(request):
    """
    Show profile edit page and save user profile information on save.
    """
    form = EditProfileForm(request.FILES, request.POST)
    user_profile = request.user.profile
    user_info_dict = {
        'user_id': request.user.id,
        'username': request.user,
        'bio': user_profile.bio,
        'gender': user_profile.gender,
        'date_of_birth': user_profile.date_of_birth,
        'mobile_number': user_profile.mobile_number,
        'address': user_profile.address,
        'city': user_profile.city,
        'country': user_profile.country,
        'photo': user_profile.photo,
    }
    context = {'user_info_dict': user_info_dict, 'form': form}
    if request.method == 'POST':
        post_data = request.POST.copy()
        post_data['date_of_birth'] = parse(post_data['date_of_birth'])
        form = EditProfileForm(post_data, instance=user_profile)
        if form.is_valid():
            Profile.objects.filter(user=request.user).update(
                bio=form.data['bio'],
                gender=form.data['gender'],
                photo=request.FILES['profile_photo'],
                mobile_number=form.data['mobile_number'],
                address=form.data['address'],
                city=form.data['city'],
                country=form.data['country'],
            )
            return redirect(reverse('core:profile'))

        print 'Profile for user "%s" failed to save due to validation errors: %s' % (
            request.user.username, form.errors)
        messages.error(request, 'Form is invalid', context)
        return render(request, 'profile_edit.html')

    return render(request, 'profile_edit.html', context)
Ejemplo n.º 4
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)
Ejemplo n.º 5
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})
Ejemplo n.º 6
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})