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

            # Add Archive
            archive = zapi.createObject('listen.ArchiveFactory',,
                                        title=u'List Archive')
            item._setObject(, 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 = ttool.getTypeInfo(archive)
                if fti is not None:
        MailBoxer.manage_afterAdd(self, self.REQUEST, kw)
Ejemplo n.º 2
 def topicContent(self):
     """ render the source of the help topic """
     source = zapi.createObject(self.context.type,
     view = zapi.getMultiAdapter((source, self.request))
     html = view.render()
     return html
    def testFactory(self):

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

        xmlconfig(StringIO(template % (

        from factory import X
        self.assertEqual(zapi.createObject('').__class__, X)
Ejemplo n.º 4
    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('', text)
        renderer = zapi.getMultiAdapter((source, self.request))
        return renderer.render()
Ejemplo n.º 5
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)
        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
 def addLanguage(self, language):
     'See `IWriteTranslationDomain`'
     catalog = zapi.createObject(u'',
     self[language] = catalog