def _getBatch(self): """ """ # Calculate products per page fi = self.getFormatInfo() products_per_page = fi.get("lines_per_page") * \ fi.get("products_per_line") # Get all products mtool = getToolByName(self.context, "portal_membership") sorting = self.request.SESSION.get("sorting") try: sorted_on, sort_order = sorting.split("-") except (AttributeError, ValueError): sorted_on = "price" sort_order = "desc" pm = IProductManagement(self.context) products = pm.getAllProducts(sorted_on=sorted_on, sort_order = sort_order) # Get start page b_start = self.request.get('b_start', 0); # Calculate Batch return Batch(products, products_per_page, int(b_start), orphan=0);
def _getBatch(self): """ """ # Calculate products per page fi = self.getFormatInfo() products_per_page = fi.get("lines_per_page") * \ fi.get("products_per_line") # Get all products mtool = getToolByName(self.context, "portal_membership") sorting = self.request.get("sorting", None) try: sorted_on, sort_order = sorting.split("-") except (AttributeError, ValueError): sorted_on = "price" sort_order = "desc" view = getMultiAdapter((self.context, self.request), name='search-view') brains = view.getSearchResults(simple=False) products = [brain.getObject() for brain in brains] # Get start page b_start = self.request.get('b_start', 0) # Calculate Batch return Batch(products, products_per_page, int(b_start), orphan=0)
def experimentslisting(self): site_path = queryUtility(IPloneSiteRoot).getPhysicalPath() b_start = self.request.get('b_start', 0) b_size = self.request.get('b_size', 20) experiment_type = self.request.get('datasets.filter.experimenttype', None) query = { 'path': { 'query': '/'.join(site_path + (defaults.EXPERIMENTS_FOLDER_ID, )) }, 'object_provides': experiment_type, 'sort_on': 'created', 'sort_order': 'descending', # provide batch hints to catalog 'b_start': b_start, 'b_size': b_size } text = self.request.get('datasets.filter.text') if text: query['SearchableText'] = text pc = getToolByName(self.context, 'portal_catalog') results = pc.searchResults(query) from Products.CMFPlone import Batch return Batch(IContentListing(results), b_size, b_start)
def getProducts(self): """ """ shop = IShopManagement(self.context).getShop() pm = IProductManagement(shop) result = [] for product in pm.getProducts(): result.append({ "uid": product.UID, "title": product.Title, }) # Get start page b_start = self.request.get('b_start', 0) if b_start == "None": b_start = 0 batch = Batch(result, 20, int(b_start), orphan=0) # Calculate Batch return { "batch": batch, "next_url": self._getNextUrl(batch), "previous_url": self._getPreviousUrl(batch) }
def __call__(self): """getFolderContents alternative for life reflectors. This should return brain-like objects. """ return Batch(self.context.values(), 100, int(self.request.get("b_start", 0)), orphan=0)
def _viewSortWeblogEntriesToDates(self): """Helper calling setWeblogEntriesToDates of the weblog view.""" from Products.CMFPlone import Batch from zope.component import getMultiAdapter entries = self.weblog.getEntries() batch = Batch(entries, 10, 0, orphan=1) view = getMultiAdapter((self.weblog, self.app.REQUEST), name='weblog_view') return view.sortWeblogEntriesToDates(batch)
def getFolderContents(self, contentFilter=None, batch=False, b_size=100, full_objects=False): """Override getFolderContents to show all objects""" contents = self.listFolderContents(contentFilter=contentFilter) if batch: from Products.CMFPlone import Batch b_start = self.REQUEST.get('b_start', 0) batch = Batch(contents, b_size, int(b_start), orphan=0) return batch return contents
def getBatchedEmployees(self): b_size = 10 employees = self.context.getEmployees() if self.request.get('all', None): b_size = 9999 from Products.CMFPlone import Batch b_start = self.request.get('b_start', 0) batch = Batch(employees, b_size, int(b_start), orphan=0) return batch
def _getBatch(self): """ """ fi = self.getFormatInfo() products_per_page = fi.get("lines_per_page") *\ fi.get("products_per_line") # Important: First all products are needed to be able to calculate the # batch. products = self._getAllProducts() b_start = self.request.get('b_start', 0) return Batch(products, products_per_page, int(b_start), orphan=0)
def getRedirections(self): """Returns all stored redirections. """ storage = getUtility(IRedirectionStorage) result = [] for old_path, new_path in storage._paths.items(): result.append({"old_path": old_path, "new_path": new_path}) # Get start page b_start = self.request.get('b_start', 0) amount = self.request.get("amount", 20) # Calculate Batch return Batch(result, int(amount), int(b_start), orphan=0)
def datasetslisting(self): """ Render the datasets listing section. Accepted parameters: - Batch range - filters - ajax ... render only list - uuid + ajax ... render only one entry """ # FIXME: decide AdvancedQuery or not; need to do some performance tests with ManagedIndex and Incrementalsearch offered by AQ USE_AQ = False if USE_AQ: query_params = self.contentFilterAQ() else: query_params = self.contentFilter() b_size = safe_int(self.request.get('b_size'), 20) b_start = safe_int(self.request.get('b_start'), 0) # get sort parameters orderby = self.request.get('datasets.filter.sort') orderby = { 'modified': ('modified', 'desc'), 'created': ('created', 'desc'), 'title': ('sortable_title', 'asc') }.get(orderby, ('modified', 'desc')) # use descending as default for last modified sorting # TODO: use different defaults for different filters? order = self.request.get('datasets.filter.order', orderby[1]) if order not in ('asc', 'desc'): order = orderby[1] pc = getToolByName(self.context, 'portal_catalog') from Products.CMFPlone import Batch if USE_AQ: # TODO: we could do multi field sorting here brains = pc.evalAdvancedQuery(query_params, ((orderby[0], order), )) else: order = {'asc': 'ascending', 'desc': 'descending'}.get(order) query_params.update({'sort_on': orderby[0], 'sort_order': order}) brains = pc.searchResults( query_params) # show_all=1?? show_inactive=show_inactive? batch = Batch(brains, b_size, b_start, orphan=0) return batch
def getEntryInDate(self,year,month,day=0,\ batch=False,b_size=0,b_start=0,\ sort_on='Date',sort_order='',\ full_objects=True): # # Return entryes in specific month,or day # Used for calender portlet and # # Make dictionary for query arguments path = {} path['query'] = '/'.join(self.getPhysicalPath()) path['depth'] = 1 s_args = {} s_args['meta_type'] = [coreblogentry_meta_type] s_args['path'] = path if day: startday = day endday = day else: #Find month daycount startday = 1 endday = calendar.monthrange(year,month)[1] start_date = DateTime("%d-%d-%d 00:00:00" % (year,month,startday)) end_date = DateTime("%d-%d-%d 23:59:59" % (year,month,endday)) if DateTime() < end_date: # Hide future entries end_date = DateTime() s_args['Date'] = { "query": [start_date, end_date], "range": "minmax" } s_args['sort_on'] = sort_on s_args['sort_order'] = sort_order # Initialize list to return objs = self.portal_catalog(show_inactive=False, **s_args) if full_objects: objs = [b.getObject() for b in objs] if batch: from Products.CMFPlone import Batch batch = Batch(objs, b_size, int(b_start), orphan=0) return batch return objs
def getEntryInCategory(self,category_ids,\ sort_on='Date',sort_order='',\ batch=False,b_size=0,b_start=0,\ full_objects=True): # # Return entryes in specific category(s) # # Make dictionary for query arguments path = {} path['query'] = '/'.join(self.getPhysicalPath()) path['depth'] = 1 args = {} args['path'] = path args['meta_type'] = [coreblogentry_meta_type] category_ids_s = [str(category_ids[0])] args['getEntry_categories'] = category_ids_s args['meta_type'] = [coreblogentry_meta_type] args['sort_on'] = sort_on args['sort_order'] = sort_order # Initialize list to return objs = self.portal_catalog(show_inactive=False,**args) if len(category_ids) > 1: for chk_cat in category_ids[1:]: objs = [ o for o in objs if str(chk_cat) in o.getObject().entry_categories ] if full_objects: objs = [b.getObject() for b in objs] if batch: from Products.CMFPlone import Batch batch = Batch(objs,b_size, int(b_start), orphan=0) return batch return objs
##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters=REQUEST=None,show_all=0,quote_logic=0,quote_logic_indexes=['SearchableText','Description','Title'],use_types_blacklist=False,show_inactive=False,use_navigation_root=False,contentFilter=None,batch=False,b_size=100,full_objects=False,is_month_view=False ##title=wraps the portal_catalog with a rules qualified query ## #import pdb #pdb.set_trace() from ubify.smartview import getResults from ubify.smartview import getQValue from ubify.smartview import getProcessResultForTimeLineView results=[] results = getResults(context) if full_objects: results = [b.getObject() for b in results] if is_month_view: results = [b.getObject() for b in results] results = getProcessResultForTimeLineView(results) if batch: from Products.CMFPlone import Batch b_start = context.REQUEST.get('b_start', 0) batch = Batch(results, b_size, int(b_start), orphan=0) return batch return results
## Script (Python) "getObjectsFromPathList" ##bind container=container ##bind context=context ##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters=paths=[],batch=False,b_size=100 ##title=method to turn a list of paths into a list of objects from zExceptions import Forbidden if container.REQUEST.get('PUBLISHED') is script: raise Forbidden('Script may not be published.') contents = [] portal = context.portal_url.getPortalObject() for path in paths: obj = portal.restrictedTraverse(str(path), None) if obj is not None: contents.append(obj) if batch: from Products.CMFPlone import Batch b_start = context.REQUEST.get('b_start', 0) batch = Batch(contents, b_size, int(b_start), orphan=0) return batch return contents
def batch_results(self): """Wrap all results in a batch""" results = self._list_results() batch = Batch(results, BATCH_SIZE, int(self.batch_start), orphan=1) return batch
def batch_results(self, b_size): from Products.CMFPlone import Batch b_start = self.context.REQUEST.get('b_start', 0) batch = Batch(self.results, b_size, int(b_start), orphan=0) return batch
def batch(self): results = self.item_list() b_size = self.request.get('b_size', self.batch_size) b_start = self.request.get('b_start', 0) return Batch(results, b_size, int(b_start), orphan=1)
path['query'] = cur_path path['depth'] = 1 contentFilter['path'] = path show_inactive = mtool.checkPermission('Access inactive portal content', context) # Provide batching hints to the catalog b_start = int(context.REQUEST.get('b_start', 0)) contentFilter['b_start'] = b_start if batch: contentFilter['b_size'] = b_size # Evaluate in catalog context because some containers override queryCatalog # with their own unrelated method (Topics) contents = context.portal_catalog.queryCatalog( contentFilter, show_all=1, show_inactive=show_inactive, ) if full_objects: contents = [b.getObject() for b in contents] if batch: from Products.CMFPlone import Batch batch = Batch(contents, b_size, b_start, orphan=0) return batch return contents
def _data(self): portal_types = self.request.get('portal_type', None) if not portal_types: portal_types = [pt['id'] for pt in self.listEnabledTypes()] query_path = self.request.get('path') or \ "/".join(self.navigation_root.getPhysicalPath()) query_path = unquote(query_path) b_start = self.request.get('b_start', 0) query_text = unquote(self.request.get('SearchableText', '')) if query_text: depth = 10 else: depth = 1 if not self.readitems: results = [] else: try: query = { 'portal_type': portal_types, 'path': { "query": query_path, 'depth': depth }, 'sort_on': 'sortable_title', 'sort_order': 'ascending' } if not HAS_PAM: query['Language'] = 'all' if query_text.strip(): query['SearchableText'] = query_text results = self.catalog(**query) # alternative: sort_order='reverse', sort_on='modified' except ParseError: results = [] # setup description cropping cropText = getMultiAdapter((self.context, self.request), name=u'plone').cropText props = getMultiAdapter((self.context, self.request), name=u'plone_tools').properties() site_properties = props.site_properties desc_length = getattr(site_properties, 'search_results_description_length', 25) desc_ellipsis = getattr(site_properties, 'ellipsis', '...') items = [] batch = Batch(results, self.limit, int(b_start), orphan=1) idnormalizer = queryUtility(IIDNormalizer) for result in batch: cssType = idnormalizer.normalize(result.portal_type) items.append({ 'UID': result.UID, 'icon': result.getIcon, 'title': result.Title or result.getId, 'description': cropText(result.Description, desc_length, desc_ellipsis), 'type': result.Type, 'folderish': result.is_folderish, 'target_url': result.getURL(), 'path': result.getPath(), 'link_css_class': 'state-%s' % result.review_state, 'cssType': 'contenttype-%s' % cssType, }) return { 'items': items, 'batch': batch, 'query': bool(query_text), 'query_text': query_text, 'path': query_path, }