Example #1
0
    def test_get_embed(self):
        embed = get_embed('www.test.com/1234',
                          max_width=400,
                          finder=self.dummy_finder)

        # Check that the embed is correct
        self.assertEqual(embed.title, "Test: www.test.com/1234")
        self.assertEqual(embed.type, 'video')
        self.assertEqual(embed.width, 400)

        # Check that there has only been one hit to the backend
        self.assertEqual(self.hit_count, 1)

        # Look for the same embed again and check the hit count hasn't increased
        embed = get_embed('www.test.com/1234',
                          max_width=400,
                          finder=self.dummy_finder)
        self.assertEqual(self.hit_count, 1)

        # Look for a different embed, hit count should increase
        embed = get_embed('www.test.com/4321',
                          max_width=400,
                          finder=self.dummy_finder)
        self.assertEqual(self.hit_count, 2)

        # Look for the same embed with a different width, this should also increase hit count
        embed = get_embed('www.test.com/4321', finder=self.dummy_finder)
        self.assertEqual(self.hit_count, 3)
Example #2
0
    def test_get_embed(self):
        embed = get_embed(
            'www.test.com/1234', max_width=400, finder=self.dummy_finder)

        # Check that the embed is correct
        self.assertEqual(embed.title, "Test: www.test.com/1234")
        self.assertEqual(embed.type, 'video')
        self.assertEqual(embed.width, 400)

        # Check that there has only been one hit to the backend
        self.assertEqual(self.hit_count, 1)

        # Look for the same embed again and check the hit count hasn't increased
        embed = get_embed(
            'www.test.com/1234', max_width=400, finder=self.dummy_finder)
        self.assertEqual(self.hit_count, 1)

        # Look for a different embed, hit count should increase
        embed = get_embed(
            'www.test.com/4321', max_width=400, finder=self.dummy_finder)
        self.assertEqual(self.hit_count, 2)

        # Look for the same embed with a different width, this should also increase hit count
        embed = get_embed('www.test.com/4321', finder=self.dummy_finder)
        self.assertEqual(self.hit_count, 3)
Example #3
0
    def test_invalid_width(self):
        embed = get_embed('www.test.com/1234',
                          max_width=400,
                          finder=self.dummy_finder_invalid_width)

        # Width must be set to None
        self.assertEqual(embed.width, None)
Example #4
0
def embed_to_editor_html(url):
    embed = get_embed(url)
    if embed is None:
        return

    return '<div class="embed-placeholder" contenteditable="false" data-embedtype="media" data-url="%s"><h3>%s</h3><p>%s</p><img src="%s"></div>' % (
    url, escape(embed.title), url, embed.thumbnail_url)
Example #5
0
def embed_to_editor_html(url):
    embed = get_embed(url)
    if embed is None:
        return

    # Render template
    return render_to_string("wagtailembeds/embed_editor.html", {"embed": embed})
Example #6
0
    def test_invalid_width(self):
        embed = get_embed(
            'www.test.com/1234',
            max_width=400,
            finder=self.dummy_finder_invalid_width)

        # Width must be set to None
        self.assertEqual(embed.width, None)
Example #7
0
def embed(url, max_width=None):
    embed = get_embed(url, max_width=max_width)
    try:
        if embed is not None:
            return mark_safe(embed.html)
        else:
            return ''
    except:
        return ''
Example #8
0
def embed_to_editor_html(url):
    embed = get_embed(url)
    if embed is None:
        return

    # Render template
    return render_to_string('wagtailembeds/embed_editor.html', {
        'embed': embed,
    })
Example #9
0
def embed_to_editor_html(url):
    embed = get_embed(url)
    if embed is None:
        return

    # Render template
    return render_to_string('wagtailembeds/embed_editor.html', {
        'embed': embed,
    })
Example #10
0
def embed(url, max_width=None):
    embed = get_embed(url, max_width=max_width)
    try:
        if embed is not None:
            return mark_safe(embed.html)
        else:
            return ''
    except:
        return ''
Example #11
0
    def test_no_html(self) :
        def no_html_finder(url, max_width=None):
            """
            A finder which returns everything but HTML
            """
            embed = self.dummy_finder(url, max_width)
            embed['html'] = None
            return embed

        embed = get_embed('www.test.com/1234', max_width=400, finder=no_html_finder)

        self.assertEqual(embed.html, '')
Example #12
0
    def test_no_html(self):
        def no_html_finder(url, max_width=None):
            """
            A finder which returns everything but HTML
            """
            embed = self.dummy_finder(url, max_width)
            embed['html'] = None
            return embed

        embed = get_embed('www.test.com/1234',
                          max_width=400,
                          finder=no_html_finder)

        self.assertEqual(embed.html, '')
Example #13
0
def embed_to_frontend_html(url):
    try:
        embed = get_embed(url)
        if embed is not None:
            # Work out ratio
            if embed.width and embed.height:
                ratio = str(embed.height / embed.width * 100) + "%"
            else:
                ratio = "0"

            # Build html
            return '<div style="padding-bottom: %s;" class="responsive-object">%s</div>' % (ratio, embed.html)
        else:
            return ''
    except:
        return ''
Example #14
0
def embed_to_frontend_html(url):
    try:
        embed = get_embed(url)
        if embed is not None:
            # Work out ratio
            if embed.width and embed.height:
                ratio = str(embed.height / embed.width * 100) + "%"
            else:
                ratio = "0"

            # Render template
            return render_to_string("wagtailembeds/embed_frontend.html", {"embed": embed, "ratio": ratio})
        else:
            return ""
    except:
        return ""
Example #15
0
def embed_to_frontend_html(url):
    try:
        embed = get_embed(url)
        if embed is not None:
            # Work out ratio
            if embed.width and embed.height:
                ratio = str(embed.height / embed.width * 100) + "%"
            else:
                ratio = "0"

            # Render template
            render_to_string('wagtailembeds/embed_frontend.html', {
                'embed': embed,
                'ratio': ratio,
            })
        else:
            return ''
    except:
        return ''
Example #16
0
def embed_to_frontend_html(url):
    try:
        embed = get_embed(url)
        if embed is not None:
            # Work out ratio
            if embed.width and embed.height:
                ratio = str(embed.height / embed.width * 100) + "%"
            else:
                ratio = "0"

            # Render template
            return render_to_string('wagtailembeds/embed_frontend.html', {
                'embed': embed,
                'ratio': ratio,
            })
        else:
            return ''
    except:
        return ''