def populate(): print('Populating books...', end='') titles = [ '穿在身上的 --草地恐龍時代毛衣', '穿在身上的 --星空刺繡暴龍長袖T恤', '穿在身上的 --手繪躲貓貓長袖T恤', '穿在身上的 --刺繡小鹿坑條毛衣', '穿在腿上的 --前口袋棉麻寬褲 ( 灰綠色 / 深灰色 )', '穿在腿上的 --刺繡扣復古高腰七分裙 ( 灰 / 藍 )', '其他其他的小東西 --窗台上的祕密戒指', '其他其他的小東西 --解不開結的戒指', '其他其他的小東西 --窗台的祕密戒指', '其他其他的小東西 --諾亞之心戒指', '裝錢的錢包 --水松木長夾( 彩色 / 原色 )', '裝錢的錢包 --手染掛頸手機零錢收納包 ( 海洋 / 夕陽 / 沙漠 )', ] materials = ['棉麻', 'Cotton, Polyester', 'Portuguese Cork', '銀'] Book.objects.all().delete() for title in titles: book = Book() book.title = title n = random.randint(0, len(materials) - 1) book.material = materials[n] book.pubdate = datetime.datetime.today() book.price = 690 book.save() print('done')
def add_book(request): context = dict() if request.method == "POST": if "url" in request.POST: url = request.POST["url"] context = parse_book_by_isbn(url) return render(request, "book/add.html", context) if "isbn" in request.POST: isbn = request.POST["isbn"] context = parse_book_by_isbn(isbn) book = Book() book.title = context["title"] book.publisher = context["publisher"] book.isbn = context["isbn"] book.url = context["url"] book.ispersonal = int(True) book.ownerid = request.user.id book.summary = context["summary"] book.price = context["price"] book.numraters = 0 book.averageRate = 3 book.created_date = datetime.datetime.now() book.updated_date = datetime.datetime.now() book.author = context["author"][0] book.authorinfo = context["author_intro"][0:4090] # print book.authorinfo book.catelog = context["catalog"][0:4090] book.pubdate = context["pubdate"] book.ispublic = int(True) book.imgurl = context["images"] book.city = Dper.objects.get(user_id=request.user.id).city book.bookcount = 1 book.status = 1 # Dper.objects.filter(id=request.user.id)[0].city book.save() # save tags of book for val in context["tags"]: tag = Tag() tag.value = val tag.createdate = datetime.datetime.now() tag.save() rel = Booktag() rel.tagid = tag.id rel.bookid = book.id rel.save() return redirect("/book/library", context) else: form = BookForm() context["form"] = form return render(request, "book/add.html", context)
def add_book(request): context = dict() if request.method == 'POST': if 'url' in request.POST: url = request.POST['url'] context = parse_book_by_url(url) return render(request, 'book/add.html', context) if 'bookid' in request.POST: bookid = request.POST['bookid'] context = parse_book_by_id(bookid) book = Book() book.title = context['title'] book.publisher = context['publisher'] book.isbn = context['isbn10'] if 'isbn10' in context else context[ 'isbn13'] book.url = context['url'] book.ispersonal = int(True) book.ownerid = request.user.id book.summary = context['summary'] book.price = context['price'] book.numraters = 0 book.averageRate = 3 book.created_date = datetime.datetime.now() book.updated_date = datetime.datetime.now() book.author = context['author'][0] book.pubdate = context['pubdate'] book.ispublic = int(True) book.imgurl = context['images'] book.save() #save tags of book for val in context['tags']: tag = Tag() tag.value = val tag.createdate = datetime.datetime.now() tag.save() rel = Booktag() rel.tagid = tag.id rel.bookid = book.id rel.save() return redirect('/book/library', context) else: form = BookForm() context['form'] = form return render(request, 'book/add.html', context)
def add_book(request): context = dict() if request.method == 'POST': if 'url' in request.POST: url = request.POST['url'] context = parse_book_by_url(url) return render(request, 'book/add.html', context) if 'bookid' in request.POST: bookid = request.POST['bookid'] context = parse_book_by_id(bookid) book = Book() book.title = context['title'] book.publisher = context['publisher'] book.isbn = context['isbn10'] if 'isbn10' in context else context['isbn13'] book.url = context['url'] book.ispersonal = int(True) book.ownerid = request.user.id book.summary = context['summary'] book.price = context['price'] book.numraters = 0 book.averageRate = 3 book.created_date = datetime.datetime.now() book.updated_date = datetime.datetime.now() book.author = context['author'][0] book.pubdate = context['pubdate'] book.ispublic = int(True) book.imgurl = context['images'] book.save() #save tags of book for val in context['tags']: tag = Tag() tag.value = val tag.createdate = datetime.datetime.now() tag.save() rel = Booktag() rel.tagid = tag.id rel.bookid = book.id rel.save() return redirect('/book/library', context) else: form = BookForm() context['form'] = form return render(request, 'book/add.html', context)
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})