Esempio n. 1
0
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)
Esempio n. 2
0
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)
Esempio n. 3
0
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)
Esempio n. 4
0
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)
Esempio n. 5
0
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)
Esempio n. 6
0
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)
Esempio n. 7
0
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)
Esempio n. 8
0
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)
Esempio n. 9
0
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)