From ebcb12531f47da632e8c2bbdda11b699cabfc702 Mon Sep 17 00:00:00 2001 From: Prabhakaran Date: Fri, 9 Jan 2015 17:57:14 +0530 Subject: [PATCH 1/2] Check video exists before proceeding to print --- INSTALL.txt | 9 +++++++++ oembed/templatetags/oembed_tags.py | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/INSTALL.txt b/INSTALL.txt index 279546c..cfd2c4c 100644 --- a/INSTALL.txt +++ b/INSTALL.txt @@ -32,6 +32,15 @@ looking at this usage: {% oembed 320x240 %} +Check if video exists before printing on the DOM +{% if video_url|is_video:video_url %} + {% oembed %} + {% for link in links %}{{ link.href }}{% endfor %} + {% endoembed %} +{% else %} + Some Default Video/Image +{% endif %} + Note that this application requires Python 2.3 or later, and Django later than 0.96. You can obtain Python from http://www.python.org/ and Django from http://www.djangoproject.com/. \ No newline at end of file diff --git a/oembed/templatetags/oembed_tags.py b/oembed/templatetags/oembed_tags.py index 2b1dcba..1252190 100644 --- a/oembed/templatetags/oembed_tags.py +++ b/oembed/templatetags/oembed_tags.py @@ -58,3 +58,11 @@ def render(self, context): kwargs['max_width'] = self.width kwargs['max_height'] = self.height return replace(self.nodelist.render(context), **kwargs) + +@register.filter +def is_video(object, link): + iframe = replace(link).find('iframe') + if iframe == 1: + return True + else: + return False From 92eaeef322f9da3819b7e374cc8dcedec2399582 Mon Sep 17 00:00:00 2001 From: Prabhakaran Date: Fri, 9 Jan 2015 18:01:09 +0530 Subject: [PATCH 2/2] Install instruction --- INSTALL.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/INSTALL.txt b/INSTALL.txt index cfd2c4c..2ccf37b 100644 --- a/INSTALL.txt +++ b/INSTALL.txt @@ -35,7 +35,7 @@ looking at this usage: Check if video exists before printing on the DOM {% if video_url|is_video:video_url %} {% oembed %} - {% for link in links %}{{ link.href }}{% endfor %} + Video url {% endoembed %} {% else %} Some Default Video/Image