Ejemplo n.º 1
0
def updatebook(id):
    book=Book.query.get_or_404(id)
    form=BookForm()
    if form.validate_on_submit():
        book.name=form.name.data
        book.page=form.page.data
        book.price=form.price.data
        book.much=form.much.data
        book.jold=form.jold.data
        book.desc=form.desc.data
        if request.files.get('image1'):
            try:
                os.unlink(os.path.join(current_app.root_path,'static/img/'+book.image1))
                book.image1=photos.save(request.files.get('image1'),name=secrets.token_hex(10)+'.')
        
            except:
                book.image1=photos.save(request.files.get('image1'),name=secrets.token_hex(10)+'.')

        flash(f'Book Successfully Updated','success')
        db.session.commit()
        return redirect(url_for('books',book_id=book.id))
    elif request.method=='GET':
        form.name.data=book.name
        form.page.data=book.page
        form.price.data=book.price
        form.much.data=book.much
        form.jold.data=book.jold
        form.desc.data=book.desc
    return render_template('updatebook.html',form=form )
Ejemplo n.º 2
0
def AddBook():
    categories=Category.query.all()
    form=BookForm()
    if form.validate_on_submit():
        name=form.name.data
        page=form.page.data
        price=form.price.data
        much=form.much.data
        jold=form.jold.data
        desc=form.desc.data
        category=request.form.get('category')
        image1=photos.save(request.files.get('image1'),name=secrets.token_hex(10)+".")
        add=Book(name=name,page=page,price=price,much=much,jold=jold,desc=desc,image1=image1,category_id=category)
        db.session.add(add)
        db.session.commit()
        flash(f'Product Created Successfully','success')
        return redirect(url_for('index'))
    return render_template('addbook.html',form=form,categories=categories)
Ejemplo n.º 3
0
def upload_book(request):
    context = {}
    if request.method == 'POST':
        form = BookForm(request.POST, request.FILES)
        if form.is_valid():
            form.save()
            return redirect('book_list')
    else:
        form = BookForm()
        return render(request, 'upload_book.html', {'form': form})
Ejemplo n.º 4
0
def post_list(request, page_number=1):
    posts = Post.objects.filter(
        published_date__lte=timezone.now()).order_by('published_date')
    current_page = Paginator(posts, 3)
    if request.method == "POST":
        form = BookForm(request.POST, request.FILES)
        if form.is_valid():
            post = form.save(commit=False)
            post.published_date = timezone.now()
            post.ordered = '0'
            post.save()
            return redirect('bookexmp', pk=post.pk)
    else:
        form = BookForm()
    return render(request, 'blog/post_list.html', {
        'posts': current_page.page(page_number),
        'form': form
    })
Ejemplo n.º 5
0
def add(request):
    if request.method == "POST":
        form = BookForm(request.POST)
    else:
        form = BookForm()
    return render(request, 'blog/edit.html', {'form': form})