def show_category(req, slug, page=1): """Show all posts categoryged with a given category slug. Available template variables: `posts`: a list of post objects we want to display `pagination`: a pagination object to render a pagination `category` the category object for this page :Template name: ``show_category.html`` :URL endpoint: ``blog/show_category`` """ category = Category.query.filter_by(slug=slug).first(True) per_page = req.app.theme.settings['category.per_page'] data = category.posts.theme_lightweight('category') \ .published().get_list(page=page, per_page=per_page, endpoint='blog/show_category', url_args=dict(slug=slug)) add_link('alternate', url_for('blog/atom_feed', category=slug), 'application/atom+xml', _(u'All posts in category %s') % category.name) return render_response('show_category.html', category=category, **data)
def show_author(req, username, page=1): """Show the user profile of an author / editor or administrator. Available template variables: `posts`: a list of post objects this author wrote and are visible on this page `pagination`: a pagination object to render a pagination `user` the user object for this author :Template name: ``show_author.html`` :URL endpoint: ``blog/show_author`` """ user = User.query.filter_by(username=username).first() if user is None or not user.is_author: raise NotFound() per_page = req.app.theme.settings['author.per_page'] data = user.posts.theme_lightweight('author').published() \ .get_list(page=page, per_page=per_page, endpoint='blog/show_author', url_args=dict(username=user.username)) add_link('alternate', url_for('blog/atom_feed', author=user.username), 'application/atom+xml', _(u'All posts written by %s') % user.display_name) return render_response('show_author.html', user=user, **data)
def show_tag(req, slug, page=1): """Show all posts categoryged with a given tag slug. Available template variables: `posts`: a list of post objects we want to display `pagination`: a pagination object to render a pagination `tag` the tag object for this page :Template name: ``show_tag.html`` :URL endpoint: ``blog/show_tag`` """ tag = Tag.query.filter_by(slug=slug).first(True) per_page = req.app.theme.settings['tag.per_page'] data = tag.posts.theme_lightweight('tag') \ .published().get_list(page=page, endpoint='blog/show_tag', per_page=per_page, url_args=dict(slug=slug)) add_link('alternate', url_for('blog/atom_feed', tag=slug), 'application/atom+xml', _(u'All posts tagged %s') % tag.name) return render_response('show_tag.html', tag=tag, **data)
def archive(req, year=None, month=None, day=None, page=1): """Render the monthly archives. Available template variables: `posts`: a list of post objects we want to display `pagination`: a pagination object to render a pagination `year` / `month` / `day`: integers or None, useful to entitle the page :Template name: ``archive.html`` :URL endpoint: ``blog/archive`` """ if not year: return render_response('archive.html', month_list=True, **Post.query.published().for_index() .get_archive_summary()) url_args = dict(year=year, month=month, day=day) per_page = req.app.theme.settings['archive.per_page'] data = Post.query.theme_lightweight('archive_overview') \ .published().for_index().date_filter(year, month, day) \ .get_list(page=page, endpoint='blog/archive', url_args=url_args, per_page=per_page) add_link('alternate', url_for('blog/atom_feed', **url_args), 'application/atom+xml', _(u'Recent Posts Feed')) return render_response('archive.html', year=year, month=month, day=day, date=date(year, month or 1, day or 1), month_list=False, **data)
def dispatch_content_type(req): """Show the post for a specific content type.""" slug = req.path[1:] # feed for the post if slug.endswith('/feed.atom'): slug = slug[:-10] want_feed = True else: want_feed = False post = Post.query.filter_by(slug=slug).first() if post is None: # if the post does not exist, check if a post with a trailing slash # exists. If it does, redirect to that post. This is allows users # to emulate folders and to get relative links working. if not slug.endswith('/'): real_post = Post.query.filter_by(slug=slug + '/').first() if real_post is None: raise NotFound() # if we want the feed, we don't want a redirect elif want_feed: post = real_post else: return redirect_to(real_post) else: raise NotFound() # make sure the current user can access that page. if not post.can_read(): raise Forbidden() # feed requested? jump to the feed page if want_feed: return atom_feed(req, post=post) # create the comment form form = NewCommentForm(post, req.user) if post.comments_enabled or post.comments: add_link('alternate', post.comment_feed_url, 'application/atom+xml', _(u'Comments Feed')) # now dispatch to the correct view handler = req.app.content_type_handlers.get(post.content_type) if handler is None: log.warn('No handler for the content type %r found.' % post.content_type) raise NotFound() return handler(req, post, form)
def index(req, page=1): """Render the most recent posts. Available template variables: `posts`: a list of post objects we want to display `pagination`: a pagination object to render a pagination :Template name: ``index.html`` :URL endpoint: ``blog/index`` """ data = Post.query.theme_lightweight('index').published() \ .for_index().get_list(endpoint='blog/index', page=page) add_link('alternate', url_for('blog/atom_feed'), 'application/atom+xml', _(u'Recent Posts Feed')) return render_response('index.html', **data)
def archive(req, year=None, month=None, day=None, page=1): """Render the monthly archives. Available template variables: `posts`: a list of post objects we want to display `pagination`: a pagination object to render a pagination `year` / `month` / `day`: integers or None, useful to entitle the page :Template name: ``archive.html`` :URL endpoint: ``blog/archive`` """ if not year: return render_response( 'archive.html', month_list=True, **Post.query.published().for_index().get_archive_summary()) url_args = dict(year=year, month=month, day=day) per_page = req.app.theme.settings['archive.per_page'] data = Post.query.theme_lightweight('archive_overview') \ .published().for_index().date_filter(year, month, day) \ .get_list(page=page, endpoint='blog/archive', url_args=url_args, per_page=per_page) add_link('alternate', url_for('blog/atom_feed', **url_args), 'application/atom+xml', _(u'Recent Posts Feed')) return render_response('archive.html', year=year, month=month, day=day, date=date(year, month or 1, day or 1), month_list=False, **data)