Exemplo n.º 1
0
def update_view(request,id ,*args ,**kwargs):
    qs = Blog.objects.get(pk=id)
    form = UpdateForm(request.POST or None, instance=qs)
    context = {
    'form':form
    }
    if form.is_valid():
        form.save()
        return redirect("/blog/"+str(id))
    return render(request, 'update.html', context)
Exemplo n.º 2
0
def account_management(request):
    if request.user.is_authenticated():
        if request.method == "POST":
            form = UpdateForm(request.POST)
            if form.is_valid():

                firstname = form.cleaned_data["firstname"]
                lastname = form.cleaned_data["lastname"]
                emailid = form.cleaned_data["emailid"]
                username = form.cleaned_data["username"]
                # password = form.cleaned_data['password']
                card_no = form.cleaned_data["card_no"]
                exp_date = form.cleaned_data["exp_date"]
                cvv = form.cleaned_data["cvv"]
                user = User.objects.get(pk=request.user.id)
                profile = UserProfile.objects.get(user_id=request.user.id)
                user.first_name = firstname
                user.last_name = lastname
                user.email = emailid
                user.username = username
                # user.set_password(password)
                user.save()
                profile.card_no = card_no
                profile.exp_date = exp_date
                profile.cvv = cvv
                profile.save()

                return HttpResponseRedirect(reverse("account_management"))
            else:
                return HttpResponseRedirect(reverse("account_management"))
        else:

            user = User.objects.get(pk=request.user.id)
            profile = UserProfile.objects.get(user_id=request.user.id)

            form = UpdateForm(
                initial={
                    "firstname": user.first_name,
                    "lastname": user.last_name,
                    "emailid": user.email,
                    "username": user.username,
                    "card_no": profile.card_no,
                    "exp_date": profile.exp_date,
                    "cvv": profile.cvv,
                }
            )

            return render(request, "blog/account.html", {"form": form})
    else:
        return HttpResponseRedirect(reverse("loginform"))
Exemplo n.º 3
0
def account_management(request):
    if request.user.is_authenticated():
        if request.method == 'POST':
            form = UpdateForm(request.POST)
            if form.is_valid():

                firstname = form.cleaned_data['firstname']
                lastname = form.cleaned_data['lastname']
                emailid = form.cleaned_data['emailid']
                username = form.cleaned_data['username']
                # password = form.cleaned_data['password']
                card_no = form.cleaned_data['card_no']
                exp_date = form.cleaned_data['exp_date']
                cvv = form.cleaned_data['cvv']
                user = User.objects.get(pk=request.user.id)
                profile = UserProfile.objects.get(user_id=request.user.id)
                user.first_name = firstname
                user.last_name = lastname
                user.email = emailid
                user.username = username
                #user.set_password(password)
                user.save()
                profile.card_no = card_no
                profile.exp_date = exp_date
                profile.cvv = cvv
                profile.save()

                return HttpResponseRedirect(reverse('account_management'))
            else:
                return HttpResponseRedirect(reverse('account_management'))
        else:

            user = User.objects.get(pk=request.user.id)
            profile = UserProfile.objects.get(user_id=request.user.id)

            form = UpdateForm(
                initial={
                    'firstname': user.first_name,
                    'lastname': user.last_name,
                    'emailid': user.email,
                    'username': user.username,
                    'card_no': profile.card_no,
                    'exp_date': profile.exp_date,
                    'cvv': profile.cvv
                })

            return render(request, 'blog/account.html', {'form': form})
    else:
        return HttpResponseRedirect(reverse('loginform'))
Exemplo n.º 4
0
def account():
    form = UpdateForm()
    if form.validate_on_submit():
        if form.picture.data:
            picture_file = save_picture(form.picture.data)
            current_user.image_file = picture_file
        current_user.username = form.username.data
        db.session.commit()
        flash('Account has been updated!', category="success")
        return redirect(url_for('account'))
    elif request.method == 'GET':
        form.username.data = current_user.username
    image_file = url_for('static',
                         filename='profile_pics/' + current_user.image_file)
    return render_template('account.html',
                           title='Account',
                           image_file=image_file,
                           form=form)
Exemplo n.º 5
0
def profile():
    form = UpdateForm()
    if form.validate_on_submit():
        # if form.picture.data:
        #     picture_file = save_picture(form.picture.data)
        #     current_user.image_file = picture_file

        current_user.username = form.username.data
        current_user.email = form.email.data
        db.session.commit()
        flash("Your account has been updated!", 'success')
        return redirect(url_for('profile'))
    # elif request.method == 'GET':
    #     form.username.data = current_user.username
    #     form.email.data = current_user.email

    image_file = url_for('static', filename='pics/' + current_user.image_file)
    return render_template('profile.html', title='Profile', image_file=image_file, form=form)
Exemplo n.º 6
0
def account():
    form=UpdateForm()
    if request.method =='GET':
        form.username.data= current_user.username
        form.email.data = current_user.email
    elif form.validate_on_submit():
        if form.image.data:
            file_name=current_user.image_file
            path=os.path.isfile(app.root_path+'/static/images/'+file_name)
            if path:
                os.remove(app.root_path+'/static/images/'+file_name)
                print (file_name)
            current_user.image_file= save_image(form.image.data)
        current_user.username=form.username.data
        current_user.email=form.email.data
        db.session.commit()
        flash("Account has updated",'success')
        return redirect(url_for('account'))
    return render_template('account.html',form=form,title="Account")
Exemplo n.º 7
0
def updatepost(request, slug):
    context = {}
    user = request.user
    blog = get_object_or_404(Blog, slug=slug)

    if request.POST:
        form = UpdateForm(request.POST or None,
                          request.FILES or None,
                          instance=blog)
        if form.is_valid():
            new_blog = form.save(commit=False)
            new_blog.save()
            blog = new_blog
            return redirect('/')

    form = UpdateForm(
        initial={
            "titleBlog": blog.titleBlog,
            "name": blog.name,
            "content": blog.content,
            "blog": blog,
        })

    context['form'] = form
    return render(request, 'blog/updatepost.html', context)
Exemplo n.º 8
0
def profil(username):
    user = User.query.filter_by(username=username).first_or_404()
    form1 = UpdateForm()
    avatar = user.avatar
    img_src = url_for('static', filename='img/userpic/' + avatar)
    form2 = AvatarForm()
    posts = Post.query.filter_by(user_id=user.id).all()
    posts = tuple(posts)
    return render_template('admin/account.html',
                           img_src=img_src,
                           form1=form1,
                           form2=form2,
                           user=user,
                           posts=posts)
Exemplo n.º 9
0
def upDetails():
    form1 = UpdateForm()
    form2 = AvatarForm()
    img_src = url_for('static', filename='img/userpic/' + current_user.avatar)
    if form1.validate_on_submit:
        current_user.username = form1.username.data
        current_user.email = form1.email.data
        db.session.commit()
        flash("Değişiklikler kaydedildi", "success")
        return redirect(url_for("profil", username=current_user.username))
    else:
        flash("Değişiklikler kaydedilemedi", "danger")
        return render_template("admin/account.html",
                               img_src=img_src,
                               form1=form1,
                               form2=form2)
Exemplo n.º 10
0
def upImage():
    form2 = AvatarForm()
    form1 = UpdateForm()
    img_src = url_for('static', filename='img/userpic/' + current_user.avatar)
    if form2.validate_on_submit():
        flash("Fotoğraf kaydedildi", "success")
        file = form2.avatar.data
        filename = secure_filename(form2.avatar.data.filename)
        file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
        current_user.avatar = filename
        db.session.commit()
        return redirect(url_for("profil", username=current_user.username))
    else:
        flash("Fotoğraf kaydetyme başarısız", "danger")
        return render_template("admin/account.html",
                               img_src=img_src,
                               form2=form2,
                               form1=form1)