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')
예제 #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]
예제 #3
0
    def __call__(self):
        root = getToolByName(self.context, 'portal_url'
                             ).getPortalObject()
        mail_info = IMailSchema(root)
        mail_from = '%s <%s>' % (mail_info.email_from_name,
                                 mail_info.email_from_address)

        comment = self.context
        conversation = aq_parent(comment)
        review = aq_parent(conversation)
        pg = IParentGetter(review)

        args = {}
        args['url'] = review.absolute_url()
        args['date'] = review.created().strftime('%d.%m.%Y')
        args['title'] = review.title + (hasattr(review, 'subtitle')
                and review.subtitle and ': ' + review.subtitle or '')
        args['year'] = getattr(review, 'yearOfPublication', '')
        args['isbn'] = getattr(review, 'isbn', '')
        args['reviewers'] = '/'.join(review.listReviewAuthors())
        args['journal'] = pg.get_title_from_parent_of_type('Publication'
                )
        args['volume'] = pg.get_title_from_parent_of_type('Volume')
        args['issue'] = pg.get_title_from_parent_of_type('Issue')
        args['commenter'] = comment.author_name
        args['commentdate'] = comment.creation_date.strftime('%d.%m.%Y')
        args['mail_from'] = mail_from

        for key in args:
            args[key] = safe_unicode(args[key])

        # for review types, notify authors of the works (via editorial
        # office)

        if review.portal_type in REVIEW_TYPES:
            authors = getattr(review, 'authors', [])
            args['recipient'] = get_formatted_names(u' / ', ' ',
                    authors)
            args['author'] = args['recipient']
            mail_to = mail_from
            pref_lang = 'de'
            for author in authors:

                # for pref_lang in
                # self.pl.getAvailableLanguages().keys(): # send one
                # mail for for every language

                subject = \
                    self.ts.translate(_('mail_new_comment_subject_review_author'
                        , mapping=args), target_language=pref_lang)
                msg_template = \
                    self.ts.translate(_('mail_new_comment_body_review_author'
                        , mapping=args), target_language=pref_lang)
                self.sendMail(msg_template, mail_from, mail_to, subject)
        else:

        # for presentation types, notify presentation author

            args['recipient'] = get_formatted_names(u' / ', ' ',
                    self.context.getReviewAuthors())
            args['author'] = 'someone'
            if hasattr(self.context, 'getAuthors'):
                args['author'] = get_formatted_names(u' / ', ' ',
                        self.context.getAuthors())
            elif hasattr(self.context, 'getInstitution'):
                institutions = self.context.getInstitution()
                if institutions:
                    args['author'] = institutions[0]['name']
            (mail_to, pref_lang) = self.findRecipient()
            if not mail_to:
                mail_to = getattr(review, 'reviewAuthorEmail', '')
            subject = \
                self.ts.translate(_('mail_new_comment_subject_presentation_author'
                                  , mapping=args),
                                  target_language=pref_lang)
            msg_template = \
                self.ts.translate(_('mail_new_comment_body_presentation_author'
                                  , mapping=args),
                                  target_language=pref_lang)
            self.sendMail(msg_template, mail_from, mail_to, subject)

        # Find other comment authors and notify them

        recipients = []
        for item in conversation.items():
            cmt = item[1]
            if not cmt.author_email in map(lambda x: x[0], recipients) \
                and (not mail_to or not cmt.author_email in mail_to) \
                and not cmt.author_email == comment.author_email:
                rcpt = self.findRecipient(id=cmt.author_username)
                recipients.append(rcpt + (cmt.author_name, ))

        for rcpt in recipients:
            (mail_to, pref_lang, name) = rcpt
            if ' ' in name:
                name = name.split(' ')
                name = {'firstname': name[0], 'lastname': name[1]}
            else:
                name = {'firstname': '', 'lastname': name}
            args['recipient'] = get_formatted_names(u' ', u' ', [name])
            if review.portal_type in REVIEW_TYPES:
                subject = \
                    self.ts.translate(_('mail_new_comment_subject_review_commenter'
                        , mapping=args), target_language=pref_lang)
                msg_template = \
                    self.ts.translate(_('mail_new_comment_body_review_commenter'
                        , mapping=args), target_language=pref_lang)
            else:
                subject = \
                    self.ts.translate(_('mail_new_comment_subject_presentation_commenter'
                        , mapping=args), target_language=pref_lang)
                msg_template = \
                    self.ts.translate(_('mail_new_comment_body_presentation_commenter'
                        , mapping=args), target_language=pref_lang)
            self.sendMail(msg_template, mail_from, mail_to, subject)
예제 #4
0
 def __call__(self):
     pub = IParentGetter(self.context).get_parent_object_of_type(
         "Publication")
     return pub.getYearOfPublication()