def convert(self, data, outdata, **kwargs):
        """Input is a module object. Output is idata, but getData returns a binary zip file."""
        #text = data.module_render()

        kw = {}
        #kw.update(data.getCourseParameters())
        styleMethod = self.config['stylesheet_method']
        if styleMethod: styleMethod = getattr(data, styleMethod, None)
        if styleMethod: styles = styleMethod()
        else: styles = getStyles()
        kw["styles"] = styles
        if len(styles) <= 1: kw["style_chooser"] = 0

        kw['offline'] = 1

        source = data.module_export_template(**kw)
        text = data.cnxml_transform(source, stylesheet=MODULE_XSL)

        container = data.getId().replace('.', '-')
        content, zipfile = makeZipFile(data, container)
        zipfile.writestr('%s/index.xhtml' % container, text)
        zipfile.writestr("%s/README.txt" % container, README)

        zipfile.writestr("%s/stylesheets/offline.css" % container, offlinecss)
        for style in styles:
            styleloc = style['source']
            wf = getToolByName(data, 'portal_skins')
            folder = wf.restrictedTraverse(styleloc)
            stylepath = "%s/stylesheets/%s" % (container, folder.getId())
            for ob_id, ob in folder.objectItems():
                val = getattr(ob, '_readFile', None)
                if val: val = val(0)  # get value from FSImage or FSFile
                else:
                    val = str(
                        getattr(ob, 'data', ob)
                    )  # get value from Image or File, with vaguely reasonable default
                zipfile.writestr('/'.join((stylepath, ob_id)), val)

        zipfile.close()
        outdata.setData(content.getvalue())
        content.close()
        # nothing to do for outdata.setSubObjects(objects)
        return outdata
示例#2
0
    def convert(self, data, outdata, **kwargs):
        """Input is a content folderish object. Output is idata, but getData returns a binary zip file."""
        
        # construct manifest file structure
        obj = data.getPublishedObject()
        if not obj: obj = data               # this needs to be smarter for non-pub objects
        identity = IDENTIFIER % obj.absolute_url()

        manifestzpt = PageTemplateFile('www/ieeemd', GLOBALS)
        manifestzpt.content_type = "text/xml"
        manifestzpt.title = "Manifest Template"
        manifestzpt = manifestzpt.__of__(data)
        
        # set up metadata info
        modmeta = data.getMetadata()
        moduledata = {}
        moduledata["modulename"] = data.getId()
        moduledata["url"] = (data.getPublishedObject() or data).absolute_url()
        moduledata["title"] = modmeta['title']
        moduledata["description"] = modmeta['abstract']
        owners = ()
        for x in modmeta['licensors']:
            owners = owners + (getUserFullname(data, x),)
        moduledata["rights"] = "This module is copyright %s under the license: %s" % (", ".join(owners), modmeta['license'])
        moduledata["size"] = data.get_size()
        moduledata["mime"] = "application/cnxml+xml"
        moduledata["language"] = 'en'
        #moduledata["userlanguage"] = 'en'
        moduledata["keywords"] = modmeta['keywords']
        moduledata["version"] = modmeta['version']
        moduledata["status"] = data.state in ("created", "modified") and "draft" or "final"
        contributors = ()
        for x in modmeta['authors']:
            vcard = getUserVCard(data, x)
            contributors = contributors + ({"role":"author", "entity":vcard},)  # also date, but we don't support that
        for x in modmeta['maintainers']:
            vcard = getUserVCard(data, x)
            contributors = contributors + ({"role":"editor", "entity":vcard},)  # also date, but we don't support that
        moduledata["contributors"] = contributors
        #moduledata["interactive"] = 0  # how do we figure this?
        # future: references (links), annotations, classifications (taxonomy)
        moduledata["files"] = []

        def addToResource(name, path, obj):
            moduledata["files"].append(path)
        
        container = data.getId().replace('.','-')
        content, zipfile = makeZipFile(data, container, callback=addToResource)
        
        ## disable XHTML export until we have a better handle on what it looks like
        #source = data.module_export_template(**kw)
        #text = data.cnxml_transform(source, stylesheet=MODULE_XSL)
        #zipfile.writestr('%s/index.xhtml' % container, text)

        manifest = manifestzpt(**moduledata)
        zipfile.writestr(MANIFEST, manifest)

        zipfile.close()
        outdata.setData(content.getvalue())
        content.close()
        # nothing to do for outdata.setSubObjects(objects)
        return outdata