Exemplo n.º 1
0
def add_book(request):
    state = None
    if request.method == 'POST':
        new_book = Book(
            isbn=request.POST.get('isbn', ''),
            title=request.POST.get('title', ''),
            publisher=request.POST.get('publisher', ''),
            publish_date=request.POST.get('publish_date', ''),
            Price=request.POST.get('Price', 0),
        )
        new_book.save()
        a_ids = request.POST.getlist('a_ids')
        for a_id in a_ids:
            # author_temp = Author.objects.filter(author_id__exact=a_id)
            new_book.author_ids.add(a_id)
        state = 'success'

    author_list = Author.objects.all().order_by('name')

    content = {
        'active_menu': 'add_book',
        'author_list': author_list,
        'state': state,
    }

    return render(request, 'management/add_book.html', content)
Exemplo n.º 2
0
def add_book(request):
    if request.method == 'POST':
        new_book = Book(
            name=request.POST.get('name', ''),
            author=request.POST.get('author', ''),
            category=request.POST.get('category', ''),
            price=request.POST.get('price', ''),
            publish_date=request.POST.get('publish_date'),
            create_datetime=request.POST.get('create_datetime'),
        )
        new_book.create_datetime = time.strftime('%Y%m%d%H%I')
        new_book.save()
        return HttpResponseRedirect(reverse('management:index'))
    return render(request, 'management/add_book.html')
Exemplo n.º 3
0
def add_book(request):
    user = request.user
    print(user)
    state = None
    if request.method == "POST":
        new_book = Book(
            name=request.POST.get("name", ""),
            author=request.POST.get("author", ""),
            category=request.POST.get("category", ""),
            price=request.POST.get("price", 0),
            publish_date=request.POST.get("publish_date", ""),
            img=request.FILES.get("img", ""),
        )
        new_book.save()
        state = "success"

    return render(request, "management/add_book.html", locals())
Exemplo n.º 4
0
def add_book(request):
    user = request.user
    state = None
    if request.method == 'POST':
        new_book = Book(name=request.POST.get('name', ''),
                        author=request.POST.get('author', ''),
                        category=request.POST.get('category', ''),
                        price=request.POST.get('price', 0),
                        publish_date=request.POST.get('publish_date', ''))
        new_book.save()
        state = 'success'
    content = {
        'user': user,
        'active_menu': 'add_book',
        'state': state,
    }
    return render(request, 'management/add_book.html', content)
Exemplo n.º 5
0
def import_info(request):
    user=request.user if request.user.is_authenticated() else None
    state=None
    if request.method=='POST':
        books=request.POST.getlist('search','')
        for book in books:
            book=eval(book)
            book_name=book['title']
            book_author=book['author']
            book_price=book['price']
            book_pubdate=book['pubdate']
            book_sum=book['summary']
            if book['category']:
                book_category=book['category']
            else:
                book_category=u'导入图书'
            try:
                new_book=Book(
                        name=book_name,
                        author=book_author,
                        price=book_price,
                        category=book_category,
                        publish_date=book_pubdate,
                        summary=book_sum
                        )
                new_book.save()
                state='success'
            except:
                state='error'
            else:
                if book.has_key('image'):
                    book_image=book['image']
                    try:
                        book_this=Book.objects.get(name=book_name)
                        filename=os.path.basename(book_image)
                        response=urllib.urlopen(book_image)
                        io=BytesIO(response.read())
                        new_pimg=Img()
                        new_pimg.book=book_this
                        new_pimg.name=book_this.name
                        new_pimg.description=book_this.category
                        new_pimg.img.save(filename,File(io))
                        new_pimg.save()
                    except Exception,ex:
                        print Exception,":",ex
Exemplo n.º 6
0
def add_book(request):
    user = request.user
    state = None
    if request.method == 'POST':
        new_book = Book(
                name=request.POST.get('name', ''),
                author=request.POST.get('author', ''),
                category=request.POST.get('category', ''),
                price=request.POST.get('price', 0),
                publish_date=request.POST.get('publish_date', '')
        )
        new_book.save()
        state = 'success'
    content = {
        'user': user,
        'active_menu': 'add_book',
        'state': state,
    }
    return render(request, 'management/add_book.html', content)
Exemplo n.º 7
0
def confirm(request,ISBN):
    Dict=douban(ISBN)
    if request.method=='POST':
        N = request.POST.get('number', '')
        N = int(N)
        for i in range(N):
            new_book = Book(
                name=request.POST.get('name', ''),
                author=request.POST.get('author', ''),
                category=request.POST.get('category', ''),
                price=re.search(r'\d+\.?\d*', request.POST.get('price', 0)).group(),
                publish_date=request.POST.get('publish_date', ''),
                location=request.POST.get('location', ''),
                img=Dict['img'],
                state=True,
                ISBN=ISBN
            )
            new_book.save()

        return render(request, 'management/message.html', {'state': 'success', 'message': 'added successfully'})
    return render(request,'management/add_book.html',Dict)