Attention

This document was written for an unsupported version of Plone, Plone 2.1.x, and was last updated 795 days ago.

For more information, see the version support policy.

To learn how to upgrade to the current version of Plone, read the upgrade manual.

create an integrated folder view based on a custom content type (sample type: RichDocument)

by kingnebu last modified Mar 19, 2010 11:07 AM
Use your own view to display all RichDocuments contained in a folder as one Page

Preface

The idea is to make it easier to have different topics on one page, i.e. the first page. The code below is a hacked version of folder_summary_view. The changes allows to combine different RichDocuments to appear as one visually Page, but should be easiely adaptable for other content types.

Example

RichDocuments A and B will be displayed in one page.

Example

Note: Images, attached to a RichDocument, will appear on the right side of the coresponding RichDocuments bodytext. Other attachments will be listed in a box below the coresponding RichDocument.

Requirements

I am using RichDocument as contenttype. So this is needed to be installed.

The view template

Create a Page Template <your-plone-site>/portal_skins/custom/folder_documents_view form the ZMI.

Insert this code in folder_documents_view:

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
     lang="en"
     metal:use-macro="here/main_template/macros/master"
     i18n:domain="plone">

<body>

   <div metal:fill-slot="main">
   <metal:main-macro define-macro="main">


       <div metal:use-macro="here/document_actions/macros/document_actions">
           Document actions (print, sendto etc)
       </div>

       <a href=""
          class="link-parent"
          tal:define="parent_url python:here.navigationParent(here, template_id)"
          tal:condition="parent_url"
          tal:attributes="href parent_url"
          i18n:translate="go_to_parent_url">
       Up one level
       </a>

       <div class="documentDescription" tal:content="here/Description">
           description
       </div>

       <metal:listingmacro define-macro="listing">
       <tal:foldercontents define="contentFilter contentFilter|request/contentFilter|nothing;
                           limit_display limit_display|request/limit_display|nothing;
                           more_url more_url|request/more_url|string:folder_contents;
                           contentsMethod python:test(here.portal_type=='Topic',
                                    here.queryCatalog, here.getFolderContents);
                           folderContents python:here.getFolderContents(contentFilter =
                                    {'portal_type' : ['RichDocument']}, batch = True);
                           use_view_action site_properties/typesUseViewActionInListings;
                           over_limit python: limit_display and len(folderContents) > limit_display;
                           folderContents python: (over_limit and folderContents[:limit_display])
                                                                or folderContents;
                           batch folderContents">
       <tal:listing condition="folderContents">
           <div metal:use-macro="here/batch_macros/macros/navigation" />

           <div  tal:repeat="item folderContents">
               <tal:block tal:define="item_url item/getURL|item/absolute_url;
                                      item_id item/getId|item/id;
                                      item_title_or_id item/pretty_title_or_id;
                                      item_description item/Description;
                                      item_type item/portal_type;
                                      item_type_title item/Type;
                                      item_modified item/ModificationDate;
                                      item_created item/CreationDate;
                                      item_type_class python: 'contenttype-' + putils.normalizeString(item_type);
                                      item_wf_state item/review_state|python: wtool.getInfoFor(item, 'review_state', '');
                                      item_wf_state_class python:'state-' + putils.normalizeString(item_wf_state);
                                      item_creator item/Creator;
                                      item_start item/start/ISO|item/StartDate|nothing;
                                      item_end item/end/ISO|item/EndDate|nothing;
                                      item_object item/getObject;

                                  ">





               <h1>
                   <span style="margin: 0;
                                padding: 0;
                                border: none !important;
                                text-decoration: none;"
                         tal:condition="not: isAnon">

                         <a href="/view"  tal:define="url python:(item_url+'/edit')" tal:attributes="href url" >

                              <img  src="" alt=""
                                    tal:attributes="src    string:$portal_url/pencil_icon.gif;
                                                    alt    python:('edit ' + item_title_or_id);
                                                   " />
                         </a>

                   </span>

                   <span class="documentFirstHeading"
                       metal:define-macro="listitem" tal:content="item_title_or_id">


                       <a href="#"
                          tal:condition="python:item_type != 'Link'"
                          tal:attributes="href python:test(item_type in use_view_action, item_url+'/view', item_url+'/');">

                           Item Title
                       </a>

                       <a href="#"
                          tal:condition="python:item_type == 'Link'"
                          tal:content="item_title_or_id"
                          tal:attributes="href item/getRemoteUrl;">
                           External Link
                       </a>

                   </span>
               </h1>



               <div class="documentByLine" tal:define="creator item_object/Creator;">

                <tal:name tal:condition="creator"
                    tal:define="author python:mtool.getMemberInfo(creator)">
                    <span i18n:translate="label_by_author">
                      by
                          <a href="#"
                             tal:attributes="href string:${portal_url}/author/${creator}"
                             tal:content="python:author and author['fullname'] or creator"
                             tal:omit-tag="not:author"
                             i18n:name="author">
                            Bob Dobalina
                          </a>
                    </span>
                &mdash;

                </tal:name>

                <span i18n:translate="box_last_modified">
                      last modified
                </span>

                 <span tal:replace="python:item_object.toLocalizedTime(item_object.ModificationDate(),long_format=1)">
                  August 16, 2001 at 23:35:59
                 </span>
               </div>


               <p class="documentDescription">
                   <span tal:omit-tag="" tal:condition="not:item_description">
                       &nbsp;
                   </span>
                   <span tal:omit-tag="" tal:content="item_description">
                       description
                   </span>
               </p>


               <div class="imagesPreviewBox"
                       tal:define="images python:item_object.getFolderContents(contentFilter =
                                   {'portal_type' : ['ImageAttachment']}, full_objects = True)"
                       tal:condition="nocall:images">

                 <div class="imagesPreviewBoxBody">
                     <tal:block repeat="image images">
                        <div class="" tal:attributes="class python:test (repeat['image'].end,
                                   'imagesPeviewBoxImage', 'imagesPreviewBoxImage bottomDivider');">

                             <img tal:replace="structure python:image.tag(scale='preview')"/>
                             <br style="clear:both" />
                             <span  tal:content="image/Title">
                                 Title
                             </span>

                        </div>
                     </tal:block>
                     </div>
                 </div>



                 <div class="plain"><tal:block tal:content="structure item_object/CookedBody" /></div>

                 <div class="visualClear"><!-- --></div>

                 <div metal:use-macro="python:item_object.widget('displayImages')"/>

                 <div metal:use-macro="python:item_object.widget('displayAttachments')"/>


               </tal:block>
           </div>

           <!-- Navigation -->
           <div metal:use-macro="here/batch_macros/macros/navigation" />


       </tal:listing>
       <metal:empty metal:define-slot="no_items_in_listing">
           <p class="discreet"
              tal:condition="not: folderContents"
              i18n:translate="description_no_items_in_folder">
               There are currently no items in this folder.
           </p>
       </metal:empty>

       </tal:foldercontents>
       </metal:listingmacro>
   </metal:main-macro>
   </div>

</body>
</html>

Use it

Add the templates id to the Available view methods form field in <your-plone-site>/portal_types/Folder. The view is now available for every folder of your plone installation. Select it from the Display menu to us it for the actual folder. In <your-plone-site>/portal_types/Folder you can define it as the default view.

TODO

I am using it for a one-editor site. That is why <span tal:condition="not: isAnon"> works fine for me. Should be improved for community portals.

I'm not a Plone geek! If you find errors or senseless things, please write it down in a comment!


Contribute

Something wrong or out of date? Anybody can edit or create a new article in the knowledge base. Simply create an account on this site, log in, and click the Edit button to contribute.