I'm trying to be too clever with my python again.  Maybe someone
will see an easier way to do this.

I've got a set of DB classes with very similar structure, and I
want to write a single CRUD controller that will handle them
all.  The only things that need to be different for the different
classes are (1) the db class, (2) the display/edit forms, and
(3) a display text label.  (1) and (3) are easy, but (2) is
giving me some trouble, because the "normal" pattern is to
reference the form in an @validate decorator.

What I'm trying to do is something like:

     class CRUD(Controller):

         def __init__(self, dbclass, form, label):
             ....
             self.__class__.save = 
expose()(validate(form=self.editform)(error_handler(self.__class__.edit)(self.__class__.save)))

         @expose(.templates.editform)
         def edit(self, id, tg_errors=None, **formdata):
             ....
             formdata = dbclass.get(id)
             ....
             return dict(form=self.editform, formdata=formdata, 
label=self.label)

         def save(self, id, label=None):
             ....

     class AccountsController(CRUD): pass
     class EntriesController(CRUD): pass


     class Root(RootController):

         accounts = Accounts(Account, accountform, 'Account')
         entries = EntriesController(Entry, entryform, 'Entry')


The overly tricky bit should be obvious, in the init method.  This works
great except for the fact that the error_handler isn't getting recognized.
When there's a validation error I get the following traceback:

      File 
"/var/www/finance.bitdance.com/moneytracker/lib/python2.4/TurboGears-1.0.1-py2.4.egg/turbogears/errorhandling.py",
        line 110, in run_with_errors raise NotImplementedError("Method %s.%s() 
has no applicable "
    NotImplementedError: Method FlowTypeController.add() has no applicable 
error handler.

I presume I can work around this by defining the save method in the
subclass and decorating it, but I hate to have to write the redundant
code :).  Is there some way to set the error handler (and the
validator, for that matter) other than the decorator?

--David

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to