Skip to content

Instantly share code, notes, and snippets.

@bennihepp
Created February 4, 2012 14:46
Show Gist options
  • Save bennihepp/1738249 to your computer and use it in GitHub Desktop.
Save bennihepp/1738249 to your computer and use it in GitHub Desktop.
Proposal for a new decorator in pyramid or an extension
from pyramid_view_controller import view_controller
from ..models import Building, House, Factory, Skyscraper
class AbstractController(object):
# will not become a view because the class has no @view_controller decorator
@view_controller(name='view')
def view(self):
...
return response
# the view method in AbstractController will now become a view within
# BuildingController because it is decorated with @view_controller, but
# it will also inherit the predicates from the class @view_controller, so
# it will only be a view for Building resources.
@view_controller(context=Building)
class BuildingController(AbstractController):
def __init__(self, request):
self.request = request
...
# do some setup for all methods
def cleanup
# do some cleanup for all methods
# this method will be the view for Factory resources
@view_controller(context=Factory)
def view_factory(self):
...
return response
@view_controller(name='edit')
def edit(self):
...
return response
# here the view method overwrites the method from the base class and will
# be called for Skyscraper resources
@view_controller(context=Skyscraper)
class SkyscraperController(BuildingController):
@view_controller()
def view(self)
...
return response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment