def getObjectInfo(item, request): """ Object info """ plone_utils = getToolByName(item, 'plone_utils') wf_tool = getToolByName(item, 'portal_workflow') state = getMultiAdapter((item, request), name="plone_context_state") item_type_class = plone_utils.normalizeString(item.portal_type) item_wf_state = wf_tool.getInfoFor(item, 'review_state', '') item_wf_state_class = 'state-' + plone_utils.normalizeString(item_wf_state) url = state.view_url() mimetype = item.get_content_type() imgview = queryMultiAdapter((item, request), name='imgview') info = { 'title': item.Title(), 'uid': item.UID(), 'description': item.Description(), 'url': url, 'absolute_url': item.absolute_url(), 'has_img': imgview != None and imgview.display() is True, 'is_video': MIVideo.providedBy(item), 'item_type': item.portal_type, 'item_mimetype': mimetype, 'item_type_class': item_type_class, 'item_wf_state': item_wf_state, 'item_wf_state_class': item_wf_state_class } return info
def __init__(self, context, request): super(DocumentRelated, self).__init__(context, request) # self.context = utils.context(self) self.plone_utils = getToolByName(context, 'plone_utils') self.normalize = self.plone_utils.normalizeString self.portal_props = getToolByName(context, 'portal_properties') self.wf_tool = getToolByName(context, 'portal_workflow') self.site_props = self.portal_props.site_properties self.use_view = getattr(self.site_props, 'typesUseViewActionInListings', []) self.related = IRelations(self.context).references() self.related_feeds = [] self.related_pages = [] self.related_media_with_player = [] self.related_other = [] self.related_images = [] for item in self.related: if MIVideo.providedBy(item): self.related_media_with_player.append(item) elif item.portal_type == 'Image': self.related_images.append(item) elif item.portal_type in [ 'Document', 'Highlight', 'PressRelease', 'Speech', 'AssessmentPart' ]: self.related_pages.append(item) else: self.related_other.append(item)
def other(self): """ Other """ other = [] for item in self.related_other: item_type_class = self.normalize(item.portal_type) item_wf_state = self.wf_tool.getInfoFor(item, 'review_state', '') item_wf_state_class = 'state-' + self.normalize(item_wf_state) urlview = getMultiAdapter((item, self.request), name="url") imgview = queryMultiAdapter((item, self.request), name="imgview") url = urlview.listing_url() other.append({'title': item.Title(), 'description': item.Description(), 'url': url, 'absolute_url': item.absolute_url(), 'item_type': item.portal_type, 'item_type_class': item_type_class, 'item_wf_state': item_wf_state, 'item_wf_state_class': item_wf_state_class, 'is_video': MIVideo.providedBy(item), 'has_img': (imgview is not None and imgview.display() is True) }) return other
def __init__(self, context, request): super(DocumentRelated, self).__init__(context, request) # self.context = utils.context(self) self.plone_utils = getToolByName(context, 'plone_utils') self.normalize = self.plone_utils.normalizeString self.portal_props = getToolByName(context, 'portal_properties') self.wf_tool = getToolByName(context, 'portal_workflow') self.site_props = self.portal_props.site_properties self.use_view = getattr(self.site_props, 'typesUseViewActionInListings', []) self.related = IRelations(self.context).references() self.related_feeds = [] self.related_pages = [] self.related_media_with_player = [] self.related_other = [] self.related_images = [] for item in self.related: if MIVideo.providedBy(item): self.related_media_with_player.append(item) elif item.portal_type == 'Image': self.related_images.append(item) elif item.portal_type in ['Document', 'Highlight', 'PressRelease', 'Speech', 'AssessmentPart']: self.related_pages.append(item) else: self.related_other.append(item)
def getObjectInfo(item, request): """ Object info """ plone_utils = getToolByName(item, 'plone_utils') wf_tool = getToolByName(item, 'portal_workflow') state = getMultiAdapter((item, request), name="plone_context_state") item_type_class = plone_utils.normalizeString(item.portal_type) item_wf_state = wf_tool.getInfoFor(item, 'review_state', '') item_wf_state_class = 'state-' + plone_utils.normalizeString(item_wf_state) url = state.view_url() mimetype = item.get_content_type() imgview = queryMultiAdapter((item, request), name='imgview') info = {'title': item.Title(), 'uid': item.UID(), 'description': item.Description(), 'url': url, 'absolute_url': item.absolute_url(), 'has_img': imgview != None and imgview.display() is True, 'is_video': MIVideo.providedBy(item), 'item_type': item.portal_type, 'item_mimetype': mimetype, 'item_type_class': item_type_class, 'item_wf_state': item_wf_state, 'item_wf_state_class': item_wf_state_class} return info
def getItems(self, portal_type=None, getBrains=False, considerDeprecated=True, constraints=None, theme=None): """ Items """ catalog = getToolByName(self.context, 'portal_catalog') query = {'sort_on': 'effective', 'sort_order': 'reverse', 'effectiveRange': DateTime()} if getattr(self.context, 'getLanguage', None): query['Language'] = self.context.getLanguage() if theme: if considerDeprecated: # 13986 ExternalDataSpec Theme doesn't have nondepregated_tags contextThemes = getattr(theme, 'nondeprecated_tags', None) if not contextThemes: contextThemes = theme.tags else: contextThemes = theme.tags query['getThemes'] = contextThemes queryThemesSeparately = False if constraints: # add 1 more to limit since we might get contextPath as result if constraints.get('sort_limit'): constraints['sort_limit'] += 1 if constraints.get('queryThemesSeparately'): queryThemesSeparately = True query.update(constraints) if portal_type: # Highlights and Press releases are usually listed together if portal_type in ['Highlight', 'PressRelease']: portal_type = ['Highlight', 'PressRelease'] elif (portal_type == 'File' and IVideo.providedBy(self.context)): query['object_provides'] = 'eea.mediacentre.interfaces.IVideo' query['portal_type'] = portal_type res = [] # split getThemes query only if we have the queryThemesSeparately flag # enabled if theme and queryThemesSeparately: for item in contextThemes: query['getThemes'] = item res.extend(catalog.searchResults(query)) brains = res else: brains = catalog.searchResults(query) contextPath = '/'.join(self.context.getPhysicalPath()) if getBrains: return [brain for brain in brains if brain.getPath() != contextPath] else: return [brain.getObject() for brain in brains if brain.getPath() != contextPath]
def promotions(self, section=None): """ Promotions """ currentTheme = getTheme(self.context) catalog = getToolByName(self.context, 'portal_catalog') promotions = [] now = DateTime() result = catalog({ 'object_provides': { 'query': [ 'eea.promotion.interfaces.IPromoted', 'Products.EEAContentTypes.content.interfaces.IExternalPromotion', ], 'operator': 'or', }, 'review_state': 'published', 'effectiveRange' : now, }) for brain in result: obj = brain.getObject() promo = queryAdapter(obj, IPromotion) if not promo: continue if not promo.display_on_themepage: continue if not promo.themes or not currentTheme == promo.themes[0]: continue if (section is not None) and (section != promo.themepage_section): continue if (section is not None) or \ (section is None and \ promo.themepage_section in [None, 'default']): uid = brain.getId ids = [i['id'] for i in promotions] count = 0 while uid in ids: count += 1 new_id = uid + '-' + str(count) if not new_id in ids: uid = new_id promotions.append({ 'id' : uid, 'Description' : brain.Description, 'Title' : brain.Title, 'url' : promo.url, 'absolute_url' : brain.getURL(), 'is_video' : IVideo.providedBy(obj), }) return promotions
def other(self): """ Other """ other = [] for item in self.related_other: item_type_class = self.normalize(item.portal_type) item_wf_state = self.wf_tool.getInfoFor(item, 'review_state', '') item_wf_state_class = 'state-' + self.normalize(item_wf_state) urlview = getMultiAdapter((item, self.request), name="url") imgview = queryMultiAdapter((item, self.request), name="imgview") url = urlview.listing_url() other.append({ 'title': item.Title(), 'description': item.Description(), 'url': url, 'absolute_url': item.absolute_url(), 'item_type': item.portal_type, 'item_type_class': item_type_class, 'item_wf_state': item_wf_state, 'item_wf_state_class': item_wf_state_class, 'is_video': MIVideo.providedBy(item), 'has_img': (imgview is not None and imgview.display() is True) }) return other
def getItems(self, portal_type=None, getBrains=False, considerDeprecated=True, constraints=None, theme=None): """ Items """ catalog = getToolByName(self.context, 'portal_catalog') query = { 'sort_on': 'effective', 'sort_order': 'reverse', 'effectiveRange': DateTime() } if getattr(self.context, 'getLanguage', None): query['Language'] = self.context.getLanguage() if theme: if considerDeprecated: # 13986 ExternalDataSpec Theme doesn't have nondepregated_tags contextThemes = getattr(theme, 'nondeprecated_tags', None) if not contextThemes: contextThemes = theme.tags else: contextThemes = theme.tags query['getThemes'] = contextThemes queryThemesSeparately = False if constraints: # add 1 more to limit since we might get contextPath as result if constraints.get('sort_limit'): constraints['sort_limit'] += 1 if constraints.get('queryThemesSeparately'): queryThemesSeparately = True query.update(constraints) if portal_type: # Highlights and Press releases are usually listed together if portal_type in ['Highlight', 'PressRelease']: portal_type = ['Highlight', 'PressRelease'] elif (portal_type == 'File' and IVideo.providedBy(self.context)): query['object_provides'] = 'eea.mediacentre.interfaces.IVideo' query['portal_type'] = portal_type res = [] # split getThemes query only if we have the queryThemesSeparately flag # enabled if theme and queryThemesSeparately: for item in contextThemes: query['getThemes'] = item res.extend(catalog.searchResults(query)) brains = res else: brains = catalog.searchResults(query) contextPath = '/'.join(self.context.getPhysicalPath()) if getBrains: return [ brain for brain in brains if brain.getPath() != contextPath ] else: return [ brain.getObject() for brain in brains if brain.getPath() != contextPath ]