From d35f5ec2fcf05b1a0c90afa04df0c31f92b7b3fe Mon Sep 17 00:00:00 2001 From: Ulysses Lara Date: Thu, 27 Jun 2019 13:21:51 -0300 Subject: [PATCH] Colocando iframe do youtube na tela de detalhes da sessao (#2838) * Adicionando suporte de video youtube e facebook * melhorando regex video do facebook * Resolvendo erros e melhorias relatados no pr --- sapl/base/templatetags/common_tags.py | 28 +++++++++++++++++++++++++-- sapl/templates/crud/detail.html | 17 +++++++++++++--- 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/sapl/base/templatetags/common_tags.py b/sapl/base/templatetags/common_tags.py index 35424ddb9..1e5a0c717 100644 --- a/sapl/base/templatetags/common_tags.py +++ b/sapl/base/templatetags/common_tags.py @@ -223,8 +223,32 @@ def audio_url(value): @register.filter -def video_url(value): - return True if url(value) and value.endswith("mp4") else False +def is_video_url(value): + video_extensions = ["mp4", "ogg", "webm", "3gp", "ogv"] + has_ext = any([value.endswith(i) for i in video_extensions]) + return url(value) and has_ext + + +@register.filter +def youtube_url(value): + # Test if YouTube video + # tested on https://pythex.org/ + youtube_pattern = "^(http://?|https://?www\.?youtube\.com/watch\?v=)" + r = re.findall(youtube_pattern, value) + return True if r else False + +@register.filter +def facebook_url(value): + facebook_pattern = "^(http://?|https://?(www?|pt-br?)\.facebook\.com/(.*?)/videos/(.*?))" + r = re.findall(facebook_pattern, value) + return True if r else False + +@register.filter +def youtube_id(value): + from urllib.parse import urlparse, parse_qs + u_pars = urlparse(value) + quer_v = parse_qs(u_pars.query).get('v')[0] + return quer_v @register.filter diff --git a/sapl/templates/crud/detail.html b/sapl/templates/crud/detail.html index 0058fc917..2d4f86b91 100644 --- a/sapl/templates/crud/detail.html +++ b/sapl/templates/crud/detail.html @@ -72,13 +72,21 @@

Este navegador não suporta o elemento áudio.

- {% elif column.text|video_url %} + {% elif column.text|is_video_url %}
-
+ {% elif column.text|youtube_url %} + + {% elif column.text|facebook_url %} +
+
{% elif column.text|url %}
{{ column.text|safe|default:"" }}
{% else %} @@ -131,4 +139,7 @@ {% endblock table_content %} {% endblock base_content %} -{% block extra_js %}{% endblock %} +{% block extra_js %} +
+ +{% endblock %}