You are here: Home / Documentation / How To's / Kim Test 3

Kim Test 3

by nguyen — published Aug 16, 2016 10:50 AM, last modified Aug 16, 2016 10:50 AM
test 3

Plone 3.3.* and Plone 4.*


You should already know how to:


    * Code a new Content Type or extend a Content Type.

    * Use Generic Setup xml files in the profiles/default directory.



This is how you setup a Indexes and Metadata field for your portal_catalog with a extended content type.  It will be the same for a new content type.  I will add one field to the Metadata and Indexes in this example.  This gives me access to the objects new attribute through portal_catalog>brains rather then waking up the object which is very slow.





    * catalog.xml


1) <?xml version="1.0"?>

2)  <object name="portal_catalog" meta_type="Plone Catalog Tool">

3)    <index name="oneSearchId" meta_type="FieldIndex">

4)       <indexed_attr value="oneSearchId"/>

5)     </index>

6)     <column value="oneSearchId"/>

7) </object>


    * Line 2: Tells Generic Setup where to map this Object Extension too.

    * Line 3-5:  This sets up the portal_catalog>Indexes.  It adds a new field called oneSearchId as a FieldIndex type.  Don't forget to give the index a new attribute value which is on Line 4.

    * Line 6: This sets up the portal_catalog>Metadata with a new field called oneSearchId.  oneSearchId is now accessible as a brain attribute when you

      make a query on the catalog.

    * (Specal Note)  Line 6:  This value oneSearchId needs to be the same name as the function definition in the Content Type Class below.  This Line maps the Content Accessor of this field to the proper Metadata field.





    * This is only a partial view of the whole file, showing key areas.


1)  IYourContentTypeSchema= folder.ATBTreeFolderSchema.copy() + atapi.Schema((

2)        IntegerField('oneSearchId',

3)            required=True,

4)            searchable=False,

5)            default = "",

6)            validators = ('isInt'),

7)            widget = IntegerWidget(

8)                description = "Your Description",

9)                label = _(u'Your Label', default=u'Your Label Default'),

10)            )),

11) ))


12) .....


13) class YourContentType(base.ATCTBTreeFolder):

14)     implements(IYourContentTypeSchema)


15)     .....


16)     def oneSearchId(self):

17)            return self.getField('oneSearchId').get(self)


18)     ......


    * Line 1-11:  We just extend the Folder Schema and add a new Schema Field.

    * Line 13-18:  This is your ContentType Class which has your accessors and mutators for your Content.

    * Line 16-17:  This is the basic accessor for your oneSearchId Field.  It access and returns the oneSearchId.

    * (Specal Note) Line 16-17:  The function definition name must be the same as the catalog.xml (Specal Note) Line 6.  The catalog.xml maps to this function definition.