how to pass in dynamic data to decorators

Posted by steve on Stack Overflow See other posts from Stack Overflow or by steve
Published on 2010-05-21T18:58:02Z Indexed on 2010/05/21 19:00 UTC
Read the original article Hit count: 268

Filed under:
|

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?

If not, I guess I could use override_template as a workaround to expose and set the template within the controller action. How would I go about validating the form within the controller action?

Thanks, Steve

© Stack Overflow or respective owner

Related posts about python

Related posts about decorator