[Zope-CMF] programmatically add topics when adding a new crea ted type

Carl Rendell cer@sol43.com
Thu, 8 Aug 2002 08:13:16 -0700


On Tuesday, August 6, 2002, at 02:26  PM, Al-Muthairi, Abdullah wrote:

>
>
> thank you very much Mr. Rendell for your reply
> but im not using products.i just copied the portal folder type=20
> with modifying it without creating a new product.currently my=20
> factory method is the same as the portal folder factory method.i=20
> tried copying the "manage_addPortalFolder" factory method from the=20
> "PortalFolder" file to a new file calling it=20
> "manage_addPortalAppDoc" and made it my new type factory method=20
> but it didnt work.i got a failure but when i returned the factory=20
> method to the portal folder factory method it worked find. how can=20
> i make it work?so that i can add the code to autocreate the 2=20
> topics with the creation of the AppDoc type.and note i want to=20
> create the 2 topics with the creation of the AppDoc type only.so=20
> if i put the code in the productName_edit.py file i get 2 topics=20
> created everytime i edit my AppDoc type.

The method I described will work regardless of whether you are=20
using file based products, scriptable types, or just copying portal=20
types. If I understand your need correctly, most of what you need=20
to do is modify a skin (form), edit method, and a portal_type.=20
Here's what you'll do.

1. In portal_types tool - Copy, Paste, and re-name the portal_type=20
you want to start with (you're starting with 'Folder' right?)

2. Select your new portal_type, click on the actions tab, and=20
change the 'edit' action from current to new form name - for=20
example on Folder :

   Was - Action =3D folder_edit_form

   Is  - Action =3D newName_folder_edit_form (you choose the 'newName'

3. In the portal_skins tool - click on zpt_content (page templates)=20
or content (dtml), and select the old form (ie folder_edit_form).

    o Click on the customize button (this will put a copy of the=20
file in the custom folder within portal_skins.

    o be sure you have 'Expand Macros when Editing' off

    o Edit the form action call to reflect the new action name and=20
save the changes. Example:

       was - <form action=3D"folder_edit"...

       is  - <form action=3D"newName_folder_edit"...

    o in the portal_skins/custom folder rename your form

       was - folder_edit_form

       is  - newName_folder_edit_form

4. Within the portal_skins tool select custom folder, and select=20
your target python script (we're using folder_edit).

    o click Customize for this item to place it in the=20
portal_skins/custom folder

    o add the additional python script you need to create the topics=20
within the new folder as I described earlier and save the changes

    o rename the script to MATCH the name you specified in the edit=20
form - For Example

      was - folder_edit

      is  - newName_folder_edit

Of note, the naming convention is not required but I prefer to know=20
where the base of the new item came from so that I can keep things=20
in sync with changes to CMF. Ideally the name of the form and the=20
edit script are all the same with the exception of the ending=20
(_edit, _form). That helps as well.

Hope that helps.

~C

>
> i really need help in this and thanx in advance
>
> -----Original Message-----
> From: Carl Rendell [mailto:cer@sol43.com]
> Sent: Friday, August 02, 2002 8:40 AM
> To: Al-Muthairi, Abdullah
> Cc: zope-cmf@zope.org
> Subject: Re: [Zope-CMF] programmatically add topics when adding a new
> created type
>
>
>
> On Friday, August 2, 2002, at 06:36=A0 AM, zope-cmf-request@zope.org
> wrote:
>
> > Message: 8
> > From: "Al-Muthairi, Abdullah" <Abdullah.Al-Muthairi@INTP.COM>
> > To: "'zope-cmf@zope.org'" <zope-cmf@zope.org>
> > Date: Thu, 1 Aug 2002 15:02:59 -0700
> > Subject: [Zope-CMF] programmatically add topics when adding a new
> > created type
> >
> > Hi everyone
> >
> > this is my first post here i would really like some help here.
> > i created a new portal type called "Application Documentation" by
> > copying a
> > folder type and modifying its actions. It should contain meta data
> > about the
> > ineternally developed applications in the company and should also
> > contain 2
> > zope topics. One of the topics will be the applications documents
> > and the
> > 2nd is user contributions. Every time a new application
> > documentation type
> > is created these 2 topics should be created also. Any ideas how to
> > automatically create the 2 topics with the creation of the type?
>
> Within the edit script for your product (productName_edit.py), you
> may add lines that create the two new topics:
>
> =A0=A0 # after you've created your new folder object...
>
> =A0=A0 folderObject =3D getattr(context,'folderName')
>
> =A0=A0 newTopics =3D {'app_docs'=A0 : { 'id'=A0=A0=A0 =
:'application_documents'
> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=
=A0=A0=A0=A0=A0 , 'title' : 'Application Documents' }
> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 ,'user cont' : { 'id'=A0=A0=A0=
 :'user_contributions'
> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=
=A0=A0=A0=A0=A0 , 'title' : 'User Contributions' }
> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 }
>
> =A0=A0 for key in newTopics.keys():
> =A0=A0=A0=A0=A0=A0 folderObject.invokeFactory(type_name=3D'Topic',
> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=
=A0=A0=A0=A0=A0=A0=A0=A0=A0 id=3DnewTopics[key][id],
> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=
=A0=A0=A0=A0=A0=A0=A0=A0=A0 title=3DnewTopics[key][id])
>
> That will get the items created and preserve the name space. Within
> the for loop you can add all of the other calls that you wish to
> set up each topic the way you want to set up each topic, and
> control these by extending the dictionary.
>
> I do this pretty often with products, but not specifically with =
topics.
>
>
> > i think it is achieved in the factory method (im still new to CMF
> > and zope)
> > which brings us to my 2nd question. where can i find the factory
> > methods of
> > the portal types?
> >
>
> All of the factory method dictionaries are in the various CMF
> directories. Mainly CMFDefault.
>
> > thank you very much for your time
>
> Carl E. Rendell
> Solution43
> Information Distribution Consulting=A0=A0=A0=A0=A0=A0=A0 |=A0=A0 =
"Ahhhh the power of
> cer@sol43.com=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=
=A0=A0=A0=A0=A0=A0=A0=A0=A0 |=A0=A0=A0 acquisition"=A0 -=20
> Chef Z
> The information contained in this email message may be privileged=20
> and is confidential information intended only for the use of the=20
> recipient or any employee or agent responsible for delivering it=20
> to the intended recipient.=A0 Any unauthorized use, distribution or=20
> copying of this information is strictly prohibited and may be=20
> unlawful.=A0 If you have received this communication in error,=20
> please notify the sender immediately and destroy the original=20
> message and all attachments from your electronic files.
>
>

Carl E. Rendell
Solution43
Information Distribution Consulting        |   "Ahhhh the power of
cer@sol43.com                              |    acquisition"  - Chef Z