[Zope-CMF] [dev] working on the trunk

yuppie y.2011 at wcm-solutions.de
Thu Sep 29 03:39:04 EST 2011


Hi Charlie!


Charlie Clark wrote:
> Am 27.01.2011, 17:05 Uhr, schrieb yuppie<y.2011 at wcm-solutions.de>:
>
>> zope.formlib is not made for DateTime values and encoded strings. So you
>> *always* have to make sure these values are converted correctly. And it
>> is hard to do that inside the form code. Obviously you did have trouble
>> to get it right that way. After I started using adapters for the edited
>> objects I had much less trouble using formlib. Of course you don't need
>> an adapter if your objects already provide the right interface.
>
>> And one more benefit: Inside the form code you can completely ignore the
>> old-fashioned implementation of the edited objects and write nice modern
>> code.
>
> Finally have made the time to look at this. I've written a schema adapter
> for the forms and it looks like SettingsEditForm handles the conversion to
> Zope's DateTime nicely. Now, I'm stuck with the problem of getting my view
> unit tests to work. Looks like I need a few adapters registered. :-/

SettingsEditFormBase has a getContent() method similar to that in 
z3c.form. This allows a clean distinction between 'content' and 
'context'. For content objects they are usually the same, but in your 
case the site root is the context and the (adapted) SyndicationTool is 
the edited "content".

Please have a look at the membership views. They show how to use 
getContent(). In your case the method would look like this:

     @memoize
     def getContent(self):
         syndtool = getUtility(ISyndicationTool)
         return SyndicationToolSchemaAdapter(syndtool)

This example uses a hardcoded adapter. You can still register it and 
look it up, but I guess that's overkill. I doubt anybody wants to use a 
customized adapter. And if it is hardcoded, you don't need to register 
it for testing ;)


Cheers,

	Yuppie


More information about the Zope-CMF mailing list