Exemple #1
0
    def getResults(self):
        context = Acquisition.aq_inner(self.context)

        # try to get query parameters from Topic (if present)
        query = hasattr(context, 'buildQuery') and context.buildQuery()
        if query:
            catalog = getToolByName(context, 'portal_catalog')
            results = catalog(query)
            # filter out results that are both outdated and expired
            to_show = [
                x for x in results if not (
                    getattr(x, 'outdated', False) and isExpired(x))
            ]
            return to_show

        # otherwise construct a query
        portal_state = getMultiAdapter(
            (self.context, self.request), name=u'plone_portal_state')
        navigation_root_path = portal_state.navigation_root_path()

        oshaview = getMultiAdapter(
            (self.context, self.request), name=u'oshaview')
        mySEP = oshaview.getCurrentSingleEntryPoint()
        kw = ''

        if mySEP:
            kw = mySEP.getProperty('keyword', '')

        query = '(portal_type:("News Item") OR isNews:true) AND '
        'review_state:published AND path_parents:%s' % navigation_root_path
        if kw != '':
            query = ' AND '.join([query, 'Subject:(%s)' % ' OR '.join(kw)])
        return search_solr(query, sort='Date desc')
Exemple #2
0
    def _data(self):
        portal_languages = getToolByName(self.context, 'portal_languages')
        preflang = portal_languages.getPreferredLanguage()

        # search in the navigation root of the currently selected language and in the canonical path
        # with Language = preferredLanguage or neutral
        paths = list()
        portal_state = getMultiAdapter((self.context, self.request), name=u'plone_portal_state')
        navigation_root_path = portal_state.navigation_root_path()
        paths.append(navigation_root_path)
        try:
            navigation_root = portal_state.portal().restrictedTraverse(navigation_root_path)
            canonical_path = '/'.join(navigation_root.getCanonical().getPhysicalPath())
            paths.append(canonical_path)
        except:
            pass

        oshaview = getMultiAdapter((self.context, self.request), name=u'oshaview')
        mySEP = oshaview.getCurrentSingleEntryPoint()
        kw = ''
        if mySEP is not None:
            kw = mySEP.getProperty('keyword', '')
            
        limit = self.data.count
        state = self.data.state
        
        query = '(portal_type:"News Item" OR isNews:true) AND review_state:(%(review_state)s) AND path_parents:(%(path)s) AND Language:(%(Language)s) AND effective:[* TO %(effective)s]' % {'review_state': ' OR '.join(state), 'path': ' OR '.join(paths), 'Language': ' OR '.join([preflang, 'any']), 'effective': iso8601date(DateTime()), }
        if kw !='':
            query += ' AND Subject:(%s)' % ' OR '.join(kw)
        try:
            return search_solr(query, sort='Date desc', rows=limit)[:limit]
        except KeyError, e:
            log.error('KeyError: %s' %  e.__str__())
            return []
Exemple #3
0
    def getResults(self):
        context = Acquisition.aq_inner(self.context)

        # try to get query parameters from Topic (if present)
        query = hasattr(context, 'buildQuery') and context.buildQuery()
        if query:
            catalog = getToolByName(context, 'portal_catalog')
            results = catalog(query)
            # filter out results that are both outdated and expired
            to_show = [
                x for x in results
                if not (getattr(x, 'outdated', False) and isExpired(x))
            ]
            return to_show

        # otherwise construct a query
        portal_state = getMultiAdapter((self.context, self.request),
                                       name=u'plone_portal_state')
        navigation_root_path = portal_state.navigation_root_path()

        oshaview = getMultiAdapter((self.context, self.request),
                                   name=u'oshaview')
        mySEP = oshaview.getCurrentSingleEntryPoint()
        kw = ''

        if mySEP:
            kw = mySEP.getProperty('keyword', '')

        query = '(portal_type:("News Item") OR isNews:true) AND '
        'review_state:published AND path_parents:%s' % navigation_root_path
        if kw != '':
            query = ' AND '.join([query, 'Subject:(%s)' % ' OR '.join(kw)])
        return search_solr(query, sort='Date desc')
Exemple #4
0
    def _data(self):
        context = Acquisition.aq_inner(self.context)
        catalog = getToolByName(context, "portal_catalog")
        portal_languages = getToolByName(context, "portal_languages")
        preflang = portal_languages.getPreferredLanguage()

        # search in the navigation root of the currently selected
        # language and in the canonical path
        # with Language = preferredLanguage or neutral
        current_path = self.context.getPhysicalPath()
        if len(current_path) > 3 and current_path[3] in ("sub", "fop"):
            # in a subsite, take only the subsite or fop site
            path = "/".join(self.navigation_root_path.split("/")[:-1])
            INFOP = True
        else:
            # in the main site, limit to the events folder #7932
            path = "/osha/portal/en/events"
            INFOP = False

        oshaview = getMultiAdapter((context, self.request), name=u"oshaview")
        subsite = oshaview.getCurrentSubsite()
        # calendar = self.getCalendar(preflang)
        # # If we're in the root (i.e. no in a subiste), and a valid pointer to a
        # # calendar exists, use its path as a query parameter
        # if subsite is None and calendar:
        #     paths = ['/'.join(calendar.getPhysicalPath())]

        subject = list(self.data.subject)
        limit = self.data.count

        # make sure to exclude the subs
        query = (
            "portal_type:(Event) AND "
            "review_state:(%(review_state)s) AND path_parents:(%(path)s) "
            "AND end:[%(now)s TO *]"
            % {"review_state": " OR ".join(self.data.state), "path": path, "now": iso8601date(DateTime())}
        )

        # If a subject is selected, use that for the query
        if subject:
            query += " AND Subject:(%s)" % " OR ".join(subject)

        if INFOP:
            results = search_solr(query, sort="start asc", rows=limit)
        else:
            lf_search_view = self.context.restrictedTraverse("@@language-fallback-search")
            results = lf_search_view.search_solr(query, sort="start asc", rows=limit, lang_query=False)

        items = list()
        for res in results[:limit]:
            try:
                items.append(res.getObject())
            except AttributeError:
                pass
            if len(items) >= limit:
                break
        return items
Exemple #5
0
    def _data(self):
        """Search for news everywhere, then try to find translations in the
        current language. If no translation is found, use the 'en' version.
        """
        current_path = self.context.getPhysicalPath()
        if len(current_path) > 3 and current_path[3] in ('sub', 'fop'):
            # in a subsite, take only the subsite or fop site
            path = '/'.join(self.navigation_root_path.split('/')[:-1])
            INFOP = True
        else:
            # in the main site, exclude sub
            path = "/osha/portal AND -/osha/portal/sub AND -/osha/portal/fop"
            INFOP = False

        subject = list(self.data.subject)
        limit = self.data.count

        # make sure to exclude the subs
        query = '(portal_type:"News Item" OR isNews:true) AND ' \
            'review_state:(%(review_state)s) AND path_parents:(%(path)s) ' \
            'AND effective:[* TO %(effective)s]' % \
            {'review_state': ' OR '.join(self.data.state),
             'path': path,
             'effective': iso8601date(DateTime()), }

        if subject:
            query += ' AND Subject:(%s)' % ' OR '.join(subject)

        if INFOP:
            results = search_solr(query, sort='Date desc', rows=limit)
        else:
            lf_search_view = self.context.restrictedTraverse(
                "@@language-fallback-search")
            results = lf_search_view.search_solr(
                query, sort='Date desc', rows=limit)  # lang_query=False)
        items = list()
        for res in results[:limit]:
            if isExpired(res) and getattr(res, 'outdated', False):
                continue
            try:
                items.append(res.getObject())
            except Exception:
                pass
        return items
Exemple #6
0
    def _data(self):
        """Search for news everywhere, then try to find translations in the
        current language. If no translation is found, use the 'en' version.
        """
        current_path = self.context.getPhysicalPath()
        if len(current_path) > 3 and current_path[3] in ('sub', 'fop'):
            # in a subsite, take only the subsite or fop site
            path = '/'.join(self.navigation_root_path.split('/')[:-1])
            INFOP = True
        else:
            # in the main site, exclude sub
            path = "/osha/portal AND -/osha/portal/sub AND -/osha/portal/fop"
            INFOP = False

        subject = list(self.data.subject)
        limit = self.data.count

        # make sure to exclude the subs
        query = '(portal_type:"News Item" OR isNews:true) AND ' \
            'review_state:(%(review_state)s) AND path_parents:(%(path)s) ' \
            'AND effective:[* TO %(effective)s]' % \
            {'review_state': ' OR '.join(self.data.state),
             'path': path,
             'effective': iso8601date(DateTime()), }

        if subject:
            query += ' AND Subject:(%s)' % ' OR '.join(subject)

        if INFOP:
            results = search_solr(query, sort='Date desc', rows=limit)
        else:
            lf_search_view = self.context.restrictedTraverse(
                "@@language-fallback-search")
            results = lf_search_view.search_solr(
                query, sort='Date desc', rows=limit)  # lang_query=False)
        items = list()
        for res in results[:limit]:
            if isExpired(res) and getattr(res, 'outdated', False):
                continue
            try:
                items.append(res.getObject())
            except Exception:
                pass
        return items
 def getRecentPracticalSolutions(self):
     context = self.context
     subject = self.data.subject
     search_portal_types = [ "OSH_Link", "RALink",
                             "CaseStudy", "Provider", "Publication"]
     # Publications are Files which implement the
     # IPublicationEnhanced interface
     query = '((portal_type:File ' \
             'AND object_provides:slc.publications.interfaces.IPublicationEnhanced ' \
             'AND Subject:(%(Subject)s)) ' \
         'OR ' \
             'portal_type:(%(portal_type)s)) ' \
       'AND ' \
         'review_state:published' % {
                     'Subject': subject,
                     'portal_type': search_portal_types,
                         }
     brains = search_solr(query, sort='effective desc')
     results = self.getBrainsBySection(brains, 3)
     return results
 def getRecentPracticalSolutions(self):
     context = self.context
     subject = self.data.subject
     search_portal_types = [
         "OSH_Link", "RALink", "CaseStudy", "Provider", "Publication"
     ]
     # Publications are Files which implement the
     # IPublicationEnhanced interface
     query = '((portal_type:File ' \
             'AND object_provides:slc.publications.interfaces.IPublicationEnhanced ' \
             'AND Subject:(%(Subject)s)) ' \
         'OR ' \
             'portal_type:(%(portal_type)s)) ' \
       'AND ' \
         'review_state:published' % {
                     'Subject': subject,
                     'portal_type': search_portal_types,
                         }
     brains = search_solr(query, sort='effective desc')
     results = self.getBrainsBySection(brains, 3)
     return results
Exemple #9
0
    def getResults(self):
        context = Acquisition.aq_inner(self.context)
        catalog = getToolByName(context, 'portal_catalog')
        if hasattr(catalog, 'getZCatalog'):
            catalog = catalog.getZCatalog()

        now = DateTime()
        #queryA = Eq('portal_type', 'News Item')
        #queryB = Eq('isNews', True)
        #queryBoth = In('review_state', 'published') & \
        #Eq('path', '/'.join(context.getPhysicalPath())) \
        #    & Le('effective', now)

        #query = And(Or(queryA, queryB), queryBoth)
        #oldresults = catalog.evalAdvancedQuery(query, (('Date', 'desc'),))

        query = '(portal_type:("News Item") OR isNews:true) AND ' \
                'review_state:published AND path_parents:%(path)s AND ' \
                'effective:[* TO %(effective)s]' % \
                {'path': '/'.join(context.getPhysicalPath()),
                 'effective': iso8601date(now), }
        results = search_solr(query, sort='Date desc')
        return results
Exemple #10
0
    def getResults(self):
        context = Acquisition.aq_inner(self.context)
        catalog = getToolByName(context, 'portal_catalog')
        if hasattr(catalog, 'getZCatalog'):
            catalog = catalog.getZCatalog()

        now = DateTime()
        #queryA = Eq('portal_type', 'News Item')
        #queryB = Eq('isNews', True)
        #queryBoth = In('review_state', 'published') & \
        #Eq('path', '/'.join(context.getPhysicalPath())) \
        #    & Le('effective', now)

        #query = And(Or(queryA, queryB), queryBoth)
        #oldresults = catalog.evalAdvancedQuery(query, (('Date', 'desc'),))

        query = '(portal_type:("News Item") OR isNews:true) AND ' \
                'review_state:published AND path_parents:%(path)s AND ' \
                'effective:[* TO %(effective)s]' % \
                {'path': '/'.join(context.getPhysicalPath()),
                 'effective': iso8601date(now), }
        results = search_solr(query, sort='Date desc')
        return results
Exemple #11
0
    def _data(self):
        context = Acquisition.aq_inner(self.context)
        catalog = getToolByName(context, 'portal_catalog')
        portal_languages = getToolByName(context, 'portal_languages')
        preflang = portal_languages.getPreferredLanguage()

        # search in the navigation root of the currently selected
        # language and in the canonical path
        # with Language = preferredLanguage or neutral
        current_path = self.context.getPhysicalPath()
        if len(current_path) > 3 and current_path[3] in ('sub', 'fop'):
            # in a subsite, take only the subsite or fop site
            path = '/'.join(self.navigation_root_path.split('/')[:-1])
            INFOP = True
        else:
            # in the main site, limit to the events folder #7932
            path = "/osha/portal/en/events"
            INFOP = False

        oshaview = getMultiAdapter((context, self.request), name=u'oshaview')
        subsite = oshaview.getCurrentSubsite()
        # calendar = self.getCalendar(preflang)
        # # If we're in the root (i.e. no in a subiste), and a valid pointer to a
        # # calendar exists, use its path as a query parameter
        # if subsite is None and calendar:
        #     paths = ['/'.join(calendar.getPhysicalPath())]

        subject = list(self.data.subject)
        limit = self.data.count

        # make sure to exclude the subs
        query = 'portal_type:(Event) AND ' \
            'review_state:(%(review_state)s) AND path_parents:(%(path)s) ' \
            'AND end:[%(now)s TO *]' % \
                {'review_state': ' OR '.join(self.data.state),
                'path': path,
                'now': iso8601date(DateTime()), }

        # If a subject is selected, use that for the query
        if subject:
            query += ' AND Subject:(%s)' % ' OR '.join(subject)

        if INFOP:
            results = search_solr(query, sort='start asc', rows=limit)
        else:
            lf_search_view = self.context.restrictedTraverse(
                "@@language-fallback-search")
            results = lf_search_view.search_solr(query,
                                                 sort='start asc',
                                                 rows=limit,
                                                 lang_query=False)

        items = list()
        for res in results[:limit]:
            try:
                items.append(res.getObject())
            except AttributeError:
                pass
            if len(items) >= limit:
                break
        return items