def profile(request): articles = Article.objects.filter(status=1).order_by('-date_posted')[:2] 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 = { 'title': 'Profile', 'articles': articles, 'user_form': user_form, 'profile_form': profile_form, } return render(request, 'accounts/profile.html', context)
def profile(request): """ Return the user's profile page. Allows editing the profile, as well as the login details for a user. """ if request.method == 'POST': user_form = UserUpdateForm(request.POST, initial={'username': ''}, 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, 'accounts/profile.html', context)
def profile_view(request): if request.method == 'POST': user_form = UserUpdateForm(request.POST, instance=request.user) profile_form = ProfileUpdateForm(request.POST, request.FILES, instance=request.user.userprofileinfo) if user_form.is_valid() and profile_form.is_valid(): user_form.save() profile = profile_form.save(commit=False) user = user_form.save() user.email = profile.email user.save() profile.save() messages.success(request, 'Your profile is successfully updated!') return redirect('profile') else: messages.error(request, user_form.errors) messages.error(request, profile_form.errors) else: user_form = UserUpdateForm(instance=request.user) profile_form = ProfileUpdateForm(instance=request.user.userprofileinfo) return render(request, 'accounts/profile.html', { 'user_form': user_form, 'profile_form': profile_form })
def update_user_profile(request): user = User.objects.get(email=request.user.email) #forms to update user profile 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,'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, 'user': user } return render(request, 'update_profile.html', context)
def update_profile(request, slug): profile = Profile.objects.get(slug=slug) if request.method == 'POST': u_form = UserUpdateForm(request.POST, instance=request.user) p_form = ProfileUpdateForm(request.POST, request.FILES, instance=profile) if u_form.is_valid() and p_form.is_valid(): u_form.save() p_form.save() new_slug = request.POST.get('slug') messages.success(request, f'User information has been updated!') # return reverse("accounts:profile", kwargs={"slug": slug}) return HttpResponseRedirect( reverse('accounts:profile', args=[new_slug])) else: print("user errors:", u_form.errors.as_data()) print("profile errors:", p_form.errors.as_data()) else: u_form = UserUpdateForm(instance=request.user) p_form = ProfileUpdateForm(instance=profile) context = { 'p_form': p_form, 'u_form': u_form, 'categories': Category.objects.all() } return render(request, 'accounts/profile_update.html', context)
def edit_profile(request): if request.method == 'POST': u_form = EditProfileForm(request.POST, instance=request.user) p_form = ProfileUpdateForm(request.POST, request.FILES, instance=request.user.userprofile) if u_form.is_valid() and p_form.is_valid(): u_form.save() p_form.save() return redirect('/account/profile') else: args = { 'p_form': p_form, 'u_form': u_form, } return render(request, 'accounts/profile_edit.html', args) else: u_form = EditProfileForm(instance=request.user) p_form = ProfileUpdateForm(instance=request.user.userprofile) args = { 'p_form': p_form, 'u_form': u_form, } return render(request, 'accounts/profile_edit.html', args)
def user_profile(request): '''The user profile page''' 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") 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} # Gettting user object user = User.objects.get(email=request.user.email) # Gettting profile object through foreign key return render(request, 'profile.html', { 'profile': user, 'u_form': u_form, 'p_form': p_form })
def ProfileView(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') return redirect('memberships:dashboard') else: u_form = UserUpdateForm(instance=request.user) p_form = ProfileUpdateForm(instance=request.user.profile) courses = Course.objects.order_by('start_date').all()[:3] instructors = Instructor.objects.order_by('dofb').all()[:3] context = { 'u_form': u_form, 'p_form': p_form, 'courses': courses, 'instructors': instructors } return render(request, 'accounts/profile.html', context)
def bank_view(request): try: cart = Cart.objects.get(user=request.user.id, active=True) items = CartItem.objects.filter(cart=cart) except ObjectDoesNotExist: cart = Cart.objects.create(user=request.user) items = CartItem.objects.filter(cart=cart) total = cart.total 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() return redirect('zarinpal:request') else: u_form = UserUpdateForm(instance=request.user) p_form = ProfileUpdateForm(instance=request.user.profile) context = { 'u_form': u_form, 'p_form': p_form, 'cart': items, 'total': total } return render(request, 'cart/bank.html', context)
def post(self, request, *args, **kwargs): 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() and profile_form.save() messages.success(request, f"Your account has been updated!") return redirect("bookstore")
def post(self, request, username): 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, _('Account successfully updated!')) return redirect('accounts:profile:bio', self.get_username()) return self.get(request, username)
def user_profile_update_form(request): if request.method == 'POST': form = ProfileUpdateForm(request.POST, request.FILES, instance=request.user.profile) if form.is_valid(): form.save() messages.success(request, 'Your profile has been updated') return redirect('accounts:dashboard') else: form = ProfileUpdateForm(instance=request.user.profile) context = {'form': form} return render(request, 'accounts/update/edit_profile_info.html', context)
def update_user_profile(request): """ Update the profile for the logged in user """ if request.method == "POST": profile_update_form = ProfileUpdateForm(request.POST) if profile_update_form.is_valid(): current_user = request.user user_email = profile_update_form.cleaned_data["email"] user_username = profile_update_form.cleaned_data["username"] try: db_user = User.objects.get(email=user_email) if db_user.email == current_user.email: db_user.username = user_username db_user.email = user_email db_user.save() messages.success(request, "Your profile has been updated.") return render(request, 'profile.html', {"profile": db_user}) else: profile_update_form.add_error( "email", "Sorry that email is taken by someone else.") except: try: db_user = User.objects.get(email=current_user.email) db_user.username = user_username db_user.email = user_email db_user.save() messages.success(request, "Your profile has been updated.") return render(request, 'profile.html', {"profile": db_user}) except: messages.error(request, "We were unable to update your details.") else: profile_update_form.add_error(None, "Please check the details.") else: profile_update_form = ProfileUpdateForm(initial={ "username": request.user.username, "email": request.user.email }) return render(request, 'profile_update.html', {"profile_update_form": profile_update_form})
def update_profile(request, pk): if request.method == 'POST': form = ProfileUpdateForm(request.POST, instance=request.user) if form.is_valid(): profile = form.save(commit=False) profile.username = profile.email profile.save() messages.add_message(request, messages.INFO, 'Success, Profile Updated!') return redirect('accounts:profile_detail', pk=pk) else: return HttpResponse(form.errors) else: form = ProfileUpdateForm(instance=request.user) return render(request, 'accounts/profile_form.html', {'form': form})
def edit_profile(request): if request.method == "POST": form = UserUpdateForm(request.POST, instance=request.user) form2 = ProfileUpdateForm(request.POST, instance=request.user.profile) if form.is_valid() and form2.is_valid(): form.save() form2.save() return redirect('view_profile') else: form = UserUpdateForm(instance=request.user) form2 = ProfileUpdateForm(instance=request.user.profile) context = {"form": form, "form2": form2} return render(request, "edit_profile.html", context)
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() 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, 'accounts/profile.html', context)
def profile_page(request, *args, **kwargs): 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() 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/profile-update.html', context)
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!") 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, 'registration/profile.html', context)
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'Your account has been updated!') return redirect('profile') else: messages.error(request, _('Please correct the error below.')) 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, 'accounts/profile.html', context)
def user_update(request): if request.method == 'POST': # request.user is user data user_form = UserUpdateForm(request.POST, instance=request.user) profile_form = ProfileUpdateForm(request.POST, request.FILES, instance=request.user.profiles) if user_form.is_valid() and profile_form.is_valid(): user_form.save() profile_form.save() return HttpResponseRedirect('/profile/') else: user_form = UserUpdateForm(instance=request.user) # "userprofile" model -> OneToOneField relatinon with user profile_form = ProfileUpdateForm(instance=request.user.profiles) context = {'user_form': user_form, 'profile_form': profile_form} return render(request, 'accounts/update.html', context)
def update_profile(request): user = get_object_or_404(Profile, user=request.user) if request.method == "POST": form = ProfileUpdateForm(request.POST, request.FILES, instance=user) print(request.POST['first_name']) print(request.POST['last_name']) if form.is_valid(): prof = form.save(commit=False) prof.user = request.user prof.save() return redirect('index') else: print("Invalid form=================") else: form = ProfileUpdateForm(instance=user) prof = Profile.objects.get(user=request.user) context = {'form': form, 'prof': prof} return render(request, 'accounts/update_profile.html', context)
def edit_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'Your Profile has been updated') 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, "edit_profile.html", context)
def edit_profile(req): if req.method == 'POST': user_form = UserUpdateForms(req.POST, instance=req.user) profile_form = ProfileUpdateForm(req.POST, req.FILES, instance=req.user.profile) if user_form.is_valid() and profile_form.is_valid(): user_form.save() profile_form.save() messages.success(req, f'Your account has been update!') return redirect('my_profile') else: user_form = UserUpdateForms(instance=req.user) profile_form = ProfileUpdateForm(instance=req.user.profile) storage = messages.get_messages(req) storage.used = True context = {'user_form': user_form, 'profile_form': profile_form} return render(req, 'accounts/edit-profile.html', context=context)
def post(self, request, *args, **kwargs): form = ProfileUpdateForm(request.POST) if form.is_valid(): if form.cleaned_data['first_name'] is not '': request.user.first_name=form.cleaned_data['first_name'] if form.cleaned_data['last_name'] is not '': request.user.last_name=form.cleaned_data['last_name'] if form.cleaned_data['bio'] is not '': request.user.profile.bio=form.cleaned_data['bio'] if request.FILES: profile_picture_form = ProfilePictureUpdateForm(request.POST, request.FILES, instance=request.user.profile) if profile_picture_form.is_valid(): profile_picture_form.save() request.user.save() else: errors = form.errors.get_json_data() for x in errors: for error in errors[x]: messages.add_message(request, messages.ERROR, error["message"]) return redirect("/accounts/profile/{}".format(request.user.username))
def profile(request): if request.method == 'POST': userupdateform = UserUpdateForm(request.POST, instance=request.user) profileupdateform = ProfileUpdateForm(request.POST, request.FILES, instance=request.user.profile) if userupdateform.is_valid() and profileupdateform.is_valid(): userupdateform.save() profileupdateform.save() messages.success(request, f'Your Profile is updated!') return redirect('profile') else: userupdateform = UserUpdateForm(instance=request.user) profileupdateform = ProfileUpdateForm(instance=request.user.profile) context = { 'userupdateform': userupdateform, 'profileupdateform': profileupdateform } return render(request, 'accounts/profile.html', context)
def update_profile(request): """Updates details of the user.""" if request.method == 'POST': form = ProfileUpdateForm(request.POST, request.FILES, instance=request.user) if form.is_valid(): form.save() sweetify.success( request, "Account details updated", icon='success', timer='3000', toast='true', position='bottom', background='#181818', ) return redirect('profile') else: form = ProfileUpdateForm(instance=request.user) return render(request, 'update.html', {"form": form})
def profiles(request): #args = {'user': request.user} 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.succes(request, f'Your account has beeen updated!') return redirect('profiles') 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, 'counsel_profile.html', context)
def user_profile(request): """The user profile page""" 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, "You have successfully updated your account!") return redirect(request.META['HTTP_REFERER']) 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, 'profile.html', context)
def user_profile(request): """The user's profile page""" user = User.objects.get(email=request.user.email) 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) group = Group.objects.get(name="paid").user_set.all() bugs = Bug.objects.filter( author=user).order_by('-published_date') features = Feature.objects.filter( author=user).order_by('-published_date') context = { 'user_form': user_form, 'profile_form': profile_form, 'group': group, 'bugs': bugs, 'features': features } return render(request, 'profile.html', context)
def profile(request): """ The user's profile page """ user = User.objects.get(email=request.user.email) if request.method == "POST": update_form = UserUpdateForm(request.POST, instance=request.user) profile_form = ProfileUpdateForm(request.POST, request.FILES, instance=request.user.profile) # validate forms for updating user and profile if update_form.is_valid() and profile_form.is_valid(): update_form.save() profile_form.save() messages.success(request, f"Profile successfully updated!") return redirect(reverse("profile")) else: update_form = UserUpdateForm(instance=request.user) profile_form = ProfileUpdateForm(instance=request.user.profile) context = { "update_form": update_form, "profile_form": profile_form, "profile": user } return render(request, "profile.html", context)