示例#1
0
def savebook(request):
    ISBN = request.POST.get("book_ISBN", "")
    title = request.POST.get("book_title", "")
    authorID = request.POST.get("book_authorID", "")
    publisher = request.POST.get("book_publisher", "")
    publishDate = request.POST.get("book_publishDate", "")
    price = request.POST.get("book_price", "")
    author = Author.objects.filter(AuthorID=authorID)

    if author:
        newbook = Book(
            ISBN=ISBN, Title=title, AuthorID=author[0], Publisher=publisher, PublishDate=publishDate, Price=price
        )
        newbook.save()
        return HttpResponseRedirect("/")
    else:
        return render(
            request,
            "newauthor.html",
            {
                "book_isbn": ISBN,
                "book_title": title,
                "book_publisher": publisher,
                "book_publishDate": publishDate,
                "book_price": price,
            },
        )
示例#2
0
    def handle(self, *args, **options):
        for argfile in args:
            try: 
                if os.path.exists(argfile):
                    with open(argfile, 'r') as f: 
                        for line in f:
                            data = line.split (",", 6)

                            book_title= data[0].strip()[0:97]
                            if len(book_title) == 97:
                                book_title += '...'
                            book_author = data[1].strip()[0:97]
                            if len(book_author) == 97:
                                book_author += '...'
                            book_pub_date = data[2].strip() + "-01-01"
                            book_publisher = data[4].strip()[0:97]
                            if len(book_publisher) == 97:
                                book_publisher += '...'
                            book_isbn = data[5].strip()
                            book = Book(title=book_title, 
                                        author=book_author, 
                                        pub_date=book_pub_date, 
                                        publisher=book_publisher, 
                                        isbn=book_isbn)
                            book.save()
                    print "All books from " + argfile + " imported."
                else:
                    print "No such file " + argfile + "."
            except:
                raise CommandError('Fail! Reason\n %s\n %s' % 
                                   str(sys.exc_info()),
                                   str(traceback.format_exc()))
示例#3
0
def insertToDb1(data_file):
    try:
        for val in range(0, int(data_file[4])):
            authorname = data_file[1]
            authorname = authorname.split(",")
            if len(authorname) > 1:
                author, created1 = Author.objects.get_or_create(
                    name=authorname[1], surname=authorname[0])
            else:
                author, created1 = Author.objects.get_or_create(
                    name=authorname[0], surname='')
            publisher, created2 = Publisher.objects.get_or_create(
                name=data_file[3])
            Book(
                title=data_file[0],
                ISBN=1111111111111,
                page_amount=250,
                author=author,
                lend_period=LendPeriods.objects.get(id=1),
                publisher=publisher,
                status='available',
                genre=data_file[2],
            ).save()

    except Exception, e:
        print "Exception happen: " + str(
            e) + "book having problem" + data_file[0]
示例#4
0
def savebook(request):
    ISBN = request.POST.get('book_ISBN','')
    title = request.POST.get('book_title','')
    authorID = request.POST.get('book_authorID','')
    publisher = request.POST.get('book_publisher','')
    publishDate = request.POST.get('book_publishDate','')
    price = request.POST.get('book_price','')
    author=Author.objects.filter(AuthorID = authorID)
    
    if(author):
        newbook = Book(ISBN = ISBN,Title = title,AuthorID = author[0],Publisher = \
        publisher,PublishDate = publishDate,Price = price)
        newbook.save() 
        return HttpResponse('Save successfully')
    else:
        return render(request, 'newauthor.html',{'book_isbn':ISBN,'book_title':title, \
        'book_publisher':publisher, 'book_publishDate':publishDate,\
        'book_price':price})
示例#5
0
def saveall(request):
    authorID = request.POST.get("author_ID", "")
    name = request.POST.get("author_name", "")
    age = request.POST.get("author_age", "")
    country = request.POST.get("author_country", "")
    newauthor = Author(AuthorID=authorID, Name=name, Age=age, Country=country)
    newauthor.save()

    ISBN = request.POST.get("book_ISBN", "")
    title = request.POST.get("book_title", "")
    publisher = request.POST.get("book_publisher", "")
    publishDate = request.POST.get("book_publishDate", "")
    price = request.POST.get("book_price", "")
    #    print price
    newbook = Book(
        ISBN=ISBN, Title=title, AuthorID=newauthor, Publisher=publisher, PublishDate=publishDate, Price=price
    )
    newbook.save()
    return HttpResponseRedirect("/")
示例#6
0
def saveall(request):
    authorID = request.POST.get('author_ID','')
    name = request.POST.get('author_name','')
    age = request.POST.get('author_age','')
    country = request.POST.get('author_country','')
    newauthor = Author(AuthorID = authorID, Name = name, Age = age, Country \
    = country)
    newauthor.save()
    
    ISBN = request.POST.get('book_ISBN','')
    title = request.POST.get('book_title','')
    publisher = request.POST.get('book_publisher','')
    publishDate = request.POST.get('book_publishDate','')
    price = request.POST.get('book_price','')
#    print price
    newbook = Book(ISBN = ISBN,Title = title,AuthorID = newauthor,Publisher = \
    publisher,PublishDate = publishDate,Price = price)
    newbook.save() 
    return HttpResponseRedirect("/")
    
        
        
        
示例#7
0
 def test_was_published_recently_with_old_book(self):
     time = timezone.now() - datetime.timedelta(days=31)
     past_book = Book(title='Past', author='Past', publisher='Past', pub_date=time)
     self.assertEqual(past_book.was_published_recently(), False)
示例#8
0
 def test_was_published_recently_with_future_book(self):
     time = timezone.now() + datetime.timedelta(days=30)
     future_book = Book(title='Future', author='Future', publisher='Future', pub_date=time)
     self.assertEqual(future_book.was_published_recently(), False) 
示例#9
0
 def test_was_published_recently_with_recent_book(self):
     time = timezone.now() - datetime.timedelta(days=15)
     recent_book = Book(title='Recent', author='Recent', publisher='Recent', pub_date=time)
     self.assertEqual(recent_book.was_published_recently(), True)