Beispiel #1
0
def update_friend(request, id):
    frid = Friends.objects.get(id=id)
    if request.method=='POST':
        form = UserUpdateForm(request.POST, instance=frid)
        if form.is_valid():
            form.save()
            #form = UserUpdateForm(None)
        return redirect('/friends')
    return render(request, 'home/update_friend.html', {'f':frid})
Beispiel #2
0
def add_friend(request):
    form = AddFriendForm() # refresh the form
    if request.method=='POST':
        form = AddFriendForm(request.POST or None)
        if form.is_valid():
            form.save()
            form = UserUpdateForm(None)

    return render(request, 'home/add_friend.html', {'a_form':form}) 
Beispiel #3
0
def profile(request):
    if request.method == 'POST':
        u_form = UserUpdateForm(request.POST, instance=request.user)
        p_form = ProfileUpdateForm(request.POST,
                                   request.FILES,
                                   instance=request.user.profile)
        if u_form.is_valid() and p_form.is_valid():
            u_form.save()
            p_form.save()
            messages.success(request, f'Account updated successfully!')
            return redirect('profile')
    else:
        u_form = UserUpdateForm(instance=request.user)
        p_form = ProfileUpdateForm(instance=request.user.profile)
    context = {'u_form': u_form, 'p_form': p_form}
    return render(request, 'home/profile.html', context)
Beispiel #4
0
def user_update(request):
    if request.method == 'POST':
        form = UserUpdateForm(request.POST, instance=request.user)
        if form.is_valid():
            user = form.save()
            messages.success(request, 'Your Profile was successfully updated!')
            return HttpResponseRedirect('profile')
    else:
        form = UserUpdateForm(instance=request.user)
    context = {'page': 'user',
               'form': form,
              }
    return render(request, "user_update.html", context)
Beispiel #5
0
def user_update(request):
    if request.method == 'POST':
        user_form = UserUpdateForm(request.POST, instance = request.user)
        profile_form = ProfileUpdateForm(request.POST, request.FILES, instance= request.user.userprofile)
        if user_form.is_valid() and profile_form.is_valid():
            user_form.save()
            profile_form.save()
            messages.success(request, 'Your account has been updated!')
            return redirect('/user')
        else:
            category = Category.objects.all()
            user_form = UserUpdateForm(instance = request.user.userprofile)
            profile_form = ProfileUpdateForm(instance = request.user.userprofile)
            context = {
                'category': category,
                'user_form': user_form,
                'profile_form': profile_form
            }
            return render(request, 'user_update.html', context)
Beispiel #6
0
def update_profile(request):
    if request.method == 'POST':
        user_form = UserUpdateForm(request.POST, instance=request.user)
        profile_form = ProfileUpdateForm(request.POST,
                                         request.FILES,
                                         instance=request.user.profile)
        if user_form.is_valid() and profile_form.is_valid():
            user_form.save()
            profile_form.save()
            messages.success(request, f'Your account has been updated!')
            return redirect('profile')
    else:
        user_form = UserUpdateForm(instance=request.user)
        profile_form = ProfileUpdateForm(instance=request.user.profile)

    context = {
        'user_form': user_form,
        'profile_form': profile_form,
    }

    return render(request, 'profile/update_profile.html', context)
Beispiel #7
0
def userUpdate(request):
    if request.method == 'POST':
        userForm = UserUpdateForm(request.POST, instance=request.user)
        profileForm = ProfileUpdateForm(request.POST,
                                        request.FILES,
                                        instance=request.user.userprofile)
        if userForm.is_valid() and profileForm.is_valid():
            userForm.save()
            profileForm.save()
            messages.success(request, 'Profil bilgileriniz güncellendi!')
            return HttpResponseRedirect('/customer-account')

        else:
            context = {'userForm': userForm, 'profileForm': profileForm}
            messages.warning(request, 'Bilgilerinizde hata var!')

            return render(request, 'customer-account.html', context)

    else:
        userForm = UserUpdateForm(instance=request.user)
        profileForm = ProfileUpdateForm(instance=request.user.userprofile)
        context = {'userForm': userForm, 'profileForm': profileForm}
        return render(request, 'customer-account.html', context)