Hi,
I am trying to write a base crud controller 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 intent is to have my controllers extend this base class, set the model, field_validation, and template locations, and am ready to go.
Unfortunately, decorators (to my understanding), are interpreted when the function is defined. Hence it won't have access to instance's value. Is there a way to pass in dynamic data or values from the sub class?
For example:
class AddressController(BaseCrudController):
model = Address
template_dir = "addressbook.templates.addresses"
When I try to load AddressController, it says "self is not defined". I am assuming that the base class is evaluating the decorator before the sub class is initialized.
Thanks, Steve