def all_entries(self, page=1): # Similar to above. Now, we won't filter by category. now = datetime.datetime.utcnow() entries_per_page = g.blog_config.entries_per_page nr_of_entries = query.entries(self.is_preview, archivable=True).count() # same as above (see ``self.category``) if nr_of_entries > 0 and (page-1)*entries_per_page >= nr_of_entries: return abort(404) entries = query.entries(self.is_preview, start=(page - 1) * entries_per_page, page_size=entries_per_page, archivable=True) if page <= 1: newer = None else: newer = page - 1 if page * entries_per_page >= nr_of_entries: older = None else: older = page + 1 return render_template('all-entries.html', entries=entries, # we have to tell the template this is the 'All' page is_all=True, current_page=page, older=older, newer=newer, cls=self)
def category(self, catslug, page=1): now = datetime.datetime.utcnow() category = db.session.query(Category).filter_by(slug=catslug).first() if not category: return abort(404) entries_per_page = g.blog_config.entries_per_page nr_of_entries = query.entries(self.is_preview, catslug, archivable=False).count() # if nr_of_entries is = 0, we don't want to show an error, as it simply # means the category is empty. Especially when adding entries from the command line, # it might be useful to have temporarily empty entries if nr_of_entries > 0 and (page-1)*entries_per_page >= nr_of_entries: return abort(404) # Get the entries (remember, page numbers start at 1!) entries = query.entries(self.is_preview, catslug, start=(page - 1) * entries_per_page, page_size=entries_per_page, archivable=False).all() # Get the *next* (= ``newer``) and *previous* (= ``older``) pages: # if there are no ``older`` or ``newer```pages, set the corresponding # value to ``None``. This will be used by the template. if page <= 1: newer = None else: newer = page - 1 if page * entries_per_page >= nr_of_entries: older = None else: older = page + 1 return render_template('category.html', entries=entries, category=category, active_category=catslug, current_page=page, older=older, newer=newer, route='category', cls=self)
def search_results_entries(self, search_query): now = datetime.datetime.utcnow() sql_q = query.entries(self.is_preview, archivable=False) entries = search(sql_q, search_query.lower()) # It won't need pagination for now return render_template('search-results-entries.html', search_query=search_query, entries=entries, cls=self)
def archives(self): now = datetime.datetime.utcnow() entries = query.entries(self.is_preview) # Group the entries by year: grouping = itertools.groupby(entries, lambda entry: entry.created.year) return render_template("archives.html", title="Archives", grouping=grouping, # We have to tell th template that we are rendering the # "archives" page, so that the template knows what to # mark as active in the bar. is_archives=True, # we supply the instance as an argument, so that we can call # ``cls.url_for()`` inside the template, and be redirected to # the correct endpoint. cls=self)
def atom_feed_entries(): now = datetime.datetime.utcnow() config = g.blog_config title = config.blog_title + " Entries" subtitle = config.blog_subtitle feed = AtomFeed(title, feed_url=request.url, url=request.host_url, subtitle=subtitle) for entry in query.entries(False, page_size=config.entries_in_feed).all(): feed.add(entry.title, entry.lead + entry.content, content_type='html', author=entry.author.name, url=url_for('PublicView.entry', slug=entry.slug), id=entry.id, updated=entry.created, published=entry.created) return feed.get_response()
def recent_entries(self): max_entries = g.blog_config.entries_in_sidebar now = datetime.datetime.utcnow() recent_entries = query.entries(self.is_preview, page_size=max_entries) return recent_entries