[Plone-UI] Using Python code to render a home page view

Sanders nique at webtic.nl
Sun Nov 22 18:02:12 UTC 2009


In chapter 11 Veda Williams Plone Theming book there's an great example of
using Python code to render a home page view. But I'm stuck when trying to
expand this example with more then 3 items on the homepage.

What I did:

Addded to interfaces.py:
-------------

    def getSlot4Image():
	   """Returns an absolute url for the image to appear in the first slot.
          Use either the image associated with the first item returned by
getSlot1Items or
          the fallback, which lives in homepage/images/slot4.jpg
          If that doesn't exist either, return None.
        """

    def getSlot4Items():
	    """Return the first 3 content items for the first slot.  We're assuming
that a
        Collection lives at the path /homepage/slot4; we'll return its first
three items.
        """
---------------


Added to homepage.py:
----------------
	def getSlot4Image(self):
	        return self._getSlotImage(4)

	@memoize
	def getSlot4Items(self):
	    return self._getSlotItems(4)
----------------



Added to homepage_view.pt:
-----------------
		<td id="home-cell-four"
            tal:define="items hp_view/getSlot4Items"
            tal:condition="items">
            <div class="cell-wrapper">
                <h2>Column Four</h2>
                <h3>Titel 4</h3>

                 
                
                <div class="folder-listing"
                     tal:repeat="item items">

                    <tal:slot
                        tal:define="is_in_collection python:not
item.getId().startswith('slot')">

                         
                            [Title]
                         

                        <tal:collection_item
tal:condition="is_in_collection">
                            [Description]
                             Read more... 
                        </tal:collection_item>
                    
                        <tal:document tal:condition="python:not
is_in_collection">
                            
                        
                            <tal:edit_link
tal:condition="python:item.portal_type=='Document' and
checkPermission('Modify portal content', item)">
                                 # 
                                   Edit...
                                 
                            </tal:edit_link>
                        </tal:document>
                        
                    </tal:slot>
                </div>
            </div>
        </td>
---------------


The example is working perfect with only 3 items on the homepage but when I
add the fourth item it gives an error 'TraversalError:
(<Products.Five.metaclass.Homepage object at 0x81390f8d0>, 'getSlot4Items')
'

I really appreciate any help on this issue.
Nique


-- 
View this message in context: http://n2.nabble.com/Using-Python-code-to-render-a-home-page-view-tp4047127p4047127.html
Sent from the User Interface & Design mailing list archive at Nabble.com.




More information about the UI mailing list