Skip to content

Instantly share code, notes, and snippets.

@ianjosephwilson
Created April 16, 2012 04:03
Show Gist options
  • Save ianjosephwilson/2396292 to your computer and use it in GitHub Desktop.
Save ianjosephwilson/2396292 to your computer and use it in GitHub Desktop.
Pyramid route factory for a blog post.
class Post(object):
#...
@classmethod
def factory(cls, request):
if 'post_id' in request.matchdict:
post = cls.from_identifier(request.matchdict['post_id'])
if not post or not post.is_published():
raise NotFound()
if 'post_slug' in request.matchdict and \
post.slug != request.matchdict['post_slug']:
raise HTTPMovedPermanently(
location=request.route_url('blog-post',
post=post))
return post
else:
return None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment