def delete(request, identifier): book = Book().get(identifier) readerBook = ReaderBook().byReaderAndBook(Reader.byCurrentUser(), book) readerBook.delete() return HttpResponseRedirect('/')
def index(request, username=None, state=None, page=1): reader = Reader.byUsername(username) if not reader: return HttpResponse('No such username') page = int(page) template_values = {} template_values["currentState"] = state template_values["readOnly"] = True template_values["books"] = [] template_values["toReadCount"] = reader.toReadCount template_values["inProgressCount"] = reader.inProgressCount template_values["finishedCount"] = reader.finishedCount template_values["totalCount"] = reader.totalCount # paging stuff paging.preparePagingTemplateForBookcase(template_values, reader, state, page) # end paging stuff for readerBook in ReaderBook.byReaderAndState(reader, state, page - 1): template_values["books"].append( mapping.toReaderBookTemplate(readerBook.book, readerBook)) template_values["navRoot"] = "/public/" + username return render(template_values)
def markAsTodo(request, identifier): book = Book().get(db.Key(identifier)) readerBook = ReaderBook.byReaderAndBook(Reader.byCurrentUser(), book) readerBook.state = 'unread' readerBook.put() return redirectToBook(book)
def index(request, username=None, state=None, page=1): reader = Reader.byUsername(username) if not reader: return HttpResponse('No such username') page = int(page) template_values = {} template_values["currentState"] = state template_values["readOnly"] = True template_values["books"] = [] template_values["toReadCount"] = reader.toReadCount template_values["inProgressCount"] = reader.inProgressCount template_values["finishedCount"] = reader.finishedCount template_values["totalCount"] = reader.totalCount # paging stuff paging.preparePagingTemplateForBookcase(template_values, reader, state, page) # end paging stuff for readerBook in ReaderBook.byReaderAndState(reader, state, page - 1): template_values["books"].append(mapping.toReaderBookTemplate(readerBook.book, readerBook)) template_values["navRoot"] = "/public/" + username return render(template_values)
def createReaderBookIfNecessary(reader, book, state): readerBook = ReaderBook.byReaderAndBook(reader, book) if not readerBook: readerBook = ReaderBook(parent=reader) readerBook.reader = reader readerBook.book = book readerBook.state = state readerBook.put()
def index(request, state=None, page=1): reader = Reader().byCurrentUser() user = users.get_current_user() page = int(page) template_values = {} if state: template_values["currentState"] = state else: template_values["currentState"] = "" if user: template_values["isLoggedIn"] = True else: template_values["isLoggedIn"] = False if not reader: template_values["loginUrl"] = users.create_login_url('/reader') else: template_values["hasReader"] = True template_values["books"] = [] template_values["toReadCount"] = reader.toReadCount template_values["inProgressCount"] = reader.inProgressCount template_values["finishedCount"] = reader.finishedCount template_values["totalCount"] = reader.totalCount template_values["showRatings"] = True # paging stuff paging.preparePagingTemplateForBookcase(template_values, reader, state, page) # end paging stuff if state == "unrated": collection = ReaderBook.byReaderUnrated(reader, page - 1) else: collection = ReaderBook.byReaderAndState(reader, state, page - 1) for readerBook in collection: template_values["books"].append( mapping.toReaderBookTemplate(readerBook.book, readerBook)) template_values["navRoot"] = "/bookcase" template_values["viewtype"] = "searchresult.html" return render(template_values)
def index(request, state=None, page=1): reader = Reader().byCurrentUser() user = users.get_current_user() page = int(page) template_values = {} if state: template_values["currentState"] = state else: template_values["currentState"] = "" if user: template_values["isLoggedIn"] = True else: template_values["isLoggedIn"] = False if not reader: template_values["loginUrl"] = users.create_login_url('/reader') else: template_values["hasReader"] = True template_values["books"] = [] template_values["toReadCount"] = reader.toReadCount template_values["inProgressCount"] = reader.inProgressCount template_values["finishedCount"] = reader.finishedCount template_values["totalCount"] = reader.totalCount template_values["showRatings"] = True # paging stuff paging.preparePagingTemplateForBookcase(template_values, reader, state, page) # end paging stuff if state == "unrated": collection = ReaderBook.byReaderUnrated(reader, page - 1) else: collection = ReaderBook.byReaderAndState(reader, state, page - 1) for readerBook in collection: template_values["books"].append(mapping.toReaderBookTemplate(readerBook.book, readerBook)) template_values["navRoot"] = "/bookcase" template_values["viewtype"] = "searchresult.html" return render(template_values)
def delete(request): r = Reader.byCurrentUser() if r: list = ReaderBook.all(keys_only=True).ancestor(r).fetch(1000) db.delete(list) r.delete() else: return HttpResponseRedirect('/') return HttpResponse(render('reader_delete_confirm.html', None))
def export(request): reader = Reader().byCurrentUser() collection = ReaderBook.finishedBooks(reader) response = HttpResponse(content_type='text/csv') response['Content-Disposition'] = 'attachment; filename="somefilename.csv"' writer = csv.writer(response) writer.writerow(['Title', 'ISBN', 'My Rating', 'Date Read', 'Date Added']) for c in collection: title = c.book.title.replace('""', '') writer.writerow([title,c.book.isbn,c.rating,c.finishedDate,c.created]) return response
def export(request): reader = Reader().byCurrentUser() collection = ReaderBook.finishedBooks(reader) response = HttpResponse(content_type='text/csv') response['Content-Disposition'] = 'attachment; filename="somefilename.csv"' writer = csv.writer(response) writer.writerow(['Title', 'ISBN', 'My Rating', 'Date Read', 'Date Added']) for c in collection: title = c.book.title.replace('""', '') writer.writerow( [title, c.book.isbn, c.rating, c.finishedDate, c.created]) return response
def index(request): reader = Reader().byCurrentUser() fromDate = getPastDate(1) finished = ReaderBook.finishedBooks(reader, fromDate) # 12 months where each is a list to a book months = [[] for i in range(12)] for b in finished: if b.finishedDate: months[b.finishedDate.month - 1].append(b.book.title) tv = {} tv["months"] = months return render(tv)
def layout(request): # get all the books within x amount of time layed out by date # go by each day from the earliest day # output day and the book that is being read on that day # and continue doing that until all the books have been output reader = Reader().byCurrentUser() fromDate = getPastDate(2) finished = ReaderBook.finishedBooks(reader, fromDate) currentDate = fromDate byDate = {} while currentDate <= datetime.date.today() + datetime.timedelta(days=1): list = matchedBookByDate(currentDate, finished) byDate[currentDate] = [] for b in list: byDate[currentDate].append(b.book.title) currentDate = currentDate + datetime.timedelta(days=1) return render_to_response('layout.html', {"data" : sorted(byDate.iteritems())})
def layout(request): # get all the books within x amount of time layed out by date # go by each day from the earliest day # output day and the book that is being read on that day # and continue doing that until all the books have been output reader = Reader().byCurrentUser() fromDate = getPastDate(2) finished = ReaderBook.finishedBooks(reader, fromDate) currentDate = fromDate byDate = {} while currentDate <= datetime.date.today() + datetime.timedelta(days=1): list = matchedBookByDate(currentDate, finished) byDate[currentDate] = [] for b in list: byDate[currentDate].append(b.book.title) currentDate = currentDate + datetime.timedelta(days=1) return render_to_response('layout.html', {"data": sorted(byDate.iteritems())})
def viewByIsbn(request, isbn = ""): user = users.get_current_user() reader = None book = None readerBook = None if user: reader = Reader.byCurrentUser() book = fetchCreateByISBN(isbn, invokeSearchByIsbn, True) readerBook = ReaderBook.byReaderAndBook(reader, book) template_values = mapping.toReaderBookTemplate(book, readerBook) if not user: template_values["loginUrlToAdd"] = users.create_login_url('/book/isbn/' + isbn) else: if not reader: template_values["signupUrl"] = '/reader' return render(template_values)
def viewByIsbn(request, isbn=""): user = users.get_current_user() reader = None book = None readerBook = None if user: reader = Reader.byCurrentUser() book = fetchCreateByISBN(isbn, invokeSearchByIsbn, True) readerBook = ReaderBook.byReaderAndBook(reader, book) template_values = mapping.toReaderBookTemplate(book, readerBook) if not user: template_values["loginUrlToAdd"] = users.create_login_url( '/book/isbn/' + isbn) else: if not reader: template_values["signupUrl"] = '/reader' return render(template_values)
def view(request, identifier): book = db.get(db.Key(identifier)) readerBook = ReaderBook.byReaderAndBook(Reader.byCurrentUser(), book) return render(mapping.toReaderBookTemplate(book, readerBook))
def getCurrentUserBook(identifier): return ReaderBook.byReaderAndBook(Reader.byCurrentUser(), db.Key(identifier))
def view(request, identifier): book = db.get(db.Key(identifier)) readerBook = ReaderBook.byReaderAndBook(Reader.byCurrentUser(), book) return render( mapping.toReaderBookTemplate(book, readerBook) )