def _findResults(self): """Put all matching links into self._results. """ # TODO: hier geht's weiter... :) context = utils.context(self) portal_catalog = getToolByName(context, 'portal_catalog') path = '/'.join(context.getPhysicalPath()) contentType = 'AzPage' query = {'sort_on': 'sortable_title'} query['path'] = path query['portal_type'] = contentType if self.startLetter: query['getFirstLetter'] = self.startLetter if self.searchText: query['SearchableText'] = self.searchText if self.category and self.category != ['Alle Kategorien']: query['getSelectedCategory'] = self.category if self.zipcategory and self.zipcategory != ['Alle Bereiche']: query['getSelectedZipCategory'] = self.zipcategory try: results = portal_catalog.searchResults(query) except ParseTree.ParseError: results = [] if results is None: # fix in case results is `None` results = [] self._results = results
def results(self): """Return results ordered by a..z. The results will be a list of dictionaries with keys 'letter' and 'lines'. Each result item will be a dictionary with a title and a link key. """ context = utils.context(self) membership = getToolByName(context, 'portal_membership') # check the necessary permissions on the folder not the object itself can_edit = membership.checkPermission(cmfperms.ModifyPortalContent, context) resultlist = [] for item in self._results: # Grab the things we want from the item: dictItem = {} dictItem['title'] = item.Title dictItem['desc'] = item.Description dictItem['link'] = item.getURL dictItem['types'] = item.getObject().getSelectedEventtype dictItem['providers'] = item.getObject().getSelectedEventprovider dictItem['fee'] = item.getObject().getWekaeventFee dictItem['city'] = item.getWekaeventCity dictItem['startdate'] = item.getObject().getWekaEventStartDate dictItem['zipcode'] = item.getObject().getWekaeventZIP resultlist.append(dictItem) return resultlist
def _findResults(self): """Put all matching links into self._results. """ context = utils.context(self) portal_catalog = getToolByName(context, 'portal_catalog') path = '/'.join(context.getPhysicalPath()) contentType = 'WekaEvent' reviewState =['published',] datefilter={'query':DateTime(), 'range': 'min'} query = {'sort_on': 'sortable_title'} query['path'] = path query['portal_type'] = contentType query['review_state'] = reviewState query['getWekaEventStartDate'] = datefilter if self.startLetter: query['getFirstLetter'] = self.startLetter if self.searchText: query['SearchableText'] = self.searchText if self.eventtype and self.eventtype != ['Alle Veranstaltungen']: query['getSelectedEventtype'] = self.eventtype if self.eventzip and self.eventzip != ['Alle Bereiche']: query['getSelectedEventzip'] = self.eventzip if self.eventprovider and self.eventprovider != ['Alle Anbieter']: query['getSelectedEventprovider'] = self.eventprovider try: results = portal_catalog.searchResults(query) except ParseTree.ParseError: results = [] if results is None: # fix in case results is `None` results = [] self._results = results
def __init__(self, *args, **kwargs): utils.BrowserView.__init__(self, *args, **kwargs) self._results = [] self.startLetter = self.request.get("startLetter", None) self.category = self.request.get("category", None) self.searchText = self.request.get("searchText", None) if self.startLetter or self.category or self.searchText: self._findResults() context = utils.context(self) self.context_url = context.absolute_url()
def results(self): """ """ context = utils.context(self) putils = getToolByName(context, 'plone_utils') portal_catalog = getToolByName(context, 'portal_catalog') typesToShow = ['Publication'] return self.request.get( 'items', portal_catalog.searchResults(sort_on='modified', portal_type=typesToShow, sort_order='reverse', sort_limit=5)[:5])
def __init__(self, *args, **kwargs): utils.BrowserView.__init__(self, *args, **kwargs) self._results = [] self.startLetter = self.request.get('startLetter', None) self.eventtype = self.request.get('eventtype', None) self.eventprovider = self.request.get('eventprovider', None) self.eventzip = self.request.get('eventzip', None) self.searchText = self.request.get('searchText', None) if self.startLetter or self.eventtype or self.eventprovider or self.eventzip or self.searchText: self._findResults() context = utils.context(self) self.context_url = context.absolute_url()
def zipcategories(self): """Return a list of zip code categories. Each category will be a dictinary with a title and a searchLink key """ context = utils.context(self) cats = list(context.getZipcategories()) # Add 'all' cats.append('Alle Bereiche') cats.sort() return cats
def categories(self): """Return a list of categories. Each category will be a dictionary with a title and a searchLink key. """ context = utils.context(self) cats = list(context.getCategories()) # Add 'all' cats.append('Alle Kategorien') cats.sort() return cats
def eventproviders(self): """Return a list of categories. Each category will be a dictionary with a title and a searchLink key. """ context = utils.context(self) cats = list(context.getEventproviders()) # Add 'all' cats.append('Alle Anbieter') cats.sort() return cats
def results(self): """Return results ordered by a..z. The results will be a list of dictionaries with keys 'letter' and 'lines'. Each result item will be a dictionary with a title and a link key. """ context = utils.context(self) membership = getToolByName(context, 'portal_membership') # check the necessary permissions on the folder not the object itself can_edit = membership.checkPermission(cmfperms.ModifyPortalContent, context) letterCollectionMap = {} for item in self._results: firstLetter = item.getFirstLetter if not firstLetter: continue letterCollection = letterCollectionMap.get( firstLetter, []) # Grab the things we want from the item: dictItem = {} dictItem['title'] = item.Title dictItem['desc'] = item.Description dictItem['link'] = item.getURL dictItem['premium'] =item.getObject().getIsPremiumEntry dictItem['city'] = item.getObject().getOrgCity dictItem['zipcode'] = item.getObject().getOrgZIP dictItem['logo'] = item.getObject().getOrgLogo if can_edit: dictItem['edit_link'] = item.getURL() + '/edit' letterCollection.append(dictItem) letterCollectionMap[firstLetter] = letterCollection lettersFound = letterCollectionMap.keys() lettersFound.sort() output = [] for letter in lettersFound: uppercaseLetter = letter.upper() lines = letterCollectionMap[letter] output.append({'letter': uppercaseLetter, 'lines': lines}) return output
def categories(self): """Return a list of categories. Each category will be a dictionary with a title and a searchLink key. """ context = utils.context(self) cats = list(context.getGlossaryCategories()) # Add 'all' cats.append("Alle Kategorien") cats.sort() results = [] for cat in cats: item = {} item["title"] = cat item["searchLink"] = generateLink(self.context_url, "category", cat) results.append(item) return results
def _findResults(self): """Put all matching links into self._results. """ context = utils.context(self) portal_catalog = getToolByName(context, "portal_catalog") path = "/".join(context.getPhysicalPath()) contentType = "glossaryItem" query = {"sort_on": "sortable_title"} query["path"] = path query["portal_type"] = contentType if self.startLetter: query["getDefFirstLetter"] = self.startLetter if self.searchText: query["SearchableText"] = self.searchText try: results = portal_catalog.searchResults(query) except ParseTree.Error: results = [] if self.category and self.category != "Alle Kategorien": results = [r for r in results if self.category in r.getDefSelectedCategory] self._results = results
def results(self): """Return results ordered by a..z. The results will be a list of dictionaries with keys 'letter' and 'lines'. Each result item will be a dictionary with a title and a link key. """ context = utils.context(self) membership = getToolByName(context, "portal_membership") # acquire permissions from the parent folder # to avoid performance issues can_edit = membership.checkPermission(cmfperms.ModifyPortalContent, context) letterCollectionMap = {} for item in self._results: firstLetter = item.getDefFirstLetter if not firstLetter: continue letterCollection = letterCollectionMap.get(firstLetter, []) # Grab the things we want from the item: dictItem = {} dictItem["title"] = item.Title dictItem["link"] = item.getURL if can_edit: dictItem["edit_link"] = item.getURL() + "/edit" letterCollection.append(dictItem) letterCollectionMap[firstLetter] = letterCollection lettersFound = letterCollectionMap.keys() lettersFound.sort() output = [] for letter in lettersFound: uppercaseLetter = letter.upper() lines = letterCollectionMap[letter] output.append({"letter": uppercaseLetter, "lines": lines}) return output
def getNavRoot(self): """ Override """ if not utils.base_hasattr(self, '_root'): self._root = [getApplicationRoot(utils.context(self))] return self._root[0]
def getAd(self, object=False, slot=None, template=None, ad_types=['Ad']): """Retrieve an ad from the ad manager """ context = utils.context(self) catalog_tool = getToolByName(context, 'ad_catalog') prop_tool = getToolByName(context, 'portal_properties') ad_states = prop_tool.promo_engine_properties.ad_states ads = [] unique_objects = [] unique_slots = [] # get the ads based on the object's references if object: # try and except in case the object doesn't support references try: raw_object_ads = object.getBRefs('AdLocation') object_ads = LazyFilter(raw_object_ads, skip='View') # ads of a given type filtered_ads = [obj for obj in object_ads \ if obj.portal_type in ad_types] wf_tool = getToolByName(context, 'portal_workflow') # get ads of workflow states defined in the properties published_object_ads = [obj for obj in filtered_ads \ if wf_tool.getInfoFor(obj,'review_state',None) in ad_states] unique_objects = [item.UID() for item in published_object_ads] except AttributeError: # if the object doesn't support refs then set object to none # so we can still use slots on that object object = None # get the ads based the slot wanted if slot: query = {'portal_type':ad_types, 'getAdSlot':slot, 'review_state':ad_states} slot_ads = catalog_tool.searchResults(query) unique_slots = [item.UID for item in slot_ads] # see if there is a call for a slot and an object and get the # unique results. Otherwise get the unique_slots or unique_objects if object is not False and slot: # Check to see if the context given is None if object is not None: ads = [item for item in unique_objects if item in unique_slots] else: # we had no context. return empty. ads = [] elif slot: ads = unique_slots elif object: ads = unique_objects # if there are ads then choose one and then get the object if ads: uidtool = getToolByName(context, 'uid_catalog') # TODO: could optionaly use some 80/20 type functionality here ad_uid = random.choice(ads) query = {'UID':ad_uid} ad_brains = uidtool(query) for brain in ad_brains: ad_obj = brain.getObject() # otherwise return and empty macro else: ad_obj = None macro = template.pt_macros()['empty'] return macro # look for the context in the stack frame = sys._getframe() try: econtext = _marker while econtext is _marker and frame is not None: econtext = frame.f_locals.get('econtext', _marker) frame = frame.f_back if econtext is _marker: raise RuntimeError, 'Context not found' finally: del frame econtext.setLocal('ad', ad_obj) macro = template.pt_macros()['view'] return macro