Did you find a solution to this?
I think it could be posible thanks to formencode(http://formencode.org/Validator.html):
You could create a validator and use it side efect, conversion, to save you object in session.
so you should define something like:
import formencode
import cherrypy
class SaveRestoreObject(fromencode.FancyValidator):
def _to_python(self, value, state):
if not has_key(cherrypy.session , value):
raise formencode.Invalid("Object not found", value, state)
return cherrypy.session[value]
def _from_python(self, value, state):
cherrypy.session["publish_object"]=value
return "publish_object"
and use this a validator in the form and, don't forget to put the formin the @validate() of def save(). So you have:
class myFormSchema(formencode.Schema):
...
myObject=SaveRestoreObject()
....
def createMyForm():
field1= widgets.HiddenField("myObject")
...
form = widgets.TableForm(fields=[field1,..], validator=myFormSchema)
and use it to define your controller as showed in:
http://trac.turbogears.org/turbogears/wiki/FormValidationWithWidgetsTwo
Well for the second step applying the changes from the form to the object saved in the session, I have it not well defined, I'm thinking on a chained_validator, I'll give it a try sometime from now.
I hope this would help on something.
Regards.
On 4/11/06, Yannick <[EMAIL PROTECTED]> wrote:
Thank you all for your suggestions!
I am afraid that it wouldn't fully answer my problem though...
Should I encode this object in a hidden field, or a session dict on the
server, then the object's parameter won't be updated by the user.
.i.e. In my kid template I want:
<form action=""
Modify Bar: <input name="publish_object.bar"
value="${publish_object.bar}" />
</form>
And then in my save method, I want to be able to retrieve the value
that the user submitted (without having to type all the form's input
fields one by one in the method signature, but just the
publish_object):
turbogears.expose("mytemplate2")
def save(self, publish_object):
print "value is: %d" % publish_object.bar
return dict()
Thanks,
Yannick
--
Julio
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

