From 87c7271b298dced2423ba4e7daba8f9db4af91d0 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Wed, 16 May 2018 19:53:11 +0200 Subject: Imports: a web link can be put for images --- ishtar_common/utils.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'ishtar_common/utils.py') diff --git a/ishtar_common/utils.py b/ishtar_common/utils.py index 7c77fc3d1..b2ba2bc24 100644 --- a/ishtar_common/utils.py +++ b/ishtar_common/utils.py @@ -23,6 +23,7 @@ from itertools import chain import hashlib import os import random +import requests import shutil import subprocess import tempfile @@ -73,6 +74,20 @@ class MultiValueDict(BaseMultiValueDict): return lst +def is_downloadable(url): + """ + Does the url contain a downloadable resource + """ + h = requests.head(url, allow_redirects=True) + header = h.headers + content_type = header.get('content-type') + if 'text' in content_type.lower(): + return False + if 'html' in content_type.lower(): + return False + return True + + def get_current_year(): return datetime.datetime.now().year -- cgit v1.2.3