Example #1
0
def contribute_book(request):
	if request.method == 'POST':
		book(book_title=request.POST['title'],
			user=request.user,
			book_author=request.POST['auther'],
			description = request.POST['description'],
			details = request.POST['detail'],
			cover=request.FILES['cover_image'],
			alt_text=request.POST['alt_text'],
			genre=request.POST['genre']
		).save()
		return HttpResponseRedirect('/bookshelf')
	else:
		return render(request, "books/upload.html", {})
Example #2
0
def contribute_book(request):
    if request.method == 'POST':
        book(book_title=request.POST['title'],
             user=request.user,
             book_author=request.POST['author'],
             description=request.POST['description'],
             details=request.POST['detail'],
             cover=request.FILES['cover_image'],
             alt_text=request.POST['alt_text'],
             genre=request.POST['genre'],
             book_text=request.FILES['book_text']).save()
        return HttpResponseRedirect('/bookshelf')
    else:
        return render(request, "books/upload.html", {})
Example #3
0
def book_index(request):
    if request.method == 'POST':
        form = newBookForm(request.POST)
        if form.is_valid():
            googleAPIURL = 'https://www.googleapis.com/books/v1/volumes'
            PARAMS = {
                'key': os.environ.get('googleBookKey'),
                'q': form.cleaned_data['bookTitle'],
                'maxResults': '1'
            }
            data = requests.get(url=googleAPIURL, params=PARAMS).json()
            bookInfo = data['items'][0]['volumeInfo']

            newBook = book(
                title=bookInfo['title'],
                author=bookInfo['authors'][0],
                genre=bookInfo['categories'][0],
                page_count=bookInfo['pageCount'],
            )
            newBook.save()

    else:
        form = newBookForm()

    books = book.objects.all().order_by('read_on')
    context = {'books': books, 'form': form}
    return render(request, 'book_index.html', context)
Example #4
0
    def setUp(self):
        self.author1 = AuthorFactory(name="Author 1")
        self.author2 = AuthorFactory(name="Author 2")

        self.book= book(title="MyBook")
        self.book.save()

        self.book.authors.add(self.author1.pk,self.author2.pk)
Example #5
0
def addbook(request):
    j=request.GET['p']
    k=request.GET['q']
    l=request.GET['i']
    if Author.objects.filter(Name=j):
        Athor=Author.objects.get(Name=j)
        p1=book(AuthorID=Athor.AuthorID,Title=k)
        p1.save()
        return render_to_response('search_form.html')
    else:
        if Author.objects.filter(AuthorID=l):
            return HttpResponse("The ID already exists!")
        else:
            p2=Author(Name=j,AuthorID=l)
            p2.save()
            p=book(AuthorID=l,Title=k)
            p.save()
            return render_to_response('search_form.html')
Example #6
0
def save_book(book_id,isbn,title,author,publisher):
        new_book=book()
        
        new_book.book_id=book_id
        new_book.isbn=isbn
        
        new_book.title= title
        new_book.author= author
        new_book.publisher= publisher
        new_book.save()
Example #7
0
def save_book(book_id, isbn, title, author, publisher):
    new_book = book()

    new_book.book_id = book_id
    new_book.isbn = isbn

    new_book.title = title
    new_book.author = author
    new_book.publisher = publisher
    new_book.save()
Example #8
0
def add_user_book(user, cover, title, points, author, description, genre):

	userProf = userProfile.objects.get(user=user)
        userProf.points = F('points') + 50
	userProf.save()

	Book = book()
	Book.book_cover = cover
	Book.book_title = title
	Book.book_points = points
	Book.book_author = author
	Book.description = description
	Book.genre = genre
	Book.user = user
	Book.save()
Example #9
0
def add_user_book(user, cover, title, points, author, description, genre, reqpoints, book_text):

	#userProf = userProfile.objects.get(user=user)
        #userProf.points = F('points') + 50
	#userProf.save()

	Book = book()
	Book.book_cover = cover
	Book.book_title = title
	Book.book_text = book_text
        if points.isdigit():
            Book.book_points = points
        Book.reqpoints = reqpoints
	Book.book_author = author
	Book.description = description
	Book.genre = genre
	Book.user = user
	Book.save()
Example #10
0
def books(request):    
    disk={"exist":False,'isbn':''}   
    if request.path!="/book/":
        isbn=re.findall("(?<=\/book\/)\d*",request.path)[0]
        abook=book.objects.get(ISBN=isbn)
        list_=[abook.ISBN,abook.Title,abook.AuthorID.Name,abook.Publisher\
        ,str(abook.PublishDate.year)+'-'+str(abook.PublishDate.month)+'-'+\
        str(abook.PublishDate.day),abook.Price]
        disk={"exist":False,'isbn':'','list':list_}
        if request.POST:
            name=request.POST['AuthorName']
            if request.POST['ISBN']=='' or\
                    request.POST['Title']=='' or \
                    request.POST['Publisher']=='' or\
                    request.POST['Price']=='':
                        disk={"exist":False,'isbn':'有缺省项'}
            elif not re.match('\d{13}$',request.POST['ISBN']):
                disk={"exist":False,'isbn':'isbn不符合格式,要求13位数字!'}
            else:                
                try:
                    if request.POST["ISBN"]!=abook.ISBN:
                        book.objects.get(ISBN=request.POST["ISBN"])
                        disk['isbn']='ISBN冲突'
                    else:
                        raise ObjectDoesNotExist
                except ObjectDoesNotExist:
                    try:
                        anauth=Author.objects.get(Name=name)
                        abook.ISBN=request.POST['ISBN']
                        abook.save()
                        abook.Title=request.POST['Title']
                        abook.save()
                        abook.Publisher=request.POST['Publisher']
                        abook.save()
                        abook.PublishDate=request.POST['year']+'-'+\
                                 request.POST['month']+'-'+\
                                 request.POST['day']
                        abook.save()
                        abook.AuthorID=anauth
                        abook.save()
                        book.objects.get(ISBN=isbn).delete()
                        disk={"exist":False,'isbn':'修改成功!'}
                    except ObjectDoesNotExist:
                        disk["exist"]=True
                        disk['isbn']='作者不存在或书籍已经存在'                                                    
    else:
        if request.POST:
            name=request.POST['AuthorName']
            if request.POST['ISBN']=='' or\
                    request.POST['Title']=='' or \
                    request.POST['Publisher']=='' or\
                    request.POST['Price']=='':
                        disk={"exist":False,'isbn':'有缺省项'}
            elif not re.match('\d{13}$',request.POST['ISBN']):
                disk={"exist":False,'isbn':'isbn不符合格式,要求13位数字!'}
            else:
                try:
                    anauth=Author.objects.get(Name=name)
                    new=book(ISBN=request.POST['ISBN'],
                             Title=request.POST['Title'],
                             Publisher=request.POST['Publisher'],
                             PublishDate=request.POST['date'],
                             Price=request.POST['Price'],
                             AuthorID=anauth   )                        
                    new.save()
                    disk={"exist":False,'isbn':'添加成功!'}
                except ObjectDoesNotExist:
                    disk["exist"]=True
                    disk['isbn']='作者不存在或书籍已经存在'
    page=render_to_response('html/book.html',disk,context_instance=\
    RequestContext(request))

    return HttpResponse(page)
Example #11
0
def search_author_form(request):
    if request.POST:
        if "author_name" in request.POST and len(request.POST["author_name"]):
            author1 = author.objects.filter(name__icontains=request.POST["author_name"])
            book1 = book.objects.filter(authorID__name__icontains=request.POST["author_name"])
            if len(author1):
                return render_to_response(
                    "search_author_form.html",
                    {
                        "submit": True,
                        "author_exist": True,
                        "author": author1[0],
                        "books": book1,
                        "booknumber": len(book1),
                    },
                )
            else:
                return render_to_response(
                    "search_author_form.html",
                    {"submit": True, "author_exist": False, "authorname": request.POST["author_name"]},
                )

        if (
            ("authorID" in request.POST)
            and ("name" in request.POST)
            and ("age" in request.POST)
            and ("country" in request.POST)
            and request.POST["authorID"]
            and request.POST["name"]
            and request.POST["age"]
            and request.POST["country"]
        ):
            author2 = author(
                authorID=request.POST["authorID"],
                name=request.POST["name"],
                age=request.POST["age"],
                country=request.POST["country"],
            )
            author2.save()
            return render_to_response(
                "search_author_form.html", {"submit": True, "author_exist": True, "author": author2}
            )

        if (
            request.POST["ISBN"]
            and request.POST["title"]
            and request.POST["authorID"]
            and request.POST["publisher"]
            and request.POST["publishDate"]
            and request.POST["price"]
        ):
            author3 = author.objects.filter(authorID__icontains=request.POST["authorID"])
            if len(author3):
                book1 = book(
                    ISBN=request.POST["ISBN"],
                    title=request.POST["title"],
                    authorID=author3[0],
                    publisher=request.POST["publisher"],
                    publishDate=request.POST["publishDate"],
                    price=request.POST["price"],
                )
                book1.save()
                book1 = book.objects.filter(authorID__name__icontains=author3[0].name)
                return render_to_response(
                    "search_author_form.html",
                    {
                        "submit": True,
                        "author_exist": True,
                        "author": author3[0],
                        "books": book1,
                        "booknumber": len(book1),
                    },
                )

    return render_to_response("search_author_form.html", {"submit": False})