def account_view(request): if not request.user.is_authenticated: return redirect('login') context = {} if request.POST: form = AccountUpdateForm(request.POST, instance=request.user) if form.is_valid(): form.initial = { "email": request.POST['email'], "username": request.POST['username'], } form.save() context['prompt_user_success'] = "Succesfully Updated" else: form = AccountUpdateForm( initial={ "email": request.user.email, "username": request.user.username, } ) context['account_form'] = form return render(request, 'accounts/account.html', context)
def account_view(request): context = {} # to enable search bar in account view if request.GET: return search(request) # code for update acount if not request.user.is_authenticated: return redirect("Accounts:login") if request.POST: form = AccountUpdateForm(request.POST, instance=request.user) if form.is_valid(): form.initial = { "email": request.POST['email'], "name": request.POST['name'], "contact": request.POST['contact'] } form.save() context['message'] = "Your Account is Updated" else: form = AccountUpdateForm( initial={ "email": request.user.email, "name": request.user.name, "contact": request.user.contact, }) context['update_form'] = form blog_posts = BlogPost.objects.filter(author=request.user) context['blog_post'] = blog_posts return render(request, 'accounts/acount.html', context)
def edit_account_view(request, *args, **kwargs): if not request.user.is_authenticated: return redirect("login") user_id = kwargs.get("user_id") account = Account.objects.get(pk=user_id) if account.pk != request.user.pk: return HttpResponse("You cannot edit someone elses profile.") context = {} if request.POST: form = AccountUpdateForm(request.POST, request.FILES, instance=request.user) if form.is_valid(): # delete old profile image so the name preserved # account.profile_image.delete() form.save() # new_username = form.cleaned_data['username'] return redirect("accounts:view", user_id=account.pk) else: form = AccountUpdateForm(request.POST, instance=request.user, initial={ "id": account.pk, "email": account.email, "username": account.username, "profile_image": account.profile_image, "hide_email": account.hide_email, }) context['form'] = form else: form = AccountUpdateForm( initial={ "id": account.pk, "email": account.email, "username": account.username, "profile_image": account.profile_image, "hide_email": account.hide_email, }) context['form'] = form context[ 'DATA_UPLOAD_MAX_MEMORY_SIZE'] = settings.DATA_UPLOAD_MAX_MEMORY_SIZE return render(request, "accounts/edit_account.html", context)
def account_view(request): if not request.user.is_authenticated: return redirect("login") context = {} if request.POST: form = AccountUpdateForm(request.POST, instance=request.user) if form.is_valid(): form.initial = {"username": request.POST['username']} form.save() context['success_message'] = "updated successfully!" else: form = AccountUpdateForm(initial={ "username": request.user.username, }) context['account_form'] = form return render(request, 'account/account.html', context)
def account_view(request): if not request.user.is_authenticated: return redirect('login') context = {} if request.POST: form = AccountUpdateForm(request.POST, instance=request.user) if form.is_valid(): form.save() else: form = AccountUpdateForm(initial={ 'email': request.user.email, 'username': request.user.username, }) context['account_form'] = form return render(request, 'account.html', context)
def account_view(request): if not request.user.is_authenticated: return redirect("login") context = {} if request.POST: form = AccountUpdateForm(request.POST, instance=request.user) if form.is_valid(): form.save() else: form = AccountUpdateForm( initial={ "email": request.user.email, "username": request.user.username, "employee": request.user.employee, # "password": request.user.password, }) context['account_form'] = form return render(request, 'accounts/account.html', context)
def update(): form = AccountUpdateForm.load(request) form.validate() if form.email.data != g.account.email: if Account.find_by_email(form.email.data): form.error('email', 'This email is already used on our service.') updates = form.get_as_dict() pendingEmail = False if updates.get('email', None) and g.account.email != updates['email']: ae = AccountEmail(g.account.id, updates['email']) ae.save(True) ae.send(updated=True) del updates['email'] pendingEmail = True if updates.get('company_vat'): try: details = get_vat_details(form.company_vat.data) if not updates.get('company_name') and not g.account.company_name: updates['company_name'] = details['name'] if not updates.get('company_details') and not g.account.company_details: updates['company_details'] = details['address'] if not updates.get('country') and not g.account.country: updates['country'] = details['countryCode'] except Exception as e: form.error('company_vat', 'Invalid VAT provided.') g.account.update(**updates) g.account.save(True) return jsonify({ 'success': True, 'pendingEmail': pendingEmail, 'account': g.account.serialize() })
def account_view(request): if not request.user.is_authenticated: return redirect("accounts:login") context = {} if request.POST: form = AccountUpdateForm(request.POST, instance=request.user) if form.is_valid(): form.initial = { "email": request.POST['email'], "username": request.POST['username'], } form.save() context['success_message'] = "Updated" else: form = AccountUpdateForm(initial={ "email": request.user.email, "username": request.user.username, }) context['account_form'] = form return render(request, "account/account.html", context)
def account_view(request): if not request.user.is_authenticated: return redirect("accounts:login") context = {} if request.POST: form = AccountUpdateForm(request.POST, instance=request.user) if form.is_valid(): form.save() context['success'] = True else: form = AccountUpdateForm( initial={ "email": request.user.email, "mobNo": request.user.mobNo, "first_name": request.user.first_name, "last_name": request.user.last_name, }) context['account_form'] = form return render(request, 'accounts/account.html', context)
def account_view(request): context = {} if request.POST: form = AccountUpdateForm(request.POST, request.FILES, instance=request.user) if form.is_valid(): form.save() context['success_message'] = 'Data Updated' else: form = AccountUpdateForm( initial={ 'email': request.user.email, 'username': request.user.username, 'image': request.user.image.url, 'name': request.user.name, 'dob': request.user.dob, 'address': request.user.address, 'bio': request.user.bio, 'phone_number': request.user.phone_number, }) context['account_form'] = form return render(request, 'accounts/profile.html', context)