On Jul 10, 6:32 pm, alex23 <[EMAIL PROTECTED]> wrote: > The problems: > 1. The code works when _setting_ .skills, but won't display which ones > are already present in the list during the initial form render. > 2. I put traces on CoerceSkill's to/from_python functions, and for > some reason, it's to_python is called _immediately after_ the > from_python during the initial form render. > 3. If I comment out the CoerceSkill validator's 'to_python' function, > it will _display_ the correct skills but doesn't set them (the > opposite of #1).
Okay, after reading http://groups.google.com/group/turbogears/browse_thread/thread/ee62cdd368a83ebc I think I have a solution. Firstly, I changed the options-filling callback to: def opt_skills(): return [(s, s.name) for s in Skill.select()] Next, I added a __str__ to Skill that returned its ID. And now it seems to work. It looks like convert=True also takes care of converting the options list items. With the __str__ solution, I lose the ability to have Skill instances render as their name when displayed, but that I can work-around. I can remove the __str__ and change CoerceSkill to: def _to_python(self, value, state): try: id = int(value) params = dict(id=id) except: params = dict(name=value) return Skill.get_by(**params) Is this the worst kind of kludge? It still feels incredibly awkward to do what I had expected would be a fairly standard form pattern... > 4. If I attach the skills ForEach validator to the schema, I get > completely different behaviour (I had expected them to be identical). > It tracebacks with "Please enter an integer value" > > class StaffSchema(Schema): > team_id = IndexValidator() > skills = ForEach( > CoerceSkill(), > convertToList=True, > ) I still haven't worked out why this is the case, though.... - alex23 --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---

