Beispiel #1
0
def book_input_auto():
    book_list = get_data('book_out.txt')
    from book.models import Book
    from book.models import Taxonomy
    
    for b in book_list:
        bs = None
        if b[6] != '':
            bs = Book.objects.filter(isbn=b[6]) 
        if bs is None or not bs.exists():
            bs = Book.objects.filter(name=b[0], version=b[7]) 
            if not bs.exists():
                try:
                    book = Book()
                    book.name = b[0]
                    book.subtitle = b[1]
                    if b[2] is None:
                        book.author = ''
                    else:
                        book.author = b[2]
                    if b[3] is None:
                        book.press = ''
                    else:
                        book.press = b[3]
                    book.price_ori = b[4]
                    if b[5] is None or b[5] == 0:
                        book.price_now = 0.4*b[4]
                    else:
                        book.price_now = b[5]
                    book.isbn = b[6]
                    book.version = b[7]
                    book.publication_date = b[8]
                    book.page_number = b[9]
                    book.size = b[10]
                    book.binding = b[11]
                    if b[12] == 'zh':
                        book.language = 'zh'
                    else:
                        book.language = 'en'
                    if b[13] is None:
                        book.translator = ''
                    else:
                        book.translator = b[13]
                    book.status = 4
                    book.save()
                    try:
                        if b[14] is not None and b[14] != '':
                            t = Taxonomy.objects.get(name=TAXONOMY_DICT[b[13]])
                            book.add_taxonomy(t)
                    except Exception, e:
                        print "Add taxonomy failed"
                        print e
                        print book_list.index(b)
                        print b
                        import pdb;pdb.set_trace()
                except Exception, e:
                    print e
                    print book_list.index(b)
                    print b
Beispiel #2
0
def addbook(request):
    if request.method == 'POST':
        # user = cache.get('shuji')
        # print(user)

        user = request.user

        bookname = request.POST.get('bookname')
        author = request.POST.get('author')
        binding = request.POST.get('binding')
        publisher = request.POST.get('publisher')
        pubdate = request.POST.get('pubdate')
        price = request.POST.get('price')
        pages = request.POST.get('pages')
        isbn = request.POST.get('isbn')
        summary = request.POST.get('summary')
        image = request.FILES.get('image')
        book = Book()
        book.bookname = bookname
        book.author = author
        book.binding = binding
        book.publisher = publisher
        book.pubdate = pubdate
        book.price = price
        book.pages = pages
        book.isbn = isbn
        book.summary = summary
        book.image = image
        book.user_id_id = user.id
        book.save()
        user = User.objects.filter(pk=user.id).first()
        user.beans += 1
        user.save()
        # recent = Book.objects.filter(user_id_id=user.id)
        recent = Book.objects.all()

        return render(request,'index.html',{'recent':recent,'user':user})