def get(self, aid=None): if aid is None: aid = self.aid form = forms.HelloForm() a = A.select().where(A.id == aid).get() blist = [(b, C.select().where(C.parent == b)) for b in B.select().where(B.parent == a)] context = {'a': a, 'blist': blist, 'form': form} self.render('index.html', **context)
def get(self): form = forms.HelloForm() a = A.select().where(A.id == 1).get() blist = [(b, C.select().where(C.parent == b)) for b in B.select().where(B.parent == a)] context = {'a': a, 'blist': blist, 'form': form} alist = A.select().order_by(A.id) context.update(alist=alist) self.render('index.html', **context)
def get(self, aid, bid): b = B.select().where(B.id == bid).get() if b.parent.id != int(aid): aid = b.parent.id self.redirect('/%s_%s/' % (b.parent.id, bid)) a = A.select().where(A.id == aid).get() chapters = [(b, C.select().where(C.parent == b))] context = {'book': a, 'chapter': b, 'chapters': chapters} books = A.select().order_by(A.id) context.update(books=books) self.render("index.html", **context)
def get(self, aid): try: a = A.select().where(A.id == aid).get() chapters = [(b, C.select().where(C.parent == b)) for b in B.select().where(B.parent == a)] context = {'a': a, 'blist': chapters} books = A.select().order_by(A.id) context.update(books=books) self.render("index.html", **context) except A.DoesNotExist: raise tornado.web.HTTPError(404)
def get(self, aid, bid, cid): try: b = B.select().where(B.id == bid).get() except B.DoesNotExist: raise tornado.web.HTTPError(404) b = B.select().where(B.id == bid).get() if b.parent.id != int(aid): aid = b.parent.id self.redirect('/%s_%s/%s.html' % (b.parent.id, bid, cid)) a = A.select().where(A.id == aid).get() try: c = C.select().where(C.id == cid).get() except C.DoesNotExist: raise tornado.web.HTTPError(404) try: nextone = C.select().where(C.id > c.id, C.parent == b).order_by(C.id).get() except C.DoesNotExist: nextone = None try: previous = C.select().where(C.id < c.id, C.parent == b).order_by( C.id.desc()).get() except C.DoesNotExist: previous = None context = { 'book': a, 'chapter': b, 'article': c, 'previous': previous, 'next': nextone } books = A.select().order_by(A.id) context.update(books=books) print context self.render("detail.html", **context)