def user_update(request): setting = Setting.objects.get(pk=1) current_user = request.user profile = UserProfile.objects.get(user_id=current_user.id) 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 = Categories.objects.all() user_form = UserUpdateForm(instance=request.user) profile_form = ProfileUpdateForm(instance=request.user.userprofile) context = { 'category': category, 'user_form': user_form, 'profile_form': profile_form, 'profile': profile, 'setting': setting, } return render(request, 'user_update.html', context)
def user_update(request): if request.method == "POST": user_form = UserUpdateForm( request.POST, instance=request.user) # request.user is user data # *"instance=request.user.userprofile" comes from "userprofile" model --> OneToOne relationship 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 HttpResponseRedirect('/user') else: messages.warning(request, user_form.errors, profile_form.errors) return HttpResponseRedirect('/user/update') else: category = Category.objects.all() user_form = UserUpdateForm(instance=request.user) profile_form = ProfileUpdateForm( instance=request.user.userprofile ) # "userprofile" model --> OneToOne relationship with user context = { 'category': category, 'user_form': user_form, 'profile_form': profile_form, } return render(request, 'user_update.html', context)
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, "Profiliniz Guncellendi") return redirect('/user') else: user_form = UserUpdateForm(instance=request.user) profile_form = ProfileUpdateForm(instance=request.user.userprofile) categori = Categori.objects.filter(tip="categori") menu = Categori.objects.filter(tip="menu") menu_icerik = Urun.objects.filter(tip="menu") ayar = Ayarlar.objects.get(pk=1) context = { 'ayar': ayar, 'categori': categori, 'user_form': user_form, 'profile_form': profile_form, 'menu': menu, 'menu_icerik': menu_icerik, } return render(request, 'bilgi_yenile.html', context)
def user_update(request): if request.method == 'POST': user_form = UserUpdateForm( request.POST, instance=request.user) #request user is user session data 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) # user form user ile ilişki kuracak 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)
def user_update(request): if request.method == 'POST': user_form = UserUpdateForm( request.POST, instance=request.user) #request.user is user data. 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) #model user data profile_form = ProfileUpdateForm( instance=request.user.userprofile ) #güncelleme durumlarında bu kısım formu getir diyoruz. #"userprofile" model -> OneToOneField relation with user context = { 'category': category, 'user_form': user_form, 'profile_form': profile_form, } return render(request, 'user_update.html', context)
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, 'Bilgileriniz Güncellenmiştir ! ') return redirect('/user') else: category = Category.objects.all() user_form = UserUpdateForm(instance=request.user) profile_form = ProfileUpdateForm(instance=request.user.userprofile) current_user = request.user profile = UserProfile.objects.get(user_id=current_user.id) context = { 'category': category, 'user_form': user_form, 'profile_form': profile_form, 'profile': profile, } return render(request, 'user_update.html', context)
def user_update(request): if request.method == 'POST': user_form = UserUpdateForm( request.POST, instance=request.user) # request.user is user data 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 HttpResponseRedirect('/user') else: category = Category.objects.all() user_form = UserUpdateForm(instance=request.user) profile_form = ProfileUpdateForm( instance=request.user.userprofile ) # "userprofile" model -> OneToOneField relatinon with user setting = Setting.objects.get(pk=1) context = { 'category': category, 'setting': setting, 'user_form': user_form, 'profile_form': profile_form } return render(request, 'user_update.html', context)
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: settings = Setting.objects.get(pk=1) user_form = UserUpdateForm(instance=request.user) profile_form = ProfileUpdateForm(instance=request.user.userprofile) context = {'settings': settings, "user_form": user_form, "profile_form": profile_form} return render(request, 'user_update.html', context)
def userinfo(request): if request.method == 'GET': if 'account_number' in request.session: user = User.objects.filter( account_number=request.session['account_number']).first() return render(request, 'user.html', { 'userInfo': user, 'session': request.session['account_number'] }) if request.method == 'POST': form = UserUpdateForm(request.POST) if form.is_valid(): user = User.objects.filter( account_number=request.session['account_number']).first() user.password = form.cleaned_data['password'] user.name = form.cleaned_data['name'] user.sex = form.cleaned_data['sex'] user.id_card = form.cleaned_data['id_card'] user.age = form.cleaned_data['age'] user.phone = form.cleaned_data['phone'] user.address = form.cleaned_data['address'] user.save() success = '修改成功' return render(request, 'user.html', { 'success': success, 'userInfo': user }) errors = form.errors return render(request, 'user.html', {'errors': errors})
def profile(request): user = request.user form = UserUpdateForm(instance = user) photoForm = PhotoForm() image = None if not Photo.objects.filter(users_id = request.user.id) else Photo.objects.filter(users_id = request.user.id)[0] # image = Photo.objects.get(users_id = request.user.id) return render(request,'profile/profile.html',{'user_update_form':form, 'photo_form':photoForm, 'image':image})
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, "Profiliniz Başarıyla Güncellendi") return redirect('/user') else: user_form = UserUpdateForm(instance=request.user) profile_form = ProfileUpdateForm(instance=request.user.userprofile) context = {'user_form': user_form, 'profile_form': profile_form} return render(request, 'user-update.html', context)
def profile_update(request): if request.method == 'POST': u_form = UserUpdateForm(request.POST, instance=request.user) p_form = UserProfileUpdateForm(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, "Your profile has been successfully updated") return redirect('welcome') else: u_form = UserUpdateForm(instance=request.user) p_form = UserProfileUpdateForm(instance=request.user.profile) context = {'u_form': u_form, 'p_form': p_form} return render(request, 'ams/update.html', context)
def update(request): if request.user.is_authenticated: user = User.objects.get(id=request.user.id) if request.method == 'POST': form = UserUpdateForm(request.POST) if form.is_valid(): user.last_name = form.cleaned_data['last_name'] user.first_name = form.cleaned_data['first_name'] user.email = form.cleaned_data['email'] user.save() form = UserUpdateForm(initial={'first_name': user.first_name, 'last_name': user.last_name, 'email': user.email}) return render(request, 'user/update.html', {'form': form }) else: return HttpResponseRedirect('/auth/login')
def setUp(self): self.fakeUser = Faker() self.data = { 'username': self.fakeUser.user_name(), 'firstname': self.fakeUser.first_name(), 'lastname': self.fakeUser.last_name() } self.form = UserUpdateForm(data=self.data)
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 successfully updated') return HttpResponseRedirect('/user') else: category = Category.objects.all() setting = Setting.objects.get(pk=1) user_form = UserUpdateForm(instance=request.user) profile_form = ProfileUpdateForm(instance=request.user.userprofile) current_user = request.user shopcart = ShopCart.objects.filter(user_id=current_user.id) #shipping = 0 #for rs in shopcart: #shipping = float(2000) subtotal = 0 for rs in shopcart: subtotal += rs.product.price * rs.quantity total = 0 for rs in shopcart: total += rs.product.price * rs.quantity added = 0 for rs in shopcart: added += rs.quantity context = { 'category': category, 'total': total, 'added': added, 'user_form': user_form, 'profile_form': profile_form, 'shopcart': shopcart, 'setting': setting, } return render(request, 'user_update.html', context)
def get_context_data(self, **kwargs): if 'uForm' not in kwargs and 'pForm' not in kwargs: kwargs['uForm'] = UserUpdateForm(self.request.POST, instance=self.request.user) kwargs['pForm'] = ProfileUpdateForm( self.request.POST, self.request.FILES, instance=self.request.user.profile) return kwargs
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, "Your account has been updated successfully!") return redirect('user-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, 'user/user_profile.html', context)
def test_UserUpdateForm_invalid_email_exist(self): # pragma: no cover form = UserUpdateForm( data={ "user_name": "user", "email": "*****@*****.**" }, instance=self.user, ) self.assertFalse(form.is_valid())
def test_edit_form_is_valid(self): form = UserUpdateForm(data={ 'username' : 'Korisnik', 'first_name' : 'OvoJeIme', 'last_name' : 'OvoJePrezime', 'email' : '*****@*****.**' }) self.assertTrue(form.is_valid())
def user_update(request): if request.method == 'POST': user_form = UserUpdateForm(request.POST, instance=request.user) # request.user is user data 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 HttpResponseRedirect('/user') else: user_form = UserUpdateForm(instance=request.user) profile_form = ProfileUpdateForm(instance=request.user.userprofile) #"userprofile" model -> OneToOneField relatinon with user context = { 'user_form': user_form, 'profile_form': profile_form } return render(request, 'update_user_information.html', context)
def update_user_profile(request): context = dict() form = UserUpdateForm(request.POST or None, instance=request.user) context['form'] = form if request.method == "POST": if form.is_valid(): form.save() messages.success(request, "Your profile updated successfully.") return redirect("user_profile") return render(request, "user/update_profile.html", context)
def profile_update(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,'تم تحديث الملف الشخصي') return redirect('profile') else: user_form = UserUpdateForm(instance=request.user) profile_form = ProfileUpdateForm(instance= request.user.profile) context = { 'title' : 'تعديل الملف الشخصي' , 'user_form' : user_form , 'profile_form' : profile_form } return render(request,'user/profile_update.html', context)
def post(self, request, *args, **kwargs): uForm = UserUpdateForm(request.POST, instance=request.user) pForm = ProfileUpdateForm(request.POST, request.FILES, instance=request.user.profile) if uForm.is_valid() and pForm.is_valid(): return self.forms_valid(uForm, pForm) else: return self.forms_invalid(uForm, pForm)
def test_UserUpdateForm_valid(self): # pragma: no cover form = UserUpdateForm( data={ "username": "******", "email": "[email protected]" }, instance=self.user, ) self.assertTrue(form.is_valid())
def account_edit(request): context = dict() 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, 'Bilgiler güncellendi.') return HttpResponseRedirect('/account') else: user_form = UserUpdateForm(instance=request.user) profile_form = ProfileUpdateForm(instance=request.user.userprofile) context['user_form'] = user_form context['profile_form'] = profile_form return render(request, 'account_edit.html', context)
def get(self, request): users = UserProfile.objects.all() user_create_form = UserCreateForm(auto_id="form-create-user-%s", label_suffix='') user_update_form = UserUpdateForm(auto_id="form-update-user-%s", label_suffix='') ret = { 'user_create_form': user_create_form, 'user_update_form': user_update_form, } return render(request, 'user/index.html', ret)
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.warning(request, 'your account updated!') return redirect('/user') else: category = Category.objects.all() user_form = UserUpdateForm (instance=request.user) 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)
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 update!') return HttpResponseRedirect('/user') category = Category.objects.all() user_form = UserUpdateForm(instance=request.user) 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)
def profile(request): if request.method == 'POST': pform = ProfileForm(request.POST, request.FILES, instance=request.user.profile) uform = UserUpdateForm(request.POST, instance=request.user) if pform.is_valid() and uform.is_valid(): pform.save() uform.save() return HttpResponseRedirect(reverse('profile')) # return HttpResponse(request.FILES) else: pform = ProfileForm(instance=request.user.profile) uform = UserUpdateForm(instance=request.user) return render(request, 'user/profile.html', { 'pform': pform, 'uform': uform })
def user_update(request): if request.method == 'POST': user_form = UserUpdateForm(request.POST, instance=request.user) # request.user kullanıcı verisidir # "instance = request.user.userprofile", "userprofile" modelinden gelir -> OneToOneField ilişkisi profile_form = ProfileUpdateForm(request.POST, request.FILES, instance=request.user.userprofile) # instance ile bağlıyoruz 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) 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)