Exemplo n.º 1
0
 def getKeyFacts(self, topic=False):
     """ Get keyfacts DEPRECATED, to be removed in the future
     """
     ret = []
     catalog = getToolByName(self.context, 'portal_catalog')
     theme = None
     if topic:
         theme = getTheme(self.context)
     query = {
         'portal_type': 'SoerKeyFacts',
     }
     if theme:
         query['getThemes'] = theme
     brains = catalog.searchResults(query)
     for brain in brains:
         obj = brain.getObject()
         parent = obj.aq_parent
         text = self._prepareText(brain)
         ret.append({
             'text': text,
             'url': brain.getURL(),
             'parent_url': parent.absolute_url(),
             'parent_title': parent.Title(),
             'effective': SoerFrontpage.getEffective(brain),
         })
     return ret
Exemplo n.º 2
0
def _getItems(self,
              visibilityLevel=None,
              portaltypes=None,
              interfaces=None,
              noOfItems=6,
              language=None):
    """ generic internal method for getting items from catalog
    (via portaltypes or via interfaces) filtered by topic or not.
    """
    visibilityLevel = visibilityLevel or ''
    result = []
    #if topic is not passed in the REQUEST variable
    #then we try to get it from the context object
    topic = getattr(self.context.REQUEST, 'topic', None)
    tags = getattr(self.context.REQUEST, 'tags', None)
    topic_request = getTheme(self.context.aq_inner)
    if topic or topic_request:
        topic = topic if topic else topic_request

    if portaltypes:
        #if there is a topic/theme tag then get items filtered
        if topic:
            result = _getTopics(self,
                                portaltypes=portaltypes,
                                topic=topic,
                                noOfItems=noOfItems,
                                language=language)
        elif tags:
            result = _getTopics(self,
                                portaltypes=portaltypes,
                                tags=tags,
                                noOfItems=noOfItems,
                                language=language)
        else:
            result = _getItemsWithVisibility(self,
                                             visibilityLevel=visibilityLevel,
                                             portaltypes=portaltypes,
                                             noOfItems=noOfItems,
                                             language=language)
    elif interfaces:
        #if there is a topic/theme tag then get items filtered
        if topic:
            result = _getTopics(self,
                                object_provides=interfaces,
                                topic=topic,
                                noOfItems=noOfItems,
                                language=language)
        elif tags:
            result = _getTopics(self,
                                object_provides=interfaces,
                                tags=tags,
                                noOfItems=noOfItems,
                                language=language)
        else:
            result = _getItemsWithVisibility(self,
                                             visibilityLevel=visibilityLevel,
                                             interfaces=interfaces,
                                             noOfItems=noOfItems,
                                             language=language)
    return result
Exemplo n.º 3
0
    def getPromotedItem(self, ptype=None, itype=None):
        """ get promoted item
        """
        query = {
            'object_provides': {
                'query': ['eea.promotion.interfaces.IPromoted'],
            },
            'review_state': 'published',
            'sort_on': 'effective',
            'sort_order': 'reverse',
        }
        if itype:
            query['object_provides']['operator'] = 'and'
            query['object_provides']['query'].append(itype)
        if ptype:
            query['portal_type'] = ptype

        context = self.context.aq_inner
        query['getThemes'] = getTheme(context)
        catalog = getToolByName(context, 'portal_catalog')
        result = catalog(query)
        item = None
        for brain in result:
            item = brain.getObject()
            promo = IPromotion(item)
            if not promo.display_on_themepage:
                continue
            if not promo.active:
                continue
            break
        return item
Exemplo n.º 4
0
 def getKeyFacts(self, topic=False):
     """ Get keyfacts DEPRECATED, to be removed in the future
     """
     ret = []
     catalog = getToolByName(self.context, 'portal_catalog')
     theme = None
     if topic:
         theme = getTheme(self.context)
     query = {
         'portal_type': 'SoerKeyFacts',
     }
     if theme:
         query['getThemes'] = theme
     brains = catalog.searchResults(query)
     for brain in brains:
         obj = brain.getObject()
         parent = obj.aq_parent
         text = self._prepareText(brain)
         ret.append({
             'text': text,
             'url': brain.getURL(),
             'parent_url': parent.absolute_url(),
             'parent_title': parent.Title(),
             'effective': SoerFrontpage.getEffective(brain),
         })
     return ret
Exemplo n.º 5
0
 def getMessages(self, topic=False):
     """ Get KeyMessage which replaces Message ctype
     """
     ret = []
     catalog = getToolByName(self.context, 'portal_catalog')
     theme = ''
     if topic:
         theme = getTheme(self.context)
     query = {
         'portal_type': 'KeyMessage',
         'review_state': 'published'
     }
     if theme:
         query['getThemes'] = theme
     brains = catalog.searchResults(query)
     for brain in brains:
         text = self._prepareText(brain)
         obj = brain.getObject()
         parent = obj.aq_parent
         ret.append({
             'text': text,
             'url': brain.getURL,
             'parent_url': parent.absolute_url(),
             'parent_title': parent.Title(),
         })
     return ret
Exemplo n.º 6
0
 def media_items(self):
     """ Media items
     """
     currenttheme = getTheme(self.context)
     mcentre = queryUtility(IMediaCentre)
     if not mcentre:
         return []
     search = {MEDIA_SEARCH_KEY: {'theme': currenttheme}}
     return [mfile['object'] for mfile in mcentre.getMedia(search=search)]
Exemplo n.º 7
0
 def items(self):
     """ Items
     """
     context = self.context
     theme = getTheme(context)
     mediacentre = getUtility(IMediaCentre)
     query = {MEDIA_SEARCH_KEY: {'theme': theme, }, }
     files = mediacentre.getMedia(self.media_type, 1, search=query)
     return files
Exemplo n.º 8
0
 def media_items(self):
     """ Media items
     """
     currenttheme = getTheme(self.context)
     mcentre = queryUtility(IMediaCentre)
     if not mcentre:
         return []
     search = {MEDIA_SEARCH_KEY: {'theme': currenttheme}}
     return [mfile['object']
             for mfile in mcentre.getMedia(search=search)]
Exemplo n.º 9
0
def _getItems(self, visibilityLevel=None, portaltypes=None, interfaces=None,
                                        noOfItems=6, language=None):
    """ generic internal method for getting items from catalog
    (via portaltypes or via interfaces) filtered by topic or not.
    """
    visibilityLevel = visibilityLevel or ''
    result = []
    #if topic is not passed in the REQUEST variable
    #then we try to get it from the context object
    topic = getattr(self.context.REQUEST, 'topic', None)
    tags = getattr(self.context.REQUEST, 'tags', None)
    topic_request = getTheme(self.context.aq_inner)
    if topic or topic_request:
        topic = topic if topic else topic_request

    if portaltypes:
        #if there is a topic/theme tag then get items filtered
        if topic:
            result = _getTopics(self, portaltypes=portaltypes,
                                      topic=topic,
                                      noOfItems=noOfItems,
                                      language=language)
        elif tags:
            result = _getTopics(self, portaltypes=portaltypes,
                                            tags=tags,
                                            noOfItems=noOfItems,
                                            language=language)
        else:
            result = _getItemsWithVisibility(self,
                                            visibilityLevel=visibilityLevel,
                                            portaltypes=portaltypes,
                                            noOfItems=noOfItems,
                                            language=language)
    elif interfaces:
        #if there is a topic/theme tag then get items filtered
        if topic:
            result = _getTopics(self, object_provides=interfaces,
                                      topic=topic,
                                      noOfItems=noOfItems,
                                      language=language)
        elif tags:
            result = _getTopics(self, object_provides=interfaces,
                                      tags=tags,
                                      noOfItems=noOfItems,
                                      language=language)
        else:
            result = _getItemsWithVisibility(self,
                                            visibilityLevel=visibilityLevel,
                                            interfaces=interfaces,
                                            noOfItems=noOfItems,
                                            language=language)
    return result
Exemplo n.º 10
0
    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
Exemplo n.º 11
0
    def media_items(self):
        """ Media items
        """
        currentTheme = getTheme(self.context)
        mediacentre = getUtility(IMediaCentre)
        search = {MEDIA_SEARCH_KEY: {'theme': currentTheme}}
        files = mediacentre.getMedia(self.media_type, full_objects=False,
                                     search=search)

        videos = []
        for media_dict in files:
            videos.append(media_dict['object'])

        return videos
Exemplo n.º 12
0
    def items(self):
        """ Items
        """
        context = self.context
        portal_catalog = getToolByName(context, 'portal_catalog')
        current_theme = getTheme(context)

        if current_theme:
            self.query['getThemes'] = current_theme
            res = portal_catalog.searchResults(self.query)
        else:
            res = []

        return res
Exemplo n.º 13
0
    def items(self):
        """ Items
        """
        context = self.context
        portal_catalog = getToolByName(context, 'portal_catalog')
        current_theme = getTheme(context)

        if current_theme:
            self.query['getThemes'] = current_theme
            res = portal_catalog.searchResults(self.query)
        else:
            res = []

        return res
Exemplo n.º 14
0
def _getPromotions(self, noOfItems=6):
    """ utility function to retrieve external and internal promotions """
    query = {
        'object_provides': {
            'query': [
                'eea.promotion.interfaces.IPromoted',
                'Products.EEAContentTypes.content.interfaces.IExternalPromotion',
            ],
            'operator':
            'or',
        },
        'review_state': 'published',
        'sort_on': 'effective',
        'sort_order': 'reverse'
    }

    context = self.context.aq_inner
    themes = getTheme(context)
    if themes:
        query['getThemes'] = themes
    result = self.catalog(query)
    cPromos = []
    for brain in result:
        obj = brain.getObject()
        promo = IPromotion(obj)

        if themes:
            if not promo.display_on_themepage:
                continue
        if hasattr(context, 'layout') and \
                                    context.layout == 'frontpage_view':
            if not promo.display_on_frontpage:
                continue
        if not promo.active:
            continue

        promo_versionIds = [b.getVersionId for b in cPromos]
        # Add to promo list if we do not already have a newer version of this
        # versionId in the promo list
        if not brain.getVersionId in promo_versionIds:
            cPromos.append(brain)
        if len(cPromos) == noOfItems:
            break
    return cPromos
Exemplo n.º 15
0
def _getPromotions(self, noOfItems=6):
    """ utility function to retrieve external and internal promotions """
    query = {
        'object_provides': {
            'query': [
              'eea.promotion.interfaces.IPromoted',
              'Products.EEAContentTypes.content.interfaces.IExternalPromotion',
            ],
            'operator': 'or',
        },
        'review_state': 'published',
        'sort_on': 'effective',
        'sort_order' : 'reverse'
    }

    context = self.context.aq_inner
    themes = getTheme(context)
    if themes:
        query['getThemes'] = themes
    result = self.catalog(query)
    cPromos = []
    for brain in result:
        obj = brain.getObject()
        promo = IPromotion(obj)

        if themes:
            if not promo.display_on_themepage:
                continue
        if hasattr(context, 'layout') and \
                                    context.layout == 'frontpage_view':
            if not promo.display_on_frontpage:
                continue
        if not promo.active:
            continue

        promo_versionIds = [b.getVersionId for b in cPromos]
        # Add to promo list if we do not already have a newer version of this
        # versionId in the promo list
        if not brain.getVersionId in promo_versionIds:
            cPromos.append(brain)
        if len(cPromos) == noOfItems:
            break
    return cPromos
Exemplo n.º 16
0
    def relatedReportingObligations(self):
        """ Return a list of Reporting Obligations related to this theme
        """
        current_theme = getTheme(self.context)
        catalog = getToolByName(self.context, 'portal_catalog')
        rodbaseurl = 'http://rod.eionet.europa.eu/obligations/'
        rods = []
        rodsdone = []
        now = DateTime()
        rodsinfo = {}
        result = None
        xmlrpclib = eventlet.import_patched('xmlrpclib')

        with eventlet.timeout.Timeout(SOCKET_TIMEOUT):
            try:
                server = xmlrpclib.Server(ROD_SERVER)
                result = server.WebRODService.getROComplete()
            except Exception, err:
                logger.exception(err)
                result = []
Exemplo n.º 17
0
 def getMessages(self, topic=False):
     """ Get KeyMessage which replaces Message ctype
     """
     ret = []
     catalog = getToolByName(self.context, 'portal_catalog')
     theme = ''
     if topic:
         theme = getTheme(self.context)
     query = {'portal_type': 'KeyMessage', 'review_state': 'published'}
     if theme:
         query['getThemes'] = theme
     brains = catalog.searchResults(query)
     for brain in brains:
         text = self._prepareText(brain)
         obj = brain.getObject()
         parent = obj.aq_parent
         ret.append({
             'text': text,
             'url': brain.getURL,
             'parent_url': parent.absolute_url(),
             'parent_title': parent.Title(),
         })
     return ret
Exemplo n.º 18
0
 def getThemeName(self):
     """ Get theme name of the context to construct the url to the
         themecentre and the datacentre page
     """
     return getTheme(self.context.aq_inner)
Exemplo n.º 19
0
 def getThemeName(self):
     """ Get theme name of the context to construct the url to the
         themecentre and the datacentre page
     """
     return getTheme(self.context.aq_inner)