Пример #1
0
    def _addComment(self, text, attaches=[]):
        cm = ICommentsManager(self.context)
        comment = cm.addComment(text, attaches)

        # send notifications
        msg = self.context.aq_inner
        type_name = msg.portal_type
        sm = ISubscriptionManager(msg)

        portal_url = getToolByName(msg, 'portal_url')

        project = msg.getProject()
        company = project.getCompany()

        # attachments in msg
        attachments_msg = ''
        attachments = self.attachable() and comment.getCommentAttaches() or [(), ()]
        image_urls = [img.absolute_url() for img in attachments[0]]
        file_urls = [file.absolute_url() for file in attachments[1]]
        len_attachments = len(image_urls + file_urls)

        if image_urls or file_urls:
            attachments_msg = translate(_(u'attachments_msg',
                                        default='This comment contains ${len_attachments} attachment(s): \n ',
                                        mapping={u'len_attachments':len_attachments}),
                                        context=self.request) 
            for url in (image_urls + file_urls):
                url = url + '/@@file_view' + '\n'
                attachments_msg+=url

        subject = '[%s] %s' % (project.Title(), comment.Title())

        mtool = getToolByName(msg, 'portal_membership')
        member = mtool.getAuthenticatedMember()
        fullname = member.getProperty('fullname')
        email = member.getProperty('email')

        if type_name in ['Image', 'File']:
            bc_url = '%s/@@file_view' % msg.absolute_url()
        else:
            bc_url = msg.absolute_url()


        body = translate(_(u'mail_body',
                        default='${project_name} of the ${company_name} have a new comment posted. DO NOT REPLY TO THIS EMAIL. To comment on this message, visit:\n${msg_url}\n\n${user_name} <${user_email}> said:\n--------------------------------------------------------------------------\n${msg_body}\n\n${attachments}\n\n--\nDO NOT REPLY TO THIS EMAIL.\nTo comment on this message, visit:\n${msg_url}', 
                        mapping={u'company_name':company.Title(),
                               u'project_name':project.Title(),
                               u'msg_url':bc_url,
                               u'user_name':fullname or member.getId(),
                               u'user_email':email,
                               u'msg_body':text,
                               u'attachments':attachments_msg}),
                        context=self.request)
        sm.sendMail(subject=subject, body=body)
        sm.subscribeAuthenticatedMember()
        return comment
Пример #2
0
    def _addComment(self, text, attaches=[]):
        cm = ICommentsManager(self.context)
        comment = cm.addComment(text, attaches)

        # send notifications
        msg = self.context.aq_inner
        type_name = msg.portal_type
        sm = ISubscriptionManager(msg)

        portal_url = getToolByName(msg, "portal_url")

        project = msg.getProject()
        company = project.getCompany()

        # attachments in msg
        attachments_msg = ""
        attachments = self.attachable() and comment.getCommentAttaches() or [(), ()]
        image_urls = [img.absolute_url() for img in attachments[0]]
        file_urls = [file.absolute_url() for file in attachments[1]]
        len_attachments = len(image_urls + file_urls)

        if image_urls or file_urls:
            attachments_msg = translate(
                _(
                    u"attachments_msg",
                    default="This comment contains ${len_attachments} attachment(s): \n ",
                    mapping={u"len_attachments": len_attachments},
                ),
                context=self.request,
            )
            for url in image_urls + file_urls:
                url = url + "/@@file_view" + "\n"
                attachments_msg += url

        subject = "[%s] %s" % (project.Title(), comment.Title())

        mtool = getToolByName(msg, "portal_membership")
        member = mtool.getAuthenticatedMember()
        fullname = member.getProperty("fullname")
        email = member.getProperty("email")

        if type_name in ["Image", "File"]:
            bc_url = "%s/@@file_view" % msg.absolute_url()
        else:
            bc_url = msg.absolute_url()

        body = translate(
            _(
                u"mail_body",
                default="${project_name} of the ${company_name} have a new comment posted. DO NOT REPLY TO THIS EMAIL. To comment on this message, visit:\n${msg_url}\n\n${user_name} <${user_email}> said:\n--------------------------------------------------------------------------\n${msg_body}\n\n${attachments}\n\n--\nDO NOT REPLY TO THIS EMAIL.\nTo comment on this message, visit:\n${msg_url}",
                mapping={
                    u"company_name": company.Title(),
                    u"project_name": project.Title(),
                    u"msg_url": bc_url,
                    u"user_name": fullname or member.getId(),
                    u"user_email": email,
                    u"msg_body": text,
                    u"attachments": attachments_msg,
                },
            ),
            context=self.request,
        )
        sm.sendMail(subject=subject, body=body)
        sm.subscribeAuthenticatedMember()
        return comment