Skip to content

Instantly share code, notes, and snippets.

@colinta
Created March 13, 2012 20:37
Show Gist options
  • Save colinta/2031404 to your computer and use it in GitHub Desktop.
Save colinta/2031404 to your computer and use it in GitHub Desktop.
@view_config(renderer='myapp:templates/blog_detail.j2')
@has_tag_cloud # ug, but I need that tag_cloud!
def blog_detail(request, blog_slug):
blog = fetch_blog(blog_slug)
return {}
@view_config(renderer='myapp:templates/tag_cloud.j2')
@has_tag_cloud # silly, since this *is* the tag cloud...
def tag_cloud(request, blog_slug):
# imagine this method is called via ajax a lot,
# to make the tag cloud spin or change or something...
return {}
def has_tag_cloud(function):
@wraps(function)
def wrapper(request, *args, **kwargs):
cloud = fetch_tag_cloud(blog_slug)
ret = function(request, *args, **kwargs)
ret['tag_cloud'] = cloud
return ret
{% extends "layouts/base.j2" %}
{% block content %}
<h1>{{ blog.title }}</h1>
{{ blog.html }}
{% endblock %}
{% block callouts %}
{{ super() }}
{# ajax or not, we can insert the tag_cloud into the DOM here: #}
{% view 'tag_cloud' %}
{% endblock %}
@view_config(renderer='myapp:templates/blog_detail.j2')
def blog_detail(request, blog_slug):
blog = fetch_blog(blog_slug)
return {}
@view_config(renderer='myapp:templates/tag_cloud.j2')
def tag_cloud(request, blog_slug):
# could be an ajax request, either way...
cloud = fetch_tag_cloud(blog_slug)
return {'tag_cloud': cloud}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment