[Zope-CMF] CMF 2.2.0-beta reminder

Charlie Clark charlie at begeistert.org
Wed Dec 2 09:31:07 EST 2009


Am 01.12.2009, 07:52 Uhr, schrieb Jens Vagelpohl <jens at dataflake.org>:

> Reminder: After this week (probably this coming Sunday) I plan on doing  
> the first CMF 2.2 beta, and creating the 2.2 release branch.

My CSS stuff won't make it into the beta. I would like to contribute some  
documentation on Yuppie's new add views but also continue the discussion.

As things currently stand Yuppie has implemented some very flexible add  
views that are almost entirely type definition-based. If a type definition  
has something in the new add view URL field then it will automatically be  
picked up for folder actions:

atool = getToolByName(self.context, 'portal_actions')
actions = atool.listFilteredActionsFor(self.context)
return actions.get("folder/add", {})

A really nice thing is support for schemaless, default add views that only  
require this URL of the form

string:${folder_url}/++add++Document

This will get you a form with just a single field for the id.

Dedicated schema-based add views are trivial to add:

 from zope.formlib import form
 from Products.CMFDefault.formlib.form import ContentAddFormBase
 from MyApp.interfaces import IMyContentType

class MyAddView(ContentAddFormBase):
	form_fields = form.FormFields(IMyContentType)

May be all you need.

Otherwise there are examples for CMF Link and CMF Favourite.

We have a use case where we need the object creation without any kind of  
fields (id's are automatically assigned) and this is easy to implement

     def __call__(self):
         self.createAndAdd({})

You need to remember to return a new view or a redirect from the call  
which in this case is likely to be something other than an object's inital  
view. For example, returning  
self.request.response.redirect(self.request.HTTP_REFERER) lets you create  
lots of objects in a folder one after the other.	

Hooking everything together is, however, a bit clunky:

     <adapter
         name="myproduct.content_type_factory"
         factory=".myproduct.MyAddView"
         />

     <class class=".myproduct.MyAddView">
       <require
           permission="cmf.AddPortalContent"
           interface="zope.formlib.interfaces.IPageForm"
           />
     </class>

For the sake of clarity it would be nice to have a directive that ties  
this together. Particularly the juxtaposition of the adapter name (which  
has to be the same as the named content type factory utility) and the view  
acting as a factory is a definite possible source of confusion. And, while  
I much prefer the security declaration outside of the view class, the  
combination is a bit unintuitive.

I would find something like:

<cmf:addView
	factory="myproduct.content_type_factory"
	class=".myproduct.MyAddView"
	permission="cmf.AddPortalContent"
	required-inteface="zope.formlib.interfaces.IPageForm"
/>

easier to work with.

I'm also not sure if the add view URL couldn't be simpler because the  
++add++ContentTypeId is a must, why this can't be interpolated either on  
type registration or in the add_action look-up. Is there any reason why  
this couldn't or shouldn't be the case?

***

Having finally taken the plunge into buildout I've been able to upgrade  
one of our projects onto Zope 2.12 and CMF 2.2 with no real problems just  
the odd "surprise". Thank you all very much for your help with Zope + CMF!

Charlie
-- 
Charlie Clark
Helmholtzstr. 20
Düsseldorf
D- 40215
Tel: +49-211-938-5360
GSM: +49-178-782-6226


More information about the Zope-CMF mailing list