def items(self): """Return items according to policy""" syndtool = getUtility(ISyndicationTool) key, reverse = self.context.getDefaultSorting() items = syndtool.getSyndicatableContent(self.context) items = sort(items, ((key, 'cmp', reverse and 'desc' or 'asc'),)) items = LazyFilter(items, skip='View') items = ({'title': o.Title(), 'description': o.Description(), 'creators': o.listCreators(), 'subjects': o.Subject(), 'rights': o.Rights, 'publisher': o.Publisher(), 'url': o.absolute_url(), 'date': o.modified().rfc822(), 'uid': None} for idx, o in enumerate(items) if idx < self.synd_info['max_items']) return items
def _processRefs(self, refs, sort_on, reverse): """util method to run the refs through LazyFilter """ filtered_refs = [] if refs and refs is not None: if not isinstance(refs, list): refs = [refs] filtered_refs = list(LazyFilter(refs, skip='View')) if sort_on is not None: filtered_refs.sort(lambda x, y: cmp( x.getField(sort_on).get(x), y.getField(sort_on).get(y))) if reverse: filtered_refs.reverse() return filtered_refs
def __call__(self): res = "" for talk in self.getTalks(): res += talk.country + "\n" return res # XXX: not sure what this is about cats = {} authors = [] for talk in self.getTalks(): if talk.keywords: for keyword in talk.keywords: keyword = keyword.strip() cats[keyword] = cats.get(keyword, 0) + 1 talks = list(LazyFilter(self.context.contentValues(), skip='')) authors = set([t.name for t in talks]) return (len(authors), cats)
def getCurrencyItemList(include_empty=1, validation_state=validation_state): result = [] if include_empty: result = [ ['', ''], ] currency_module = portal.restrictedTraverse( 'currency_module', portal.restrictedTraverse('currency', None)) if currency_module is not None: for currency in LazyFilter(currency_module.contentValues(), skip=AccessContentsInformation): if currency.getProperty('validation_state', 'validated') in validation_state: # for currency, we intentionaly use reference (EUR) not title (Euros). result.append( (currency.getReference() or currency.getTitleOrId(), currency.getRelativeUrl())) result.sort(key=lambda x: x[0]) return result
options = {} options['channel_info'] = { 'base': stool.getHTML4UpdateBase(context), 'description': context.Description(), 'frequency': stool.getUpdateFrequency(context), 'period': stool.getUpdatePeriod(context), 'title': context.Title(), 'url': context.absolute_url() } key, reverse = context.getDefaultSorting() items = stool.getSyndicatableContent(context) items = sequence.sort(items, ((key, 'cmp', reverse and 'desc' or 'asc'), )) items = LazyFilter(items, skip='View') b_size = stool.getMaxItems(context) batch_obj = Batch(items, b_size, 0, orphan=0) items = [] for item in batch_obj: items.append({ 'date': item.modified().HTML4(), 'description': item.Description(), 'listCreators': item.listCreators(), 'listSubjects': item.Subject(), 'publisher': item.Publisher(), 'rights': item.Rights(), 'title': item.Title(), 'url': item.absolute_url() }) options['listItemInfos'] = tuple(items)
def _getItems(self): (key, reverse) = self.context.getDefaultSorting() items = self.context.contentValues() items = sequence.sort(items, ((key, 'cmp', reverse and 'desc' or 'asc'), )) return LazyFilter(items, skip='View')
def _makequery(self, query=None, batch=False, b_start=0, b_size=30, sort_on=None, sort_order=None, limit=0, brains=False, custom_query=None): """Parse the (form)query and return using multi-adapter""" query_modifiers = getUtilitiesFor(IQueryModifier) for name, modifier in sorted(query_modifiers, key=itemgetter(0)): query = modifier(query) parsedquery = queryparser.parseFormquery(self.context, query, sort_on, sort_order) index_modifiers = getUtilitiesFor(IParsedQueryIndexModifier) for name, modifier in index_modifiers: if name in parsedquery: new_name, query = modifier(parsedquery[name]) parsedquery[name] = query # if a new index name has been returned, we need to replace # the native ones if name != new_name: del parsedquery[name] parsedquery[new_name] = query # Check for valid indexes catalog = getToolByName(self.context, 'portal_catalog') valid_indexes = [ index for index in parsedquery if index in catalog.indexes() ] # We'll ignore any invalid index, but will return an empty set if none # of the indexes are valid. if not valid_indexes: logger.warning( "Using empty query because there are no valid indexes used.") parsedquery = {} empty_query = not parsedquery # store emptiness if batch: parsedquery['b_start'] = b_start parsedquery['b_size'] = b_size elif limit: parsedquery['sort_limit'] = limit if 'path' not in parsedquery: parsedquery['path'] = {'query': ''} if isinstance(custom_query, dict) and custom_query: # Update the parsed query with an extra query dictionary. This may # override the parsed query. The custom_query is a dictonary of # index names and their associated query values. parsedquery.update(custom_query) empty_query = False # filter bad term and operator in query parsedquery = self.filter_query(parsedquery) results = [] if not empty_query: results = catalog(**parsedquery) if getattr(results, 'actual_result_count', False) and limit\ and results.actual_result_count > limit: results.actual_result_count = limit collapse_on = self.request.get( 'collapse_on', getattr(self.context, 'collapse_on', None)) if collapse_on is not None: fc = FieldCollapser(query={'collapse_on': collapse_on}) results = LazyMap(lambda x: x, LazyFilter(results, test=fc.collapse), length=results._len, actual_result_count=results.actual_result_count) if not brains: results = IContentListing(results) if batch: results = Batch(results, b_size, start=b_start) return results
def _get_items(self): (key, reverse) = self.context.getDefaultSorting() items = self.mtool().getRoster() items = sort(items, ((key, 'cmp', reverse and 'desc' or 'asc'),)) return LazyFilter(items, skip='View')
} for node in getInventoryList(omit_asset_decrease=1, **local_inventory_params): markNodeUsed(node) total_price = getTotalPrice(node) getAccountProps(node, payment=node['payment_uid'])['debit'] = total_price total_debit += round(total_price, precision) for node in getInventoryList(omit_asset_increase=1, **local_inventory_params): markNodeUsed(node) total_price = getTotalPrice(node) getAccountProps(node, payment=node['payment_uid'])['credit'] = - total_price total_credit -= round(total_price, precision) # }}} # include all accounts, even those not selected before (no movements in the # period) for node in LazyFilter(portal.account_module.contentValues(), skip=''): # XXX: context should already be account_module if node.getRelativeUrl() not in account_used: getAccountProps( { 'node_relative_url': node.getRelativeUrl(), }, all_empty=True, ) initial_balance_date = (from_date - 1).latestTime() # Initial Balance # standards accounts {{{ # balance at period start date local_inventory_params = {
total_price = getTotalPrice(node) getAccountProps(node, payment=node['payment_uid'])['debit'] = total_price total_debit += round(total_price, precision) for node in getInventoryList(omit_asset_increase=1, **local_inventory_params): markNodeUsed(node) total_price = getTotalPrice(node) getAccountProps(node, payment=node['payment_uid'])['credit'] = -total_price total_credit -= round(total_price, precision) # }}} # include all accounts, even those not selected before (no movements in the # period) for node in LazyFilter(portal.account_module.contentValues(), skip=''): if node.getRelativeUrl() not in account_used: getAccountProps( { 'node_relative_url': node.getRelativeUrl(), }, all_empty=True, ) initial_balance_date = (from_date - 1).latestTime() # Initial Balance # standards accounts {{{ # balance at period start date local_inventory_params = {
## Script (Python) "filterObjectValues" ##bind container=container ##bind context=context ##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters=values=None ##title= ## from ZTUtils import LazyFilter from AccessControl import getSecurityManager checkPermission=getSecurityManager().checkPermission items = [] raw_items = context.objectValues(values) secure_items = LazyFilter(raw_items, skip='') for item in secure_items: if checkPermission('Access contents information', item): items.append(item) return items