示例#1
0
    def testPublish(self):
        
        imsitem = self.cp.organizations[0].items[0]
        filename = ""
        import ims.utils
        resource = ims.utils.getIMSResourceForIMSItem(self.cp, imsitem)
        if resource:
            filename = resource.getFilename()
            
        self.assert_(os.path.exists(os.path.join(self.testdir, filename)))
        publisher = GetPublisherForFilename(filename)
        self.assert_(publisher)
        publisher.Publish(None, imsitem, dir=self.testdir)
        pub_filename = publisher.GetFileLink(filename)
        
        pub_path = os.path.join(self.testdir, pub_filename)
        self.assert_(os.path.exists(pub_path))
        print pub_path
        soup = BeautifulSoup(open(pub_path).read())
        
        html = """<p>Hello world!
<p>Test
"""
        self.assertEquals(soup.find("meta", attrs={"http-equiv":"description"})['content'], "A Description")
        self.assertEquals(soup.find("meta", attrs={"http-equiv":"keywords"})['content'], "keyword1, keyword2")
        self.assertEquals(soup.body, html)
示例#2
0
    def ApplyTemplate(self, template="default.meld", data={}):
        if not os.path.exists(template):
            template = os.path.join(settings.AppDir, "themes", themes.FindTheme(settings.ProjectSettings["Theme"]).themename, "default.meld")
        temp = utils.openFile(template, "r")
        html = temp.read()
        temp.close()
        charset = "utf-8"
        if 'charset' in self.data.keys():
            charset = self.data['charset']
        ext = os.path.splitext(template)[1]
        soup = BeautifulSoup(html)
        for key in data.keys():
            value = data[key]
            key = key.lower()
            global metaTags
            if key in metaTags:
                tag = soup.find("meta", attrs={"http_equiv": key})
                if not tag:
                    tag = Tag(soup, "meta")
                    tag['http-equiv'] = key
                    soup.html.head.insert(0, tag)

                tag['content'] = value
                if key == 'name':
                    soup.html.head.title.insert(0, value)
            elif key == 'content':
                    soup.html.body.insert(0, value)
        
        html = soup.prettify(charset)
                
        return html