예제 #1
0
 def test_book_author(self):
     a1 = Author.objects.create(name='J.K. Rowling',
                                birth_date='1965-07-31')
     b1 = Book(title='Harry Potter',
               num_pages=300,
               date_published='1997-06-26')
     b1.author = a1
     b1.save()
     self.assertEqual(b1.author.name, 'J.K. Rowling')
예제 #2
0
def addBook(request, userId):
    user = User.objects.get(pk=userId)
    book = Book(originOwner=user, currentOwner=user)
    book.name = request.POST['name']
    book.author = request.POST['author']
    book.kind = request.POST['kind']
    book.description = request.POST['description']
    book.picture = request.FILES['picture']
    book.save()
    return HttpResponse(200)
예제 #3
0
def addBook(request,userId):
	user = User.objects.get(pk=userId)
	book = Book(originOwner=user,currentOwner=user)
	book.name = request.POST['name']
	book.author = request.POST['author']
	book.kind = request.POST['kind']
	book.description = request.POST['description']
	book.picture = request.FILES['picture']
	book.save()
	return HttpResponse(200)
예제 #4
0
def addBook(request):
    if request.method == 'POST':
        new_book = Book()
        new_book.isbn = request.POST['isbn']
        new_book.title = request.POST['title']
        new_book.author = request.POST['author']
        new_book.edition = request.POST['edition']
        new_book.save()
        return HttpResponse("Success")
    else:
        return HttpResponse("please use POST request")
예제 #5
0
 def save_book_from_row(self, book_row):
     book = Book()
     book.ISBN = book_row['ISBN']
     book.title = book_row['bookTitle']
     book.author = book_row['bookAuthor']
     book.year_of_publication = book_row['yearOfPublication']
     book.publisher = book_row['publisher']
     book.image_url_s = book_row['imageUrlS']
     book.image_url_m = book_row['imageUrlM']
     book.image_url_l = book_row['imageUrlL']
     book.save()
예제 #6
0
def addBook(request):
    '''新加书籍, post request only'''
    if request.method != "POST":
        raise Http404
    
    authorName = request.REQUEST.get('authorName', None)
    authorDesc = request.REQUEST.get('authorDesc', None)
    bookName = request.REQUEST.get('bookName', None)
    bookPrice = request.REQUEST.get('bookPrice', None)
    bookIsbn = request.REQUEST.get('bookIsbn', None)
    bookPress = request.REQUEST.get('bookPress', None)
    bookDesc = request.REQUEST.get('bookDesc', None)
    bookBinding = request.REQUEST.get('bookBinding', None)
    bookPages = request.REQUEST.get('bookPages', None)
    bookSpic = request.REQUEST.get('bookSpic', None)
    bookMpic = request.REQUEST.get('bookMpic', None)
    bookLpic = request.REQUEST.get('bookLpic', None)
    bookPublishDate = request.REQUEST.get('bookPublishDate', None)
    stock = request.REQUEST.get('stock', None)
    category = request.REQUEST.get('category', None)
    
    author = Author(name=authorName, desc=authorDesc)
    author.save()
    
    price = float(''.join([ item for item in bookPrice if item in '1234567890.' ]))
    try:
        cate = Category.objects.get(label=category)
    except Category.DoesNotExist:
        raise Http404
    try:
        book = Book.objects.get(isbn=bookIsbn)
    except Book.DoesNotExist:
        book = Book()
    book.name=bookName
    book.author=author 
    book.price=price
    book.isbn=bookIsbn
    book.press=bookPress
    book.desc=bookDesc
    book.binding=bookBinding
    book.pages=bookPages
    book.spic=bookSpic
    book.mpic=bookMpic
    book.lpic=bookLpic 
    book.publish_date=bookPublishDate
    book.stock=stock
    book.category=cate
    book.save()
    utils.addMsg(request, messages.SUCCESS, '添加成功!')
    return HttpResponseRedirect('/manage/reg_book/')
예제 #7
0
파일: utils.py 프로젝트: ebachle/stats
def read_gutenberg_headers(fp):
    book = Book()
    for line in fp:
        if line.startswith('Title:'):
            book.title = line[6:].strip(string.punctuation + string.whitespace)

        if line.startswith('Author:'):
            book.author = line[7:].strip(string.punctuation + string.whitespace)

        if line.startswith('Release Date:'):
            book.published = line[13:].strip(string.punctuation + string.whitespace)

        if line.startswith('*** START OF THIS PROJECT GUTENBERG EBOOK'):
            return book
예제 #8
0
 def handle(self, *args, **options):
   Book.objects.all().delete()
   Publisher.objects.all().delete()
   Author.objects.all().delete()
   print('* Populating books...')
   orderedLS = OrderedDict(lifestudies)
   p = Publisher(name='Living Stream Ministry', code='LSM')
   p.save()
   a = Author(first_name='Witness', last_name='Lee')
   a.save()
   for b, c in orderedLS.items():
     print b
     b = Book(publisher=p, name=b, chapters=c)
     b.save()
     b.author = (a,)
     b.save()
예제 #9
0
def book_new(request, author_id):
    author = get_object_or_404(Author, pk=author_id)
    if request.method == 'POST':
        form = BookAddForm(request.POST)
        if form.is_valid():
            book = Book()
            book.title = form.cleaned_data['title']
            book.author = author
            book.year = form.cleaned_data['year']
            book.save()
            return HttpResponseRedirect(
                reverse_lazy('author-read', args=(author_id, )))
    else:
        form = BookAddForm()
        form.fields['author'].initial = author
    return render(request, 'books/book_edit.html', {'form': form})
예제 #10
0
def read_gutenberg_headers(fp):
    book = Book()
    for line in fp:
        if line.startswith('Title:'):
            book.title = line[6:].strip(string.punctuation + string.whitespace)

        if line.startswith('Author:'):
            book.author = line[7:].strip(string.punctuation +
                                         string.whitespace)

        if line.startswith('Release Date:'):
            book.published = line[13:].strip(string.punctuation +
                                             string.whitespace)

        if line.startswith('*** START OF THIS PROJECT GUTENBERG EBOOK'):
            return book
예제 #11
0
def regFromDouban(request):
    '''利用豆瓣API获取书籍信息加入数据库'''
    try:
        DOUBAN = "https://api.douban.com/v2/book/search?q="
        q = request.REQUEST.get('q', '')
        q = urllib.quote(q.decode('utf8').encode('utf8'))  
        DOUBAN += q
    
        req = urllib.urlopen(DOUBAN)
        resp = req.read()
        result = simplejson.loads(resp)
        books = result['books']
        
        
        for i in range(len(books)):
            author = Author()
            author.name = books[i]['author'][0]
            author.desc = books[i]['author_intro']
            author.save()
            
            try:
                book = Book.objects.get(isbn=books[i]['isbn13'])
            except Book.DoesNotExist:
                book = Book()
                book.name = books[i]['title']
                book.author = author
                book.price = float(''.join([ item for item in books[i]['price'] if item in '1234567890.' ]))
                if not books[i]['isbn13']:
                    book.isbn = books[i]['isbn10']
                else:
                    book.isbn = books[i]['isbn13']
                book.press = books[i]['publisher']
                book.desc = books[i]['summary']
                book.binding = books[i]['binding']
                book.pages = books[i]['pages']
                book.spic = _downloadImg(books[i]['images']['small'], 'small')   
                book.mpic = _downloadImg(books[i]['images']['medium'], 'medium')   
                book.lpic = _downloadImg(books[i]['images']['large'], 'large')   
                book.stock = 140
                book.publish_date = books[i]['pubdate']
                book.category = _getBookCate('letter')
                book.save()
                
        return HttpResponse('success')
    except Exception:
        return HttpResponse('error')
예제 #12
0
import os

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "wechatRead.settings_dev")

import django
django.setup()

from books.models import Book, Category

from data.book_data import row_data

for book in row_data:
    b = Book()
    b.name = book['name']
    b.author = book['author']
    b.cover = book['cover']
    b.brief = book['brief']
    b.word_count = book['word_count']
    b.copyright = book['copyright']
    b.rank = book['rank']
    b.price = book['price']
    b.read_count = book['read_count']
    b.is_end = book['is_end']
    b.is_index = book['is_index']
    b.is_new = book['is_new']

    category = Category.objects.filter(name=book['category'])
    if category:
        category = category[0]
        b.category = category
    b.save()
예제 #13
0
import settings_copy as settings
setup_environ(settings)

from books.models import Book

t = int(raw_input('number of books you want to add:'))

import random

TITLE_PREFIX = (u'数学', u'方程', u'化学', u'生物', u'疾病', u'神经', u'电子', u'模拟', u'物理', u'逻辑', u'算法', u'程序', u'数据库', u'网络', u'计算机', u'概率', u'随机')
TITLE_SUFFIX = (u'引论', u'概论', u'方法', u'教程', u'导读', u'分析', u'入门')
AUTHOR_PREFIX = u'赵钱孙李周吴郑王冯陈褚卫蒋沈韩杨朱秦尤许何吕施张孔曹严华金魏陶姜'
AUTHOR_SUFFIX = u'伟芳秀敏杰丹灵华兆婷超梁晗辉军越征凯腾江帆一中君盛丽群来未晨和刚明娜'

def get_rand(s):
    return s[random.randint(0, len(s) - 1)]

for i in range(t):
    b = Book()
    b.isbn = str(int(random.random() * (10 ** 13)))
    t = random.randint(1, 2)
    s = ''.join([get_rand(TITLE_PREFIX) for tt in range(0, t)])
    s += get_rand(TITLE_SUFFIX)
    b.title = s
    b.author = get_rand(AUTHOR_PREFIX) + get_rand(AUTHOR_SUFFIX);
    if random.randint(0, 2) == 1:
        b.author += get_rand(AUTHOR_SUFFIX)
    b.press = get_rand((u"复旦大学出版社", u"机械工业出版社", u"中华书局"))
    b.sale_price = round(random.random() * 100) + 1
    print b
    b.save()