Changeset 2704 in products for quintagroup.portlet.collection/trunk/quintagroup/portlet/collection/collection.py
- Timestamp:
- Jul 20, 2010 7:51:26 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
quintagroup.portlet.collection/trunk/quintagroup/portlet/collection/collection.py
r1572 r2704 16 16 from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile 17 17 from plone.app.vocabularies.catalog import SearchableTextSourceBinder 18 from zope.schema import ValidationError 18 19 from plone.app.form.widgets.uberselectionwidget import UberSelectionWidget 19 20 20 21 from Products.ATContentTypes.interface import IATTopic 22 from Products.CMFPlone.PloneBatch import Batch 21 23 from plone.portlet.collection.collection import ICollectionPortlet 22 24 23 25 from quintagroup.portlet.collection import MessageFactory as _ 26 27 MIN_BATCH_SIZE , MAX_BATCHSIZE = 1, 30 28 29 class NotValidBatchSizeValue(ValidationError): 30 """This is not valid batch size value. 31 32 """ 33 34 def validate_batch_size(value): 35 if MIN_BATCH_SIZE <= value <= MAX_BATCHSIZE: 36 return True 37 raise NotValidBatchSizeValue(value) 24 38 25 39 class IQCollectionPortlet(ICollectionPortlet): … … 52 66 default=True) 53 67 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 54 80 class Assignment(base.Assignment): 55 81 """ … … 68 94 def __init__(self, header=u"", target_collection=None, limit=None, 69 95 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): 71 98 72 99 super(Assignment, self).__init__(header=header, … … 79 106 self.show_item_more = show_item_more 80 107 self.link_title = link_title 108 self.allow_batching = allow_batching 109 self.batch_size = batch_size 81 110 82 111 @property … … 86 115 """ 87 116 return self.header 88 89 117 90 118 class Renderer(base.Renderer): 91 119 """Portlet renderer. … … 97 125 98 126 render = ViewPageTemplateFile('collection.pt') 127 navigation = ViewPageTemplateFile('browser/templates/navigation.pt') 128 items_listing = ViewPageTemplateFile('browser/templates/items_listing.pt') 99 129 100 130 def showProperty(self, name): 101 131 return name in self.data.item_attributes 102 132 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()) 103 147 104 148 class AddForm(base.AddForm):
Note: See TracChangeset
for help on using the changeset viewer.