示例#1
0
文件: models.py 项目: guglielmo/atlas
    def render_html(self):
        """Render the asset as HTML"""
        output = []
        output.append('<figure>')
        try:
            # First try to embed the resource via oEmbed
            resource = oembed.site.embed(self.url, format='json')
            resource_data = resource.get_data()
            if resource_data['type'] in ('rich', 'video'):
                output.append(resource_data['html'])
            elif resource_data['type'] == 'photo':
                output.append(self.render_img_html(resource_data['url']))
            elif resource_data['type'] == 'link':
                output.append(self.render_link_html())
            else:
                raise AssertionError(
                    "oEmbed provider returned invalid type")
                
        except OEmbedMissingEndpoint:
            try:
                # Next try to embed things ourselves
                html = EmbedableResource.get_html(self.url)
                output.append(html)
            except UrlNotMatched:
                # If all else fails, just show an image or a link
                if self.type == 'image':
                    output.append(self.render_img_html())
                else:
                    output.append(self.render_link_html())

        full_caption_html = self.full_caption_html()
        if full_caption_html:
	    output.append(full_caption_html)
        output.append('</figure>')

        return mark_safe(u'\n'.join(output))
示例#2
0
文件: tests.py 项目: guglielmo/atlas
 def test_get_google_spreadsheet_embed(self):
     url = 'https://docs.google.com/spreadsheet/pub?key=0As2exFJJWyJqdDhBejVfN1RhdDg2b0QtYWR4X2FTZ3c&output=html' 
     expected = "<iframe width='500' height='300' frameborder='0' src='%s&widget=true'></iframe>" % url
     self.assertEqual(EmbedableResource.get_html(url), expected)