def manage_afterAdd(self, item, container, **kw):
        """Setup properties and sub-objects"""
        # Only run on add, not rename, etc.
        if not base_hasattr(self, 'mqueue'):
            setMailBoxerProperties(self, self.REQUEST, kw)
            # Setup the default checkMail validator chain
            setDefaultValidatorChain(self)

            # Add Archive
            archive = zapi.createObject('listen.ArchiveFactory', self.storage,
                                        title=u'List Archive')
            item._setObject(self.storage, archive)

            # Add moderation queue
            mqueue = zapi.createObject('listen.QueueFactory', self.mailqueue,
                                       title=u'Moderation queue')
            item._setObject(self.mailqueue, mqueue)

            ttool = getToolByName(self, 'portal_types', None)
            if ttool is not None:
                # If the archive/queue are CMF types then we must finish
                # constructing them.
                fti = ttool.getTypeInfo(mqueue)
                if fti is not None:
                    fti._finishConstruction(mqueue)
                fti = ttool.getTypeInfo(archive)
                if fti is not None:
                    fti._finishConstruction(archive)
        MailBoxer.manage_afterAdd(self, self.REQUEST, kw)
Ejemplo n.º 2
0
 def topicContent(self):
     """ render the source of the help topic """
     source = zapi.createObject(self.context.type,
                                self.context.source)
     view = zapi.getMultiAdapter((source, self.request))
     html = view.render()
     return html
    def testFactory(self):

        self.assertRaises(ComponentLookupError, zapi.createObject, 'foo')

        xmlconfig(StringIO(template % (
            '''
            <factory
               id="foo.bar"
               component="zope.app.component.tests.factory.f"
               />
            '''
            )))

        from factory import X
        self.assertEqual(zapi.createObject('foo.bar').__class__, X)
Ejemplo n.º 4
0
    def getIntroduction(self):
        text = self.context.__description__ or self.schema.__doc__
        text = translate(text, context=self.request, default=text)

        # Determine common whitespace ...
        cols = len(re.match('^[ ]*', text).group())
        # ... and clean it up.
        text = re.sub('\n[ ]{%i}' %cols, '\n', text).strip()

        if not text:
            return u''

        # Render the description as ReST.
        source = zapi.createObject('zope.source.rest', text)
        renderer = zapi.getMultiAdapter((source, self.request))
        return renderer.render()
Ejemplo n.º 5
0
def renderText(text, module=None, format=None, dedent=True):
    if not text:
        return u''

    if module is not None:
        if isinstance(module, (str, unicode)):
            module = sys.modules.get(module, None)
        format = getDocFormat(module)

    if format is None:
        format = 'zope.source.stx'

    assert format in _format_dict.values()

    text = dedentString(text)

    source = zapi.createObject(format, text)
    renderer = zapi.getMultiAdapter((source, TestRequest()))
    return renderer.render()
    def addMailBoxerMail(self, folder, id, sender, subject, date, mail):
        # Strip out the list name from the subject, as it serves no purpose
        # in the archive.
        subject = subject.replace('[%s]' % self.getValueFor('title'), '')

        new_message = zapi.createObject('listen.MailFactory',
                                        id, sender, subject, date)
        folder._setObject(id, new_message)
        msg = getattr(folder, id)
        # Adapt message to provide methods for parsing mail and extracting
        # headers
        settable_msg = IMailFromString(msg)
        # This is ugly, but it is the MailBoxer way, last option means no
        # attachments.
        store_attachments = self.archived == 0
        # Set properties on message
        settable_msg.createMailFromMessage(mail, store_attachments)
        zope.event.notify(
            zope.app.event.objectevent.ObjectModifiedEvent(msg))
        
        return msg
 def addMailBoxerFolder(self, context, id, title, btree=True):
     """ Adds an archive-folder using a configured factory
     """
     folder = zapi.createObject('listen.FolderFactory',
                                id, title, btree=btree)
     context._setObject(id, folder)
Ejemplo n.º 8
0
 def addLanguage(self, language):
     'See `IWriteTranslationDomain`'
     catalog = zapi.createObject(u'zope.app.MessageCatalog',
                                 language)
     self[language] = catalog