I'm trying to refactor a controller that adds objects to the database,
following the DRY (Don't Repeat Yourself) principle. I've got:
class Add(controllers.Root):
...
@validate(form=ThisTypeForm)
def saveThisTypeOfElement:
# do what's needed to save an object of ThisType in the
database
@validate(form=ThatTypeForm)
def saveThatTypeOfElement:
# do what's needed to save an object of ThatType in the
database
It turns out that the method bodies can be the same; the only
difference is the form--the two objects have different attributes,
validation requirements etc. I want something like:
class Add(controllers.Root):
...
@validate(form=???)
def saveElement(type):
# do what's needed to save an object of type 'type'
You see my dilemma: the decorator needs to know which form to associate
with the method, but that depends on the method's 'type' argument. I
can't, for example, call a function:
@validate(form=getForm('type'))
since 'type' is not defined when the decorator is applied. I can't use
a callable:
@validate(form=getForm)
because the callable really needs a 'type' argument to get passed at
runtime.
Am I just completely missing the point here? Surely there's a way to
associate the correct form with my method at runtime?
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---