Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Zope: CMF

[dev] newstyle content creation

 

 

First page Previous page 1 2 Next page Last page  View All Zope cmf RSS feed   Index | Next | Previous | View Threaded


y.2008 at wcm-solutions

Apr 22, 2008, 5:27 AM

Post #1 of 26 (1031 views)
Permalink
[dev] newstyle content creation

Hi!


Implementing newstyle content factories[1] and using events for content
creation[2] made it much easier to create content without using
invokeFactory and friends.

These steps are still necessary:

- check portal_type exists (*)
- check allowType(portal_type) for the container (*)
- get factory name for portal_type (*)
- get IFactory utility for the factory name
- use factory for creating an object
- set object's portal_type (*)
- set other object attributes if necessary
- send ObjectCreatedEvent
- add the object to the container using _setObject

The steps marked with (*) are CMF specific.


Today I checked in a formlib based add view for File objects[3]. There
is a new "Add File" action available if you use the "Experimental
CMFDefault Browser Views" extension profile.

Any feedback is welcome. Not sure if this makes Bug #161664[4] obsolete.


Cheers,

Yuppie



[1] http://mail.zope.org/pipermail/zope-cmf/2006-May/024464.html
[2] http://mail.zope.org/pipermail/zope-cmf/2007-December/027000.html
[3] http://svn.zope.org/?rev=85591&view=rev
[4] https://bugs.launchpad.net/zope-cmf/+bug/161664

_______________________________________________
Zope-CMF maillist - Zope-CMF[at]lists.zope.org
http://mail.zope.org/mailman/listinfo/zope-cmf

See http://collector.zope.org/CMF for bug reports and feature requests


charlie at begeistert

Apr 22, 2008, 6:54 AM

Post #2 of 26 (1005 views)
Permalink
Re: [dev] newstyle content creation [In reply to]

Am 22.04.2008 um 14:27 schrieb yuppie:

> Hi!
>
>
> Implementing newstyle content factories[1] and using events for
> content creation[2] made it much easier to create content without
> using invokeFactory and friends.
>
> These steps are still necessary:
>
> - check portal_type exists (*)
> - check allowType(portal_type) for the container (*)
> - get factory name for portal_type (*)
> - get IFactory utility for the factory name
> - use factory for creating an object
> - set object's portal_type (*)
> - set other object attributes if necessary
> - send ObjectCreatedEvent
> - add the object to the container using _setObject
>
> The steps marked with (*) are CMF specific.
>
>
> Today I checked in a formlib based add view for File objects[3].
> There is a new "Add File" action available if you use the
> "Experimental CMFDefault Browser Views" extension profile.
>
> Any feedback is welcome. Not sure if this makes Bug #161664[4]
> obsolete.


This is excellent news! I have been struggling considerably with
invokeFactory() on a recent project.

Does this mean we can develop add_forms analogue to Zope 3? And do I
get the goodies just with an svn update?

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



_______________________________________________
Zope-CMF maillist - Zope-CMF[at]lists.zope.org
http://mail.zope.org/mailman/listinfo/zope-cmf

See http://collector.zope.org/CMF for bug reports and feature requests


y.2008 at wcm-solutions

Apr 22, 2008, 8:24 AM

Post #3 of 26 (1005 views)
Permalink
Re: [dev] newstyle content creation [In reply to]

Charlie Clark wrote:
> Am 22.04.2008 um 14:27 schrieb yuppie:
>> Today I checked in a formlib based add view for File objects[3]. There
>> is a new "Add File" action available if you use the "Experimental
>> CMFDefault Browser Views" extension profile.
>>
>> Any feedback is welcome. Not sure if this makes Bug #161664[4] obsolete.
>
>
> This is excellent news! I have been struggling considerably with
> invokeFactory() on a recent project.
>
> Does this mean we can develop add_forms analogue to Zope 3?

Yes. Similar code as used for creating File objects should work for any
content. But ContentAddFormBase is new and not very well tested, so you
might find some bugs.

Note that the add view is registered for the container interface, not
IAdding. zope.formlib still uses IAdding by default, but z3c.form doesn't.

> And do I get the goodies just with an svn update?

Yes. Missing is the integration in the CMFDefault add menu. For now the
new 'add_file' action is used for showing the link to 'addFile.html'.

Cheers, Yuppie

_______________________________________________
Zope-CMF maillist - Zope-CMF[at]lists.zope.org
http://mail.zope.org/mailman/listinfo/zope-cmf

See http://collector.zope.org/CMF for bug reports and feature requests


optilude at gmx

Apr 22, 2008, 2:54 PM

Post #4 of 26 (1004 views)
Permalink
Re: [dev] newstyle content creation [In reply to]

Hi Yuppie,

> Implementing newstyle content factories[1] and using events for content
> creation[2] made it much easier to create content without using
> invokeFactory and friends.

Indeed!

> These steps are still necessary:
>
> - check portal_type exists (*)
> - check allowType(portal_type) for the container (*)
> - get factory name for portal_type (*)
> - get IFactory utility for the factory name
> - use factory for creating an object
> - set object's portal_type (*)
> - set other object attributes if necessary
> - send ObjectCreatedEvent
> - add the object to the container using _setObject
>
> The steps marked with (*) are CMF specific.

Yep.

> Today I checked in a formlib based add view for File objects[3].

Have you looked at z3c.form at all? There's a package called
plone.z3cform that provides Zope 2 integration for this (it shouldn't be
Plone specific beyond that). I'm only asking since people seem to be
going in this direction.

Martin


--
Author of `Professional Plone Development`, a book for developers who
want to work with Plone. See http://martinaspeli.net/plone-book

_______________________________________________
Zope-CMF maillist - Zope-CMF[at]lists.zope.org
http://mail.zope.org/mailman/listinfo/zope-cmf

See http://collector.zope.org/CMF for bug reports and feature requests


y.2008 at wcm-solutions

Apr 23, 2008, 12:41 AM

Post #5 of 26 (999 views)
Permalink
Re: [dev] newstyle content creation [In reply to]

Martin Aspeli wrote:
>> Today I checked in a formlib based add view for File objects[3].
>
> Have you looked at z3c.form at all? There's a package called
> plone.z3cform that provides Zope 2 integration for this (it shouldn't be
> Plone specific beyond that). I'm only asking since people seem to be
> going in this direction.

I know. These are the reasons why I chose zope.formlib:

- Zope 2 ships with zope.formlib, not with z3c.form

- zope.formlib is already used for CMF edit forms

- the work done for the zope.formlib based version is not lost if we
switch to z3c.form, converting the forms should be easy

The checked in add form borrows one pattern from z3c.form: It doesn't
depend on IAdding, the view is registered for the container.

Cheers, Yuppie

_______________________________________________
Zope-CMF maillist - Zope-CMF[at]lists.zope.org
http://mail.zope.org/mailman/listinfo/zope-cmf

See http://collector.zope.org/CMF for bug reports and feature requests


charlie at begeistert

Apr 23, 2008, 1:11 AM

Post #6 of 26 (999 views)
Permalink
Re: Re: [dev] newstyle content creation [In reply to]

Am 22.04.2008 um 23:54 schrieb Martin Aspeli:

> Have you looked at z3c.form at all? There's a package called
> plone.z3cform that provides Zope 2 integration for this (it
> shouldn't be Plone specific beyond that). I'm only asking since
> people seem to be going in this direction.


As Yuppie says a lot of work has already been done using formlib. And
while using the "latest and greatest" (yes, I know z3c.form has been
around for a while) might be desirable, I don't think there are enough
developers actively working on the CMF to keep pace. But from what I
understand of the packages - the migration to z3c.form from formlib
shouldn't be as demanding as moving to formlib in the first place but
it would make sense to complete the move to formlib first and
replacing the "add" view of Folders was probably the most demanding
bit of what's left.

Regarding plone.z3cform - doesn't the licence preclude inclusion
within the CMF?

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



_______________________________________________
Zope-CMF maillist - Zope-CMF[at]lists.zope.org
http://mail.zope.org/mailman/listinfo/zope-cmf

See http://collector.zope.org/CMF for bug reports and feature requests


charlie at begeistert

Apr 23, 2008, 1:18 AM

Post #7 of 26 (1000 views)
Permalink
Re: Re: [dev] newstyle content creation [In reply to]

Am 22.04.2008 um 17:24 schrieb yuppie:

> Yes. Missing is the integration in the CMFDefault add menu. For now
> the new 'add_file' action is used for showing the link to
> 'addFile.html'.


I hope to have some time for this (and a new table-free version of
main_template.pt) on Friday. Where exactly is the CMFDefault add menu?
Sorry, if the question is stupid but I didn't think we could use zope3
menu directives?

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



_______________________________________________
Zope-CMF maillist - Zope-CMF[at]lists.zope.org
http://mail.zope.org/mailman/listinfo/zope-cmf

See http://collector.zope.org/CMF for bug reports and feature requests


y.2008 at wcm-solutions

Apr 23, 2008, 2:12 AM

Post #8 of 26 (993 views)
Permalink
Re: [dev] newstyle content creation [In reply to]

Charlie Clark wrote:
>
> Am 22.04.2008 um 17:24 schrieb yuppie:
>
>> Yes. Missing is the integration in the CMFDefault add menu. For now
>> the new 'add_file' action is used for showing the link to 'addFile.html'.
>
> I hope to have some time for this (and a new table-free version of
> main_template.pt) on Friday. Where exactly is the CMFDefault add menu?
> Sorry, if the question is stupid but I didn't think we could use zope3
> menu directives?

Sorry for using misleading terms. I was referring to 'folder_factories'.

Cheers, Yuppie

_______________________________________________
Zope-CMF maillist - Zope-CMF[at]lists.zope.org
http://mail.zope.org/mailman/listinfo/zope-cmf

See http://collector.zope.org/CMF for bug reports and feature requests


charlie at begeistert

Apr 23, 2008, 2:22 AM

Post #9 of 26 (1000 views)
Permalink
Re: Re: [dev] newstyle content creation [In reply to]

Am 23.04.2008 um 11:12 schrieb yuppie:

> Charlie Clark wrote:
>> Am 22.04.2008 um 17:24 schrieb yuppie:
>>> Yes. Missing is the integration in the CMFDefault add menu. For
>>> now the new 'add_file' action is used for showing the link to
>>> 'addFile.html'.
>> I hope to have some time for this (and a new table-free version of
>> main_template.pt) on Friday. Where exactly is the CMFDefault add
>> menu? Sorry, if the question is stupid but I didn't think we could
>> use zope3 menu directives?
>
> Sorry for using misleading terms. I was referring to
> 'folder_factories'.


ah, so clicking on add brings up the tried and trusty page for adding
objects to folders? Only then do we get to the appropriate add_view?
Would it be a good idea to move this to a menu item like
object_actions? Got the code for this.

BTW. regarding formlib I've been bashing my head (checkout those
bruises!) for weeks on how to add a thumbnail of an existing image to
an edit form. Do I need to develop a special widget which will call
the appropriate method?

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



_______________________________________________
Zope-CMF maillist - Zope-CMF[at]lists.zope.org
http://mail.zope.org/mailman/listinfo/zope-cmf

See http://collector.zope.org/CMF for bug reports and feature requests


wichert at wiggy

Apr 23, 2008, 2:27 AM

Post #10 of 26 (984 views)
Permalink
Re: Re: [dev] newstyle content creation [In reply to]

Previously Charlie Clark wrote:
>
> Am 23.04.2008 um 11:12 schrieb yuppie:
>
> >Charlie Clark wrote:
> >>Am 22.04.2008 um 17:24 schrieb yuppie:
> >>>Yes. Missing is the integration in the CMFDefault add menu. For
> >>>now the new 'add_file' action is used for showing the link to
> >>>'addFile.html'.
> >>I hope to have some time for this (and a new table-free version of
> >>main_template.pt) on Friday. Where exactly is the CMFDefault add
> >>menu? Sorry, if the question is stupid but I didn't think we could
> >>use zope3 menu directives?
> >
> >Sorry for using misleading terms. I was referring to
> >'folder_factories'.
>
>
> ah, so clicking on add brings up the tried and trusty page for adding
> objects to folders? Only then do we get to the appropriate add_view?
> Would it be a good idea to move this to a menu item like
> object_actions? Got the code for this.
>
> BTW. regarding formlib I've been bashing my head (checkout those
> bruises!) for weeks on how to add a thumbnail of an existing image to
> an edit form. Do I need to develop a special widget which will call
> the appropriate method?

Perhaps collective.namedfile has a suitable widget.

Wichert.

--
Wichert Akkerman <wichert[at]wiggy.net> It is simple to make things.
http://www.wiggy.net/ It is hard to make things simple.
_______________________________________________
Zope-CMF maillist - Zope-CMF[at]lists.zope.org
http://mail.zope.org/mailman/listinfo/zope-cmf

See http://collector.zope.org/CMF for bug reports and feature requests


y.2008 at wcm-solutions

Apr 23, 2008, 6:10 AM

Post #11 of 26 (988 views)
Permalink
Re: [dev] newstyle content creation [In reply to]

Hi!


Charlie Clark wrote:
>
> Am 23.04.2008 um 11:12 schrieb yuppie:
>
>> Charlie Clark wrote:
>>> Am 22.04.2008 um 17:24 schrieb yuppie:
>>>> Yes. Missing is the integration in the CMFDefault add menu. For now
>>>> the new 'add_file' action is used for showing the link to
>>>> 'addFile.html'.
>>> I hope to have some time for this (and a new table-free version of
>>> main_template.pt) on Friday. Where exactly is the CMFDefault add
>>> menu? Sorry, if the question is stupid but I didn't think we could
>>> use zope3 menu directives?
>>
>> Sorry for using misleading terms. I was referring to 'folder_factories'.
>
>
> ah, so clicking on add brings up the tried and trusty page for adding
> objects to folders?

Yes.

> Only then do we get to the appropriate add_view?

No. As I said: That part is still missing. 'folder_factories' provides
the old add procedure, the new alternative for 'File' content is
available as action in the menu.

> Would it be a good idea to move this to a menu item like object_actions?
> Got the code for this.

Maybe. Does your code use the type infos or additional actions (attached
to the type infos or stored in the actions tool) to get the data? Do
your actions provide a way to specify the object id (as possible in
folder_factories) or how do you choose the ids?


Cheers,

Yuppie


_______________________________________________
Zope-CMF maillist - Zope-CMF[at]lists.zope.org
http://mail.zope.org/mailman/listinfo/zope-cmf

See http://collector.zope.org/CMF for bug reports and feature requests


charlie at begeistert

Apr 23, 2008, 6:36 AM

Post #12 of 26 (983 views)
Permalink
Re: Re: [dev] newstyle content creation [In reply to]

Am 23.04.2008 um 15:10 schrieb yuppie:

>> ah, so clicking on add brings up the tried and trusty page for
>> adding objects to folders?
>
> Yes.
>
>> Only then do we get to the appropriate add_view?
>
> No. As I said: That part is still missing. 'folder_factories'
> provides the old add procedure, the new alternative for 'File'
> content is available as action in the menu.

I'll check it out later then.

>> Would it be a good idea to move this to a menu item like
>> object_actions? Got the code for this.
>
> Maybe. Does your code use the type infos or additional actions
> (attached to the type infos or stored in the actions tool) to get
> the data? Do your actions provide a way to specify the object id (as
> possible in folder_factories) or how do you choose the ids?


Currently have a very basic vocabulary listing possible types. Have
been abusing invokeFactory to create my objects and autogenerate
content ids. For some reason couldn't get the redirect from the
TypeInfo so had to enforce the redirect manually. Would probably want
to extend this to redirect to an add form for the relevant object and
this is probably where I'll need the most help.

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



_______________________________________________
Zope-CMF maillist - Zope-CMF[at]lists.zope.org
http://mail.zope.org/mailman/listinfo/zope-cmf

See http://collector.zope.org/CMF for bug reports and feature requests


charlie at begeistert

Apr 23, 2008, 8:46 AM

Post #13 of 26 (982 views)
Permalink
Re: Re: [dev] newstyle content creation [In reply to]

Am 23.04.2008 um 15:10 schrieb yuppie:

> No. As I said: That part is still missing. 'folder_factories'
> provides the old add procedure, the new alternative for 'File'
> content is available as action in the menu.
>
>> Would it be a good idea to move this to a menu item like
>> object_actions? Got the code for this.
>
> Maybe. Does your code use the type infos or additional actions
> (attached to the type infos or stored in the actions tool) to get
> the data? Do your actions provide a way to specify the object id (as
> possible in folder_factories) or how do you choose the ids?


Okay. Had a quick look your implementation and I think I understand
it! 8-)
Had trouble with createAndAdd and finishCreate but now I understand
them. Shouldn't there be default finishCreate in the
ContentAddFormBase so that it's obvious we have to overwrite it? It's
taken me such a while to get my head around the ProxyFieldProperty
stuff that I've made all my new content stuff work without it but I
can see you've used it elegantly. I also understand what you mean
about making a menu for this stuff. It would be nice to have some
configuration for this so that we don't have to rely on actions such
as AddFile, AddImage, etc. Would that be something like listing all
views that provide a specific interface?

BTW. got bitten by the five.localsitemanager dependency with my 2.10
install. I've just reread the posts on this and I didn't quite
understand them. Things worked fine, of course, when I dropped CMFCore/
src/five into my lib/python folder but I'm guessing this is something
that's going to be phased out and that we're expecting users to be
able to install the package separately themselves. Is this assumption
correct?

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



_______________________________________________
Zope-CMF maillist - Zope-CMF[at]lists.zope.org
http://mail.zope.org/mailman/listinfo/zope-cmf

See http://collector.zope.org/CMF for bug reports and feature requests


jens at dataflake

Apr 23, 2008, 8:57 AM

Post #14 of 26 (981 views)
Permalink
Re: Re: [dev] newstyle content creation [In reply to]

On Apr 23, 2008, at 17:46 , Charlie Clark wrote:
> BTW. got bitten by the five.localsitemanager dependency with my 2.10
> install. I've just reread the posts on this and I didn't quite
> understand them. Things worked fine, of course, when I dropped
> CMFCore/src/five into my lib/python folder but I'm guessing this is
> something that's going to be phased out and that we're expecting
> users to be able to install the package separately themselves. Is
> this assumption correct?

This is correct. If I remember correctly you can just easy_install it.
You can also get it from SVN and link it into your instance's lib/
python folder.

jens



_______________________________________________
Zope-CMF maillist - Zope-CMF[at]lists.zope.org
http://mail.zope.org/mailman/listinfo/zope-cmf

See http://collector.zope.org/CMF for bug reports and feature requests


y.2008 at wcm-solutions

Apr 25, 2008, 12:23 AM

Post #15 of 26 (971 views)
Permalink
Re: [dev] newstyle content creation [In reply to]

Hi!


Charlie Clark wrote:
> Okay. Had a quick look your implementation and I think I understand it! 8-)
> Had trouble with createAndAdd and finishCreate but now I understand
> them. Shouldn't there be default finishCreate in the ContentAddFormBase
> so that it's obvious we have to overwrite it?

I simplified the code in ContentAddFormBase.create and moved it to the
add view. 'finishCreate' no longer exists, your add view has to
implement the complete 'create' method. Formlib raises an
NotImplementedError if 'create' is missing.

This requires a few more lines of code in add views for real
IDynamicType content. If you hardcode factory and portal_type in the
view, the code becomes much simpler. And if the __init__ method of your
content type handles unicode and datetime correctly, 'create' can be a
single line.

> It's taken me such a while
> to get my head around the ProxyFieldProperty stuff that I've made all my
> new content stuff work without it but I can see you've used it
> elegantly.

You should not use that stuff if you don't need it. Schema adapters and
ProxyFieldProperty are just legacy code for old content types.

> I also understand what you mean about making a menu for this
> stuff. It would be nice to have some configuration for this so that we
> don't have to rely on actions such as AddFile, AddImage, etc. Would that
> be something like listing all views that provide a specific interface?

No. The view registrations don't provide enough information and I'd like
to keep this configurable TTW.

We can look up the addable types in the types tool as folder_factories
and Plone do. But in that case we need a way to get the URL of the add
view.


Cheers,

Yuppie

_______________________________________________
Zope-CMF maillist - Zope-CMF[at]lists.zope.org
http://mail.zope.org/mailman/listinfo/zope-cmf

See http://collector.zope.org/CMF for bug reports and feature requests


charlie at begeistert

Apr 25, 2008, 9:55 AM

Post #16 of 26 (966 views)
Permalink
Re: Re: [dev] newstyle content creation [In reply to]

Am 23.04.2008 um 11:27 schrieb Wichert Akkerman:

>>
>> BTW. regarding formlib I've been bashing my head (checkout those
>> bruises!) for weeks on how to add a thumbnail of an existing image to
>> an edit form. Do I need to develop a special widget which will call
>> the appropriate method?
>
> Perhaps collective.namedfile has a suitable widget.


Couldn't find anything but I've come up with something that works in
the meantime. I suspect this is fundamentally wrong but it's the best
I can up with

<img tal:attributes="src string:${context/context/absolute_url}" />

Is this okay or am I likely to get bitten by aquisition or something
equally nasty?!

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



_______________________________________________
Zope-CMF maillist - Zope-CMF[at]lists.zope.org
http://mail.zope.org/mailman/listinfo/zope-cmf

See http://collector.zope.org/CMF for bug reports and feature requests


charlie at begeistert

Apr 25, 2008, 10:23 AM

Post #17 of 26 (965 views)
Permalink
Re: Re: [dev] newstyle content creation [In reply to]

Am 25.04.2008 um 09:23 schrieb yuppie:

> I simplified the code in ContentAddFormBase.create and moved it to
> the add view. 'finishCreate' no longer exists, your add view has to
> implement the complete 'create' method. Formlib raises an
> NotImplementedError if 'create' is missing.
>
> This requires a few more lines of code in add views for real
> IDynamicType content. If you hardcode factory and portal_type in the
> view, the code becomes much simpler. And if the __init__ method of
> your content type handles unicode and datetime correctly, 'create'
> can be a single line.

Agreed. The first five lines are generic and should probably be in
ContentAddFormBase leaving just the adapter stuff to be implemented by
the view itself which is what is was before! _create would be more in
keeping with other formlib methods such as handle_success calling
_handle_success.

>> It's taken me such a while to get my head around the
>> ProxyFieldProperty stuff that I've made all my new content stuff
>> work without it but I can see you've used it elegantly.
>
> You should not use that stuff if you don't need it. Schema adapters
> and ProxyFieldProperty are just legacy code for old content types.

I know. But I didn't know at the time and boy did it make me think
that things were going to be harder than they needed! I had to take
some time out at the time and curse the nameless people who hadn't
written the dummies guide to this! Still, it wasn't a bad idea making
me think more about this stuff.

Regarding naming: I suppose the easiest thing is to add an "id" field
to the add form for none file objects. It would be nice to have a
"require once" in the schema value for things like upload fields so
that the same schema can be used for adding and editing.

This does, of course, beg the question: when we've moved everything to
browser_views do we start thinking about moving the default classes to
zope.app based stuff? Or do we still depend too heavily on the Zope2
security declarations and other stuff?

>> I also understand what you mean about making a menu for this stuff.
>> It would be nice to have some configuration for this so that we
>> don't have to rely on actions such as AddFile, AddImage, etc. Would
>> that be something like listing all views that provide a specific
>> interface?
>
> No. The view registrations don't provide enough information and I'd
> like to keep this configurable TTW.
>
> We can look up the addable types in the types tool as
> folder_factories and Plone do. But in that case we need a way to get
> the URL of the add view.


The lookup is pretty much what I do at the moment. I can't think of an
easy way of doing this apart from convention which is pretty much what
you suggest with "addFile". I suppose the next thing would be to add
support for the '+' syntax and addMenuItem directive?

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



_______________________________________________
Zope-CMF maillist - Zope-CMF[at]lists.zope.org
http://mail.zope.org/mailman/listinfo/zope-cmf

See http://collector.zope.org/CMF for bug reports and feature requests


charlie at begeistert

Apr 28, 2008, 5:12 AM

Post #18 of 26 (924 views)
Permalink
Re: Re: [dev] newstyle content creation [In reply to]

Am 25.04.2008 um 19:23 schrieb Charlie Clark:

> Agreed. The first five lines are generic and should probably be in
> ContentAddFormBase leaving just the adapter stuff to be implemented
> by the view itself which is what is was before! _create would be
> more in keeping with other formlib methods such as handle_success
> calling _handle_success.

I've been successfully able to implement my own add Views for some of
my own objects and it definitely makes sense to have let
contentAddView do the work. For my objects I don't seem to need
anything specific in the view so always implementing a method such has
_create or maybe _handle_add doesn't make sense. Maybe a lookup to see
if such a method is implemented for adapting any additional adaptation?

if hasattr(self, "adapt_form_to_object"):
self.adapt_form_to_object

> Regarding naming: I suppose the easiest thing is to add an "id"
> field to the add form for none file objects. It would be nice to
> have a "require once" in the schema value for things like upload
> fields so that the same schema can be used for adding and editing.


Ha, should have looked more closely at the code! You're automatically
generating names as required. Maybe the lookup should also cope with
forms where an id is supplied just as you've done with filenames?

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



_______________________________________________
Zope-CMF maillist - Zope-CMF[at]lists.zope.org
http://mail.zope.org/mailman/listinfo/zope-cmf

See http://collector.zope.org/CMF for bug reports and feature requests


y.2008 at wcm-solutions

May 2, 2008, 4:50 AM

Post #19 of 26 (877 views)
Permalink
Re: [dev] newstyle content creation [In reply to]

Hi Charlie!


Charlie Clark wrote:
>
> Am 25.04.2008 um 09:23 schrieb yuppie:
>
>> I simplified the code in ContentAddFormBase.create and moved it to the
>> add view. 'finishCreate' no longer exists, your add view has to
>> implement the complete 'create' method. Formlib raises an
>> NotImplementedError if 'create' is missing.
>>
>> This requires a few more lines of code in add views for real
>> IDynamicType content. If you hardcode factory and portal_type in the
>> view, the code becomes much simpler. And if the __init__ method of
>> your content type handles unicode and datetime correctly, 'create' can
>> be a single line.
>
> Agreed. The first five lines are generic and should probably be in
> ContentAddFormBase leaving just the adapter stuff to be implemented by
> the view itself which is what is was before! _create would be more in
> keeping with other formlib methods such as handle_success calling
> _handle_success.

Did some more refactoring. If your factory can handle all the input,
ContentAddFormBase's 'create' method should be sufficient. If not, you
need a 'create' method like the one in FileAddView.

>>> It's taken me such a while to get my head around the
>>> ProxyFieldProperty stuff that I've made all my new content stuff work
>>> without it but I can see you've used it elegantly.
>>
>> You should not use that stuff if you don't need it. Schema adapters
>> and ProxyFieldProperty are just legacy code for old content types.
>
> I know. But I didn't know at the time and boy did it make me think that
> things were going to be harder than they needed! I had to take some time
> out at the time and curse the nameless people who hadn't written the
> dummies guide to this! Still, it wasn't a bad idea making me think more
> about this stuff.

Sorry. Added a small explanation in the module docstring.

> Regarding naming: I suppose the easiest thing is to add an "id" field to
> the add form for none file objects.

That's an option if you don't want automatically generated IDs. My
question was how to integrate oldstyle factories that don't have an add
form into an add menu.

> It would be nice to have a "require
> once" in the schema value for things like upload fields so that the same
> schema can be used for adding and editing.

In my own code I use some modified widgets that support
self.widgets['foo'].required=True to override required=False of the field.

> This does, of course, beg the question: when we've moved everything to
> browser_views do we start thinking about moving the default classes to
> zope.app based stuff? Or do we still depend too heavily on the Zope2
> security declarations and other stuff?

First priority for existing content classes is backwards compatibility.
I prefer to keep them as they are and to use adapters to make them work
with Zope3 style code.

>>> I also understand what you mean about making a menu for this stuff.
>>> It would be nice to have some configuration for this so that we don't
>>> have to rely on actions such as AddFile, AddImage, etc. Would that be
>>> something like listing all views that provide a specific interface?
>>
>> No. The view registrations don't provide enough information and I'd
>> like to keep this configurable TTW.
>>
>> We can look up the addable types in the types tool as folder_factories
>> and Plone do. But in that case we need a way to get the URL of the add
>> view.
>
>
> The lookup is pretty much what I do at the moment. I can't think of an
> easy way of doing this apart from convention which is pretty much what
> you suggest with "addFile". I suppose the next thing would be to add
> support for the '+' syntax and addMenuItem directive?

The IAdding view ('+' syntax) and Zope 3 menus are special code for the
Zope 3 app ZMI. I don't plan to add support for that.


Cheers,

Yuppie


_______________________________________________
Zope-CMF maillist - Zope-CMF[at]lists.zope.org
http://mail.zope.org/mailman/listinfo/zope-cmf

See http://collector.zope.org/CMF for bug reports and feature requests


l at lrowe

May 10, 2008, 7:00 AM

Post #20 of 26 (760 views)
Permalink
Re: [dev] newstyle content creation [In reply to]

yuppie wrote:
</snip>
>> The lookup is pretty much what I do at the moment. I can't think of an
>> easy way of doing this apart from convention which is pretty much what
>> you suggest with "addFile". I suppose the next thing would be to add
>> support for the '+' syntax and addMenuItem directive?
>
> The IAdding view ('+' syntax) and Zope 3 menus are special code for the
> Zope 3 app ZMI. I don't plan to add support for that.

FWIW, in Plone we rely on the adding view. If a new style factory is
specified in the FTI a view of that name is looked up on the adding view
of the container. This is from
plone.app.contentmenu.menu.FactoriesSubMenuItem:


addingview = queryMultiAdapter((addContext, self.request), name='+')
if addingview is not None:
addview = queryMultiAdapter((addingview, self.request),
name=fti.factory)
if addview is not None:
return '%s/+/%s' % (baseUrl, fti.factory,)


We don't make any use of the Zope 3 menu directives.

Laurence

_______________________________________________
Zope-CMF maillist - Zope-CMF[at]lists.zope.org
http://mail.zope.org/mailman/listinfo/zope-cmf

See http://collector.zope.org/CMF for bug reports and feature requests


y.2008 at wcm-solutions

May 13, 2008, 2:39 PM

Post #21 of 26 (719 views)
Permalink
Re: [dev] newstyle content creation [In reply to]

Hi!


Laurence Rowe wrote:
> yuppie wrote:
> </snip>
>>> The lookup is pretty much what I do at the moment. I can't think of
>>> an easy way of doing this apart from convention which is pretty much
>>> what you suggest with "addFile". I suppose the next thing would be to
>>> add support for the '+' syntax and addMenuItem directive?
>>
>> The IAdding view ('+' syntax) and Zope 3 menus are special code for
>> the Zope 3 app ZMI. I don't plan to add support for that.
>
> FWIW, in Plone we rely on the adding view.

Quoting
http://svn.zope.org/*checkout*/z3c.form/trunk/src/z3c/form/adding.txt?rev=78513
:

"While using ``IAdding``-based add forms is strongly discouraged by this
package due to performance and code complexity concerns, there is still the
need for add forms based on IAdding, especially when one wants to extend the
default ZMI and use the add menu."

If Zope 3 people strongly discourage using IAdding, I don't see a good
reason why we should use it in Zope 2.

> If a new style factory is
> specified in the FTI a view of that name is looked up on the adding view
> of the container. This is from
> plone.app.contentmenu.menu.FactoriesSubMenuItem:
>
>
> addingview = queryMultiAdapter((addContext, self.request), name='+')
> if addingview is not None:
> addview = queryMultiAdapter((addingview, self.request),
> name=fti.factory)
> if addview is not None:
> return '%s/+/%s' % (baseUrl, fti.factory,)

That means view name and factory name have to be the same. The portal
type is not passed to the view, so it has to be hardcoded inside the
view. Not very flexible, but if factory and view are only used for one
hardcoded portal type it works.


Cheers,

Yuppie


_______________________________________________
Zope-CMF maillist - Zope-CMF[at]lists.zope.org
http://mail.zope.org/mailman/listinfo/zope-cmf

See http://collector.zope.org/CMF for bug reports and feature requests


charlie at begeistert

May 19, 2008, 9:51 AM

Post #22 of 26 (615 views)
Permalink
Re: Re: [dev] newstyle content creation [In reply to]

Am 02.05.2008 um 13:50 schrieb yuppie:

> Did some more refactoring. If your factory can handle all the input,
> ContentAddFormBase's 'create' method should be sufficient. If not,
> you need a 'create' method like the one in FileAddView.

Yes, thank you very much!

>>>> You should not use that stuff if you don't need it. Schema
>>>> adapters and ProxyFieldProperty are just legacy code for old
>>>> content types.
>> I know. But I didn't know at the time and boy did it make me think
>> that things were going to be harder than they needed! I had to take
>> some time out at the time and curse the nameless people who hadn't
>> written the dummies guide to this! Still, it wasn't a bad idea
>> making me think more about this stuff.
>
> Sorry. Added a small explanation in the module docstring.

Thanks again. As I said, I don't think it did me any harm to go
through the process of working through adapters. It was just a bit off-
putting when working on my own objects.

>> Regarding naming: I suppose the easiest thing is to add an "id"
>> field to the add form for none file objects.
>
> That's an option if you don't want automatically generated IDs. My
> question was how to integrate oldstyle factories that don't have an
> add form into an add menu.

ah, now I understand the question! With addForms we get the default
next page but not with oldstyle factories? Is that correct?

>> It would be nice to have a "require once" in the schema value for
>> things like upload fields so that the same schema can be used for
>> adding and editing.
>
> In my own code I use some modified widgets that support
> self.widgets['foo'].required=True to override required=False of the
> field.

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")

>> This does, of course, beg the question: when we've moved everything
>> to browser_views do we start thinking about moving the default
>> classes to zope.app based stuff? Or do we still depend too heavily
>> on the Zope2 security declarations and other stuff?
>
> First priority for existing content classes is backwards
> compatibility. I prefer to keep them as they are and to use adapters
> to make them work with Zope3 style code.

Okay. Just going from my own experience which was take CMFDefault and
see what you can do with it. - it's actually really nice to be able to
right some very lightweight, effectively Zope 3 classes, and give them
PortalContent. So, whilst supporting legacy classes, it would also be
nice to have a couple of examples of what to do if you write your own
classes from scratch. mm, probably something I could do.

>>>> I also understand what you mean about making a menu for this
>>>> stuff. It would be nice to have some configuration for this so
>>>> that we don't have to rely on actions such as AddFile, AddImage,
>>>> etc. Would that be something like listing all views that provide
>>>> a specific interface?
>>>
>>> No. The view registrations don't provide enough information and
>>> I'd like to keep this configurable TTW.
>>>
>>> We can look up the addable types in the types tool as
>>> folder_factories and Plone do. But in that case we need a way to
>>> get the URL of the add view.
>> The lookup is pretty much what I do at the moment. I can't think of
>> an easy way of doing this apart from convention which is pretty
>> much what you suggest with "addFile". I suppose the next thing
>> would be to add support for the '+' syntax and addMenuItem directive?
>
> The IAdding view ('+' syntax) and Zope 3 menus are special code for
> the Zope 3 app ZMI. I don't plan to add support for that.


And, as I know from a later post, the IAdding interface isn't
universally popular.
--
Charlie Clark
Helmholtzstr. 20
Düsseldorf
D- 40215
Tel: +49-211-938-5360
GSM: +49-178-782-6226



_______________________________________________
Zope-CMF maillist - Zope-CMF[at]lists.zope.org
http://mail.zope.org/mailman/listinfo/zope-cmf

See http://collector.zope.org/CMF for bug reports and feature requests


charlie at begeistert

May 20, 2008, 1:50 AM

Post #23 of 26 (607 views)
Permalink
Re: Re: [dev] newstyle content creation [In reply to]

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



_______________________________________________
Zope-CMF maillist - Zope-CMF[at]lists.zope.org
http://mail.zope.org/mailman/listinfo/zope-cmf

See http://collector.zope.org/CMF for bug reports and feature requests


r.ritz at biologie

May 20, 2008, 4:22 AM

Post #24 of 26 (607 views)
Permalink
Re: [dev] newstyle content creation [In reply to]

Charlie Clark wrote:

[..]

>
> 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?
>

Alternatively, support for portal_type specification at runtime (and
anything else for that matter) could be handled as a behavior in the
sense of

http://pypi.python.org/pypi/plone.behavior/

maybe? Just a thought ...

Raphael

_______________________________________________
Zope-CMF maillist - Zope-CMF[at]lists.zope.org
http://mail.zope.org/mailman/listinfo/zope-cmf

See http://collector.zope.org/CMF for bug reports and feature requests


charlie at begeistert

Jun 22, 2008, 9:28 AM

Post #25 of 26 (199 views)
Permalink
Re: Re: [dev] newstyle content creation [In reply to]

Am 02.05.2008 um 13:50 schrieb yuppie:

> Did some more refactoring. If your factory can handle all the input,
> ContentAddFormBase's 'create' method should be sufficient. If not,
> you need a 'create' method like the one in FileAddView.


Done quite a lot of Add Forms based on your work and we ended up
extended the base view to implement form_fields and require the sub
classes to provide the portal_type and the schema or list of fields.

@property
def form_fields(self):
fields = form.FormFields(
TextLine(
__name__='portal_type',
default=self.portal_type)
)
# allow sub-classes to pass in sequences of schema
if isinstance(list, self.schema):
for s in self.schema:
fields += form.FormFields(s)
else:
fields += form.FormFields(self.schema)
return fields

I'm not sure if it's overkill to be able to handle a list of fields
but we've found it makes views a lot easier to work with. What do you
think?

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



_______________________________________________
Zope-CMF maillist - Zope-CMF[at]lists.zope.org
http://mail.zope.org/mailman/listinfo/zope-cmf

See http://collector.zope.org/CMF for bug reports and feature requests

First page Previous page 1 2 Next page Last page  View All Zope cmf RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact lists@gossamer-threads.com
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.