I am trying to write a crud controller base class that does the following:
class BaseCrudController:
model = ""
field_validation = {}
template_dir = ""
@expose(self.template_dir)
def new(self, *args, **kwargs)
....
@validate(self.field_validation, error_handler=new)
@expose()
def post(self, *args, **kwargs):
...
My intention is for my controllers to extend this base class, set model, field_validation and template locations, and I'm ready to go.
Unfortunately, decorators (as far as I know) are interpreted when a function is defined. Consequently, he will not have access to cost. Is there a way to pass dynamic data or values from a subclass to a class?
For instance:
class AddressController(BaseCrudController):
model = Address
template_dir = "addressbook.templates.addresses"
When I try to load the AddressController, it says, "I am not defined." I assume the base class evaluates the decorator before initializing the subclass.
Thanks Steve
steve source
share