Created
April 16, 2012 04:03
-
-
Save ianjosephwilson/2396292 to your computer and use it in GitHub Desktop.
Pyramid route factory for a blog post.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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