Changeset 2704 in products for quintagroup.portlet.collection


Ignore:
Timestamp:
Jul 20, 2010 7:51:26 AM (14 years ago)
Author:
fenix
Message:

added batch navigation

Location:
quintagroup.portlet.collection/trunk/quintagroup/portlet/collection
Files:
6 added
3 edited

Legend:

Unmodified
Added
Removed
  • quintagroup.portlet.collection/trunk/quintagroup/portlet/collection/browser/configure.zcml

    r1572 r2704  
    1414      /> 
    1515 
     16  <browser:resource 
     17      name="batch.js" 
     18      file="resources/batch.js" /> 
    1619</configure> 
  • quintagroup.portlet.collection/trunk/quintagroup/portlet/collection/collection.pt

    r1575 r2704  
    22    i18n:domain="plone" 
    33    tal:define="collection_url view/collection_url; 
    4                 styling view/data/styling; 
    5                 plone_view context/@@plone; 
    6                 toLocalizedTime nocall:plone_view/toLocalizedTime; 
    7                 getIcon nocall:plone_view/getIcon;" 
     4                styling view/data/styling" 
    85    tal:attributes="class string:${attrs/class} ${styling}"> 
    96 
     
    1512        </a> 
    1613        <span class="portletTopRight"></span> 
     14        <span class="portletNavSection" 
     15              tal:condition="view/data/allow_batching" 
     16              tal:content="structure view/batch_navigation"> 
     17        </span> 
    1718    </dt> 
    18      
    19     <tal:events tal:repeat="obj view/results"> 
    20     <dd class="portletItem" 
    21         tal:define="oddrow repeat/obj/odd; 
    22                     item_icon python:getIcon(obj); 
    23                     show_title python:view.showProperty('Title'); 
    24                     show_description python:view.showProperty('Description')" 
    25         tal:attributes="class python:oddrow and 'portletItem even' or 'portletItem odd'"> 
    26         <a href="#" 
    27            class="tile" 
    28            tal:attributes="href obj/getURL; 
    29                            title python: show_description and obj.Description or ''"> 
    30             <img tal:replace="structure item_icon/html_tag" /> 
    31             <span class="tileTitle" 
    32                   tal:condition="show_title" 
    33                   tal:content="obj/pretty_title_or_id"> 
    34              Title 
    35             </span> 
    36             <span class="tileDescription" 
    37                   tal:condition="show_description"> 
    38               <tal:descr content="obj/Description" /> 
    39               <span class="tileReadMore" 
    40                     tal:condition="view/data/show_item_more" 
    41                     tal:attributes="href obj/getURL" i18n:translate="more_url"> 
    42                     &hellip;more 
    43               </span>             
    44             </span> 
    45             <span class="portletItemDetails" 
    46                   tal:condition="view/data/show_dates" 
    47                   tal:content="python:toLocalizedTime(obj.Date)"> 
    48                 Date 
    49             </span> 
    50         </a> 
    51     </dd> 
    52     </tal:events> 
    53      
     19    <tal:items replace="structure view/render_items"/> 
    5420    <dd class="portletFooter" tal:condition="view/data/show_more"> 
    5521        <span class="portletBottomLeft"></span> 
  • quintagroup.portlet.collection/trunk/quintagroup/portlet/collection/collection.py

    r1572 r2704  
    1616from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile 
    1717from plone.app.vocabularies.catalog import SearchableTextSourceBinder 
     18from zope.schema import ValidationError 
    1819from plone.app.form.widgets.uberselectionwidget import UberSelectionWidget 
    1920 
    2021from Products.ATContentTypes.interface import IATTopic 
     22from Products.CMFPlone.PloneBatch import Batch 
    2123from plone.portlet.collection.collection import ICollectionPortlet 
    2224 
    2325from quintagroup.portlet.collection import MessageFactory as _ 
     26 
     27MIN_BATCH_SIZE , MAX_BATCHSIZE = 1, 30 
     28 
     29class NotValidBatchSizeValue(ValidationError): 
     30    """This is not valid batch size value. 
     31     
     32    """ 
     33 
     34def validate_batch_size(value): 
     35    if MIN_BATCH_SIZE <= value <= MAX_BATCHSIZE: 
     36        return True 
     37    raise NotValidBatchSizeValue(value) 
    2438 
    2539class IQCollectionPortlet(ICollectionPortlet): 
     
    5266                                 default=True) 
    5367 
     68    allow_batching = schema.Bool(title=_(u"Allow batching."), 
     69                                 description=_(u"If enabled, items will be splited into pages."), 
     70                                 required=False, 
     71                                 default=False) 
     72 
     73    batch_size = schema.Int(title=_(u"Batch size"), 
     74                            description=_("Amount of items per page" 
     75                                          "(if not set 3 items will be displayed as default)."), 
     76                            required=False, 
     77                            default=3,  
     78                            constraint=validate_batch_size) 
     79 
    5480class Assignment(base.Assignment): 
    5581    """ 
     
    6894    def __init__(self, header=u"", target_collection=None, limit=None, 
    6995                 random=False, show_more=True, show_dates=False, 
    70                  item_attributes=[], styling=u"", show_item_more=False, link_title=True): 
     96                 item_attributes=[], styling=u"", show_item_more=False, 
     97                 link_title=True, allow_batching=False, batch_size=3): 
    7198 
    7299        super(Assignment, self).__init__(header=header, 
     
    79106        self.show_item_more = show_item_more 
    80107        self.link_title = link_title 
     108        self.allow_batching = allow_batching 
     109        self.batch_size = batch_size 
    81110        
    82111    @property 
     
    86115        """ 
    87116        return self.header 
    88  
    89  
     117     
    90118class Renderer(base.Renderer): 
    91119    """Portlet renderer. 
     
    97125 
    98126    render = ViewPageTemplateFile('collection.pt') 
     127    navigation = ViewPageTemplateFile('browser/templates/navigation.pt') 
     128    items_listing = ViewPageTemplateFile('browser/templates/items_listing.pt') 
    99129 
    100130    def showProperty(self, name): 
    101131        return name in self.data.item_attributes 
    102132 
     133    def batches(self): 
     134        items = super(Renderer, self).results() 
     135        delta = self.data.batch_size 
     136        return [items[idx:idx + delta] for idx in range(0, len(items), delta)] 
     137     
     138    def batch_navigation(self): 
     139        return self.navigation(batches=self.batches()) 
     140 
     141    def render_items(self): 
     142        if self.data.allow_batching: 
     143            return ''.join([self.items_listing(portlet_items=batch, 
     144                                               page_number=str(index)) 
     145                            for index, batch in enumerate(self.batches())]) 
     146        return self.items_listing(portlet_items=self.results()) 
    103147         
    104148class AddForm(base.AddForm): 
Note: See TracChangeset for help on using the changeset viewer.