def Home(request): print os.path.dirname(os.path.dirname(os.path.abspath(__file__))) print os.path.dirname(os.path.abspath(__file__)) context={'page_title':Constants.homeTitle} context['booktypes']=Business.BookInformation().GetBookType() userbooks=None if request.method=='GET': context['searchform']=SearchBook() userbooks=Business.BookInformation().GetUsersBook() if request.method=='POST': serform=SearchBook(data=request.POST) name=request.POST['searchBox'] context['searchform']=serform userbooks=BookInformation().GetUsersBook(book_name=name) paginator = Paginator(userbooks,3) page = request.GET.get('page') try: books= paginator.page(page) except PageNotAnInteger: # If page is not an integer, deliver first page. books = paginator.page(1) except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results. books = paginator.page(paginator.num_pages) context['books']=books return render_to_response('Home.html',context,context_instance=RequestContext(request))
def BookFilter(request): c={'page_title':Constants.homeTitle} c['searchform']=SearchBook() book_type=Business.BookInformation().GetBookType() book_filter_id=[] selectedType=[] if request.method=='POST': for bk_type in book_type: #name=request.POST.get(str(bk_type.id)) #book_filter_id.append(name) book_filter_id=request.POST.getlist('book_type') if(book_filter_id.__len__()>0): userbooks=Business.BookInformation().GetUsersBook(book_type_id=book_filter_id) #c['len']=book_filter_id.__len__() c['FilterList']=Business.BookInformation().GetBookType(book_filter_id) else: userbooks=Business.BookInformation().GetUsersBook() c['booktypes']=book_type#Business.BookInformation().GetBookType() paginator = Paginator(userbooks,3) page = request.GET.get('page') try: books= paginator.page(page) except PageNotAnInteger: # If page is not an integer, deliver first page. books = paginator.page(1) except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results. books = paginator.page(paginator.num_pages) c['books']=books #return HttpResponse("sdgfdn gdfg") return render_to_response('Home.html',context=c,context_instance=RequestContext(request))
def BookRating(request,book_id): if request.method=='POST': rating=request.POST.get('rating_'+str(book_id)) #rating=max(rating) Business.BookInformation().bookRating(book_id, rating,user_id=request.session['user_name']) #return HttpResponse(json.dump(new_rating)) return redirect(reverse('Review.Home'))
def BookInfo(request,book_id): c={'page_title':Constants.addBookTitle} c={'page_title':Constants.bookInfoTitle} c['BookInfo']=Business.BookInformation().GetBookInfo(book_id=book_id) c['BookReview']=Business.BookInformation().GetReviewInfo(book_id=book_id,user_id=request.session['user_name']) if request.method=='GET': c['form']=ReviewForm() return render_to_response('Book_Info.html',context=c,context_instance=RequestContext(request)) if request.method=='POST': form=ReviewForm(data=request.POST) if form.is_valid(): review=request.POST['review'] user_id=request.session['user_name'] Business.BookInformation().AddReview(book_id,user_id,review) return HttpResponseRedirect("/BookInfo/%s" % book_id) else: c['form']=form return render_to_response('Book_Info.html',context=c,context_instance=RequestContext(request))
def AddBookInfo(request): if request.method=='POST': book_name=request.POST['name'] book_type=request.POST['type'] book_desc=request.POST['description'] book_image=request.FILES['image'] book_review=request.POST['review'] book_rate=request.POST['rating'] user_name=request.session['user_name'] book=Business.BookInformation().AddBook(book_name=book_name,book_type_id=book_type,book_desc=book_desc,book_image=book_image, book_rating=book_rate,book_review=book_review,user_name=user_name) return HttpResponseRedirect('/UserBooks/')
def AddBook(request): template='AddBook.html' c={'page_title':Constants.addBookTitle} c['booktypes']=Business.BookInformation().GetBookType() if request.method=='GET': c['form']=BookInfoForm() return render_to_response(template,context=c,context_instance=RequestContext(request)) if request.method=='POST': form=BookInfoForm(request.POST,request.FILES) if form.is_valid(): book_name=request.POST['name'] book_type=request.POST['type'] book_desc=request.POST['description'] book_image=request.FILES['image'] book_review=request.POST['review'] book_rate=request.POST['rating'] user_name=request.session['user_name'] book=Business.BookInformation().AddBook(book_name=book_name,book_type_id=book_type,book_desc=book_desc,book_image=book_image, book_rating=book_rate,book_review=book_review,user_name=user_name) return HttpResponseRedirect('/UserBooks/') else: c['form']=form return render_to_response(template,c,context_instance=RequestContext(request))
def AddReview(request,book_id): if request.method=='POST': review=request.POST['review'] user_id=request.session['user_name'] Business.BookInformation().AddReview(book_id,user_id,review) return HttpResponseRedirect("/BookInfo/%s" % book_id)
def UserBooks(request): user_name=request.session['user_name'] c={'page_title':'My Books'} c['UserBooks']=Business.BookInformation().GetUsersBook(user_name) c['booktypes']=Business.BookInformation().GetBookType() return render_to_response('MyLibrary.html',context=c,context_instance=RequestContext(request));