You are here: Home / Documentation / How To's / How to add a custom tabular view to D2C

How to add a custom tabular view to D2C

by ledwell published Mar 07, 2012 12:25 PM, last modified Aug 16, 2016 10:49 AM
Add a table as an option for display for a D2C object AND how to customize that table to show data thats stored in the D2C adapter

Again, thanks Nathan for helping me with the code!!

Setup

  • Make sure that you have the following products installed
    • PloneFormGen
    • PloneFormGen Save Data to Content (hereby known as D2C)
  • Create a PloneFormGen form and add some "string fields" to it
  • Turn off the "mailer adapter" (unless you want to get test emails of course)
  • I'll assume for this "howTo" that you created 5 fields and named them the following
    • 01CoolField
    • 02CoolField
    • 03CoolField
    • 04CoolField
    • 05CoolField
  • Choose "Add New" - "save data to content adapter" name it "d2cSavedData"
  • Fill out your form a couple times

Look at the existing data

  • go to your PloneFormGen form
  • select the "contents" tab
  • choose the "d2CSavedData" (you should see the couple of results you submitted)
  • choose the "view" tab
  • You should now see a "display" dropdown menu. If you select that the only view that should be available is "base_view". Were gonna add a new tabular view.

Add a new view & Customize Portal type

Now for the fun and easy part. Were gonna duplicate an existing view "folder_tabular_view" and make it selectable for D2C. 
 

note this part is "optional", if you only want the tabular view (like you see for collections and folders ) with no customizations then feel free to go directly to the next step

  • go into the zmi "url/manage"
  • choose 
    • portal_skins
    • plone_content
    • folder_tabular_view (Tabular view)
  • choose "customize" (places this view in the "custom" folder)
  • choose the checkbox next to "folder_tabular_view" 
  • choose "rename"
  • rename it "folder_tabular_d2c_view". If you change anything on this document without renaming it then you will change everything across the site using that display (that can be bad) .

Add the new view to the D2C portal type

  • go into the zmi "url/manage"
  • choose
    • portal_types
    • FormSaveData2ContentAdapter
    • Under "Available view methods" add the following
      "folder_tabular_d2c_view" OR if you you only want to add the existing tabular view then use "folder_tabular_view" instead

Change the D2C default view 

  • go back to your form
  • choose 
    • "contents" tab
    • "d2cSavedData"
    • choose the "view" tab
  • Now under display you should see your new view appears.

Customize the customization

Lets assume you want to customize the new view such that the table columns shows you specific information from the entries youve added. So lets say we dont need the "author" column and want instead to add the contents of the field named "01CoolField". 

CustomizedD2CView.png

Were gonna edit the new view weve added to our custom folder.

  • go to the custom folder (ill assume u know how to get there by now) :)
  • choose the new view named "folder_tabular_d2c_view"
  • find this code 
<tr metal:define-macro="listitem"
                        tal:define="oddrow repeat/item/odd;
                        tal:attributes="class python:test(oddrow, 'even', 'odd')">

Replace it with

<tr metal:define-macro="listitem"
                        tal:define="oddrow repeat/item/odd;
                                    item item/getObject|item;"
                        tal:attributes="class python:test(oddrow, 'even', 'odd')">

Find the table headers

The table headers should look like
<th class="nosort">&nbsp;<tal:title i18n:translate="listingheader_title"
                          >Author</tal:title>&nbsp;</th>

Change one of them to

<th class="nosort">&nbsp;<tal:title i18n:translate="listingheader_title"
                          >01CoolField</tal:title>&nbsp;</th>

Find the Column that goes with the headers

Should look something like
<td tal:condition="show_about">
                                <tal:name tal:condition="item_creator"
                                  tal:define="author python:pas_member.info(item_creator)">
                                <a href="#"
                                   tal:attributes="href string:${navigation_root_url}/author/${item_creator}"
                                   tal:content="author/name_or_id"
                                   tal:omit-tag="not:author">
                                  Bob Dobalina
                                </a>
                                </tal:name>
                            </td>

Replace that with

<td 
                                    tal:content="python:item.getValue('01CoolField')">
                                </td>

That should be all there is to it. Go back to D2C and refresh your browser. You should now see data that a user has submitted via the form appear here. I did this this way because I didnt want ALL the values from the fields to appear just certain ones.

 

 
Navigation