[Zope-CMF] Re: [dev] newstyle content creation
Charlie Clark
charlie at begeistert.org
Tue May 20 04:50:31 EDT 2008
Am 19.05.2008 um 18:51 schrieb Charlie Clark:
> That's probably the easiest solution at the moment although it would
> be nice to be able to declare this in the schema. I suppose two
> different interfaces à la IObject and IMutableObject provide a way.
> I find fiddling with the form fields too easy to mess up! I think
> the only thing that's missing from this is a nicer way of getting
> the portal_type. As this is configurable in the ZMI and perfectly
> possible to have several types deriving from the same class and,
> therefore, from the same interface. Although as with browser views
> this should no longer be possible. I can't see an easy way of doing
> this but it seems to me much more natural to do this in the
> interface rather than in the view as it's essentially declarative
> work. Maybe a dedicated schema field for CMF Types and associated
> hidden widget?
>
> portal_type = CMFDefault.schema.ContentType(title=u"portal type")
Obviously that won't work but it seems it should be possible to add
the portal_type logic to the base form as this should be true for all
add forms for CMF objects, shouldn't it?
in ContentAddFormBase
def setUpWidgets(self, ignore_request=False):
super(ContentAddFormBase,
self).setUpWidgets(ignore_request=ignore_request)
self.widgets['portal_type'].hide = True
def form_fields(self):
fields = form.FormFields(
TextLine(
__name__='portal_type',
default=self.portal_type)
)
return fields
add forms now simply need to define their portal_type and extend the
fields:
portal_type = u"Textbody"
@property
def form_fields(self):
fields = (super(TextAdd, self).form_fields() +
form.FormFields(ITextbody))
return fields
I'm not sure if it's good style to do this using properties but it
seems to work for and I find it less of a source of copy and paste
errors.
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