def render_tags(title, tags): if tags: counts = [tag['count'] for tag in tags] mincount, maxcount = min(counts), max(counts) for tag in tags: if maxcount > mincount: tag['size'] = (MIN_TAG_SIZE + (MAX_TAG_SIZE - MIN_TAG_SIZE) * (tag['count'] - mincount) / (maxcount - mincount)) else: tag['size'] = MIN_TAG_SIZE return util.render_themed('tags.jinja2', tags=tags, title=title, max_tag_size=MAX_TAG_SIZE)
def render_posts(title, posts, older, events=None, template='posts.jinja2'): atom_args = request.view_args.copy() atom_args.update({'feed': 'atom', '_external': True}) atom_url = url_for(request.endpoint, **atom_args) atom_title = title or 'Stream' rv = make_response( util.render_themed(template, posts=posts, title=title, older=older, atom_url=atom_url, atom_title=atom_title, events=events)) last_modified = max((p.updated for p in posts if p.updated), default=None) if last_modified: rv.headers['Last-Modified'] = http_date(last_modified) rv.headers['Etag'] = generate_etag(rv.get_data()) rv.make_conditional(request) return rv
def render_post(post): if not post: abort(404) if post.deleted: abort(410) # deleted permanently if not check_audience(post): abort(401) # not authorized TODO a nicer page if post.redirect: return redirect(post.redirect) rv = make_response( util.render_themed('post.jinja2', post=post, title=post.title_or_fallback)) if post.updated: rv.headers['Last-Modified'] = http_date(post.updated) rv.headers['Etag'] = generate_etag(rv.get_data()) rv.make_conditional(request) return rv