def search(self,key): print key if self.r.exists(key) != 0: book = pickle.loads(self.r.get(key)) self.dbmongo.cachehit.insert({'date':datetime.utcnow()}) else: if key[0] != 'None': print key if key[1] != 'None': print key if key[2] != '': book = list(self.dbmongo.books.find({"genre._id":ObjectId(key[0]),'author._id':ObjectId(key[1]),'name':key[2]})) else: book = list(self.dbmongo.books.find({"genre._id":ObjectId(key[0]),"author._id":ObjectId(key[1])})) elif key[2]!='': book = list(self.dbmongo.books.find({"genre._id":ObjectId(key[0]),"name":key[2]})) else: print key book = list(self.dbmongo.books.find({"genre._id":ObjectId(key[0])})) elif key[1]!='None': if key[2]!='': book = list(self.dbmongo.books.find({"author._id":ObjectId(key[1]),"name":key[2]})) else: book = list(self.dbmongo.books.find({"author._id":ObjectId(key[1])})) elif key[2]!='': book = list(self.dbmongo.books.find({"name":key[2]})) else: self.list=[] book=[] self.r.set(key, pickle.dumps(book)) self.dbmongo.activity.insert({'date':datetime.utcnow()}) books = [] for x in book: books.append(bookFromDict(x)) return books
def top100Date(self): self.dbmongo.activity.insert({'date':datetime.utcnow()}) books = self.dbmongo.books.aggregate([ {"$sort": {"date":-1}}, {"$limit":100}]); book=[] for i in books["result"]: book.append(bookFromDict(i)) return book
def top100Comments(self): self.dbmongo.activity.insert({'date':datetime.utcnow()}) books = self.dbmongo.comment.aggregate([ {"$group": {"_id": "$book._id","count": {"$sum": 1}}}, {"$sort":{"count":-1}}, {"$limit":100}]) book=[] for i in books["result"]: book.append(bookFromDict(self.dbmongo.books.find({"_id":i["_id"]})[0])) return book
def popular(self): books = self.dbmongo.books.find().sort(u'likes',-1).limit(10) book=[] x=0 for i in books: book.append(bookFromDict(i)) x+=1 if x==10: break return book
def latest_books(self): books = self.dbmongo.books.find().sort(u'date',-1) book=[] x=0 for i in books: book.append(bookFromDict(i)) x+=1 if x==10: break return book
def getBooksList(self): books = [] book = self.dbmongo.books.find().sort(u'date',-1) for x in book: books.append(bookFromDict(x)) return books
def book(request): if request.POST.get("deletecomment"): book = database.DeleteComment(request.POST["deletecomment"]) comments = database.GetComments(book) book = database.dbmongo.books.find({'_id': ObjectId((book))})[0] book = bookFromDict(book) return render( request, 'library/book.html', { 'book': book, 'genres': database.genres, 'user': database.user, 'comments': comments }) if request.POST.get("addcomment"): database.AddComment(request.POST["addcomment"], request.POST["comment"]) comments = database.GetComments(request.POST['addcomment']) book = database.dbmongo.books.find( {'_id': ObjectId((request.POST['addcomment']))})[0] book = bookFromDict(book) return render( request, 'library/book.html', { 'book': book, 'genres': database.genres, 'user': database.user, 'comments': comments }) if request.POST.get("like"): if database.checkLike(request.POST['like']) == 1: database.removeLike(request.POST['like']) else: database.addLike(request.POST['like']) comments = database.GetComments(request.POST['like']) book = database.dbmongo.books.find( {'_id': ObjectId((request.POST['like']))})[0] book = bookFromDict(book) return render( request, 'library/book.html', { 'book': book, 'genres': database.genres, 'user': database.user, 'comments': comments }) if request.POST.get("dislike"): if database.checkDislike(request.POST['dislike']) == 1: database.removeDislike(request.POST['dislike']) else: database.addDislike(request.POST['dislike']) comments = database.GetComments(request.POST['dislike']) book = database.dbmongo.books.find( {'_id': ObjectId((request.POST['dislike']))})[0] book = bookFromDict(book) return render( request, 'library/book.html', { 'book': book, 'genres': database.genres, 'user': database.user, 'comments': comments, }) comments = database.GetComments(request.POST['book']) book = database.dbmongo.books.find( {'_id': ObjectId((request.POST['book']))})[0] book = bookFromDict(book) return render( request, 'library/book.html', { 'book': book, 'genres': database.genres, 'user': database.user, 'comments': comments })