def get(self, book_id, id): chapter = Chapter.get_chapter_by_id(id) if not chapter: raise HTTPError(404) book = Book.get_book_by_id(chapter.book_id) author = Author.get_author_by_id(book["author_id"]) text = "" from tornado.options import options filepath = os.path.join(options.txt_path, str(int(book_id) / 1000), book_id, id) if os.path.exists(filepath): obj_file = open(filepath) try: text = obj_file.read() finally: obj_file.close() else: row = Chapter.get_text_by_id(id) if row is not None: text = row['text'] #text = htmlremove(text) else: text = '正在努力的加载数据...' #text = htmlremove(text) previous = Chapter.get_previous(book_id, chapter["sort_num"]) if not previous: previous = 'index' else: previous = previous["id"] next = Chapter.get_next(book_id, chapter["sort_num"]) if not next: next = 'index' else: next = next["id"] self.render( "chapter.html", book=book, chapter=chapter, text=text, author=author, previous=previous, next=next, )
def get(self, book_id, id): chapter = Chapter.get_chapter_by_id(id) if not chapter: raise HTTPError(404) book = Book.get_book_by_id(chapter.book_id) author = Author.get_author_by_id(book["author_id"]) text = "" from tornado.options import options filepath = os.path.join(options.txt_path, str(int(book_id)/1000), book_id, id) if os.path.exists(filepath): obj_file = open(filepath) try: text = obj_file.read() finally: obj_file.close() else: row = Chapter.get_text_by_id(id) if row is not None: text = row['text'] #text = htmlremove(text) else: text = '正在努力的加载数据...' #text = htmlremove(text) previous = Chapter.get_previous(book_id, chapter["sort_num"]) if not previous: previous = 'index' else: previous = previous["id"] next = Chapter.get_next(book_id, chapter["sort_num"]) if not next: next = 'index' else: next = next["id"] self.render("chapter.html", book=book, chapter=chapter, text=text, author=author, previous=previous, next=next, )
def get(self, id): book = Book.get_book_by_id(id) if not book: raise HTTPError(404) a = [] author = Author.get_author_by_id(book["author_id"]) volumes = Volume.get_volumes_by_book_id(id) chapters = Chapter.get_chapters_by_book_id(id) for i, item in enumerate(volumes): var = {} var['id'] = item.id var['title'] = item.title var['chs'] = [] for ch in chapters: if ch.volume_id == item.id: var['chs'].append(ch) a.append(var) self.render("chapters.html", book=book, volumes=a, author=author)
def get(self, id): book = Book.get_book_by_id(id) if not book: raise HTTPError(404) a = [] author = Author.get_author_by_id(book["author_id"]) volumes = Volume.get_volumes_by_book_id(id) chapters = Chapter.get_chapters_by_book_id(id) for i,item in enumerate(volumes): var ={} var['id'] = item.id var['title'] = item.title var['chs'] = [] for ch in chapters: if ch.volume_id == item.id: var['chs'].append(ch) a.append(var) self.render("chapters.html", book=book, volumes=a, author=author)