def view(self, almanac_slug): c.almanac = h.get_almanac_by_slug(almanac_slug) loc = c.almanac.location_4326 c.lng, c.lat = loc.x, loc.y page_idx = request.GET.get('page', 1) try: page_idx = int(page_idx) except ValueError: page_idx = 1 pages_query = meta.Session.query(Page).filter(Page.almanac_id==c.almanac.id).filter(Page.published == True).order_by(Page.modified.desc()) try: c.next_page = pages_query[:1][0] except IndexError: pass else: c.next_page_url = h.url_for('page_view', almanac=c.almanac, page=c.next_page) c.next_page_text = c.next_page.name per_page = 10 pagination = PaginationPage(pages_query, page=page_idx, items_per_page=per_page) c.toc_pagination_data = h.pagination_data(pagination) c.pages = pagination.items c.npages = pagination.item_count return render('/almanac/view.mako')
def all_pages(self, query): c.no_maps = True c.query_global = query if query: pages_query = Page.search_all(query) else: pages_query = Page.latest(query_only=True) page_idx = request.GET.get('page', 1) try: page_idx = int(page_idx) except ValueError: page_idx = 1 per_page = 10 pagination = PaginationPage(pages_query, page=page_idx, items_per_page=per_page) c.pagination_data = h.pagination_data(pagination) c.pages = pagination.items c.npages = pagination.item_count c.latest_pages = Page.latest() return render('/search_all.mako')
def search(self, almanac_slug, query): c.almanac = h.get_almanac_by_slug(almanac_slug) loc = c.almanac.location_4326 c.lng, c.lat = loc.x, loc.y page_idx = request.GET.get('page', 1) try: page_idx = int(page_idx) except ValueError: page_idx = 1 per_page = 10 pagination = PaginationPage(c.almanac.search(query), page=page_idx, items_per_page=per_page) c.pagination_data = h.pagination_data(pagination) c.pages = pagination.items c.npages = pagination.item_count c.query = query # latest pages for sidebar c.latest_pages = Page.latest(limit=10, almanac_id=c.almanac.id) return render('/almanac/search.mako')