def setUp(self):
        self.portal      = self.layer["portal"]
        login(self.layer['app'], SITE_OWNER_NAME)
        add_number_of_each_review_type(
            self.portal, 1, rez_classes=[ReviewMonograph, ReviewJournal])

        self.publication = self.portal["sample-reviews"]["newspapera"]
        self.review_mono = self.portal.portal_catalog.search(
            {"portal_type" :"Review Monograph",
             "path"        :{
                    "query": "/".join(self.publication.getPhysicalPath())
                    }
             }
            )[0].getObject()
        pg = IParentGetter(self.review_mono)
        self.issue_mono = pg.get_parent_object_of_type('Issue')
        self.review_jour = self.portal.portal_catalog.search(
            {"portal_type" :"Review Journal",
             "path"        :{
                    "query": "/".join(self.publication.getPhysicalPath())
                    }
             }
            )[0].getObject()
        pg = IParentGetter(self.review_jour)
        self.issue_jour = pg.get_parent_object_of_type('Issue')
Exemplo n.º 2
0
    def getReviewJournals(self):
        pc = getToolByName(self.context, 'portal_catalog')
        query = dict(portal_type=['Issue', 'Volume'],
            review_state="published",
            sort_on='effective',
            sort_order='reverse', b_size=6)
        res = pc(query)[:6]
        resultset = list()
        objects = {}
        for r in res:
            objects[r.getObject()] = r
        for obj, brain in objects.items():
            if obj.portal_type == "Issue" and \
                obj.__parent__.portal_type == "Volume":
                if obj.__parent__ in objects.keys() \
                   and objects[obj.__parent__] in res:
                    res.remove(objects[obj.__parent__])
        for r in res:
            if not r:
                continue
            try:
                o = r.getObject()
            except AttributeError:
                log.exception("Could not get object. Probably this means "
                    "there is a mismatch with solr")
                continue
            if o not in objects:
                continue
            pg = IParentGetter(o)
            publication = pg.get_parent_object_of_type('Publication')
            publication_title = publication and publication.Title() or u''
            publication_url = publication and publication.absolute_url() or u''
            if o.portal_type == 'Volume':
                volume = o
            else:
                volume = pg.get_parent_object_of_type('Volume')
            volume_title = volume and volume.Title() or u''
            volume_url = volume and volume.absolute_url() or u''

            # The title of the result shall only be shown if the result
            # is a volume. Because we already show the volume title.
            result_title = r.Title if o != volume else ''
            resultset.append(
                dict(
                    Title=result_title,
                    effective_date=self.format_effective_date(r.EffectiveDate),
                    publication_title=publication_title,
                    publication_url=publication_url,
                    review_url=r.getURL(),
                    volume_title=volume_title,
                    volume_url=volume_url
                    )
                )
        # print "getReviewJournals", len(res)
        return resultset[:3]