def _data(self): catalog = getToolByName(self.context, 'portal_catalog') portal = getToolByName(self.context, 'portal_url').getPortalObject() query = {'sort_on': 'Date', 'sort_order': 'reverse', 'portal_type': ('News Item','PressClip', 'PressRelease'), 'review_state': 'published', 'sort_limit': self.data.number_of_items+1, 'is_relatable': True, } active_field_ids = self.data.which_fields_relate # (not doing this in a loop bc getting the ph_field_* methods might be a little ugly looking) if "ph_field_1" in active_field_ids: query['ph_field_1'] = ph_field_1(self.context, portal) if "ph_field_2" in active_field_ids: query['ph_field_2'] = ph_field_2(self.context, portal) if "ph_field_3" in active_field_ids: query['ph_field_3'] = ph_field_3(self.context, portal) if "ph_field_4" in active_field_ids: query['ph_field_4'] = ph_field_4(self.context, portal) # weed out the current page me = self.context.absolute_url() results = [b for b in catalog(**query) if b.getURL() != me] return results[:self.data.number_of_items]
def _data(self): catalog = getToolByName(self.context, 'portal_catalog') portal = getToolByName(self.context, 'portal_url').getPortalObject() query = { 'sort_on': 'start', 'portal_type': 'Event', 'review_state': 'published', 'end': { 'query': DateTime(), 'range': 'min' }, 'sort_limit': self.data.number_of_items + 1, 'is_relatable': True, } active_field_ids = self.data.which_fields_relate # (not doing this in a loop bc getting the ph_field_* methods might be a little ugly looking) if "ph_field_1" in active_field_ids: query['ph_field_1'] = ph_field_1(self.context, portal) if "ph_field_2" in active_field_ids: query['ph_field_2'] = ph_field_2(self.context, portal) if "ph_field_3" in active_field_ids: query['ph_field_3'] = ph_field_3(self.context, portal) if "ph_field_4" in active_field_ids: query['ph_field_4'] = ph_field_4(self.context, portal) # weed out the current page me = self.context.absolute_url() results = [b for b in catalog(**query) if b.getURL() != me] return results[:self.data.number_of_items]
def _data(self): catalog = getToolByName(self.context, 'portal_catalog') portal = getToolByName(self.context, 'portal_url').getPortalObject() query = {'portal_type': self.data.which_content_types, 'review_state': 'published', 'is_relatable': True, } if self.data.tie_breaker == TIEBREAKER_DATE: query['sort_on'] = 'Date' query['sort_limit'] = 1 query['sort_order'] = 'reverse' active_field_ids = self.data.which_fields_relate # (not doing this in a loop bc getting the ph_field_* methods might be a little ugly looking) if "ph_field_1" in active_field_ids: query['ph_field_1'] = ph_field_1(self.context, portal) if "ph_field_2" in active_field_ids: query['ph_field_2'] = ph_field_2(self.context, portal) if "ph_field_3" in active_field_ids: query['ph_field_3'] = ph_field_3(self.context, portal) if "ph_field_4" in active_field_ids: query['ph_field_4'] = ph_field_4(self.context, portal) # for now we won't weed out the current page -- unlikely to be an issue results = catalog(**query) if not results: return None else: if self.data.tie_breaker == TIEBREAKER_RANDOM: item = random.choice(results) else: item = results[0] return item.getObject()
def _data(self): catalog = getToolByName(self.context, 'portal_catalog') portal = getToolByName(self.context, 'portal_url').getPortalObject() query = { 'portal_type': self.data.which_content_types, 'review_state': 'published', 'is_relatable': True, } if self.data.tie_breaker == TIEBREAKER_DATE: query['sort_on'] = 'Date' query['sort_limit'] = 1 query['sort_order'] = 'reverse' active_field_ids = self.data.which_fields_relate # (not doing this in a loop bc getting the ph_field_* methods might be a little ugly looking) if "ph_field_1" in active_field_ids: query['ph_field_1'] = ph_field_1(self.context, portal) if "ph_field_2" in active_field_ids: query['ph_field_2'] = ph_field_2(self.context, portal) if "ph_field_3" in active_field_ids: query['ph_field_3'] = ph_field_3(self.context, portal) if "ph_field_4" in active_field_ids: query['ph_field_4'] = ph_field_4(self.context, portal) # for now we won't weed out the current page -- unlikely to be an issue results = catalog(**query) if not results: return None else: if self.data.tie_breaker == TIEBREAKER_RANDOM: item = random.choice(results) else: item = results[0] return item.getObject()
def testIndexMethods(self): self.failUnless(ph_field_1(self.homey, self.portal) == ('a',)) self.failUnless(ph_field_2(self.homey, self.portal) == ('b',)) # these fields aren't enabled (by default) so they should return None self.failUnless(ph_field_3(self.homey, self.portal) == ()) self.failUnless(ph_field_4(self.homey, self.portal) == ())
def testIndexMethods(self): self.failUnless(ph_field_1(self.homey, self.portal) == ('a', )) self.failUnless(ph_field_2(self.homey, self.portal) == ('b', )) # these fields aren't enabled (by default) so they should return None self.failUnless(ph_field_3(self.homey, self.portal) == ()) self.failUnless(ph_field_4(self.homey, self.portal) == ())