diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-05-16 19:53:11 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-06-12 08:44:34 +0200 |
commit | 882cf2378f7b1af9d8f08a287c2f9fc96dd3742e (patch) | |
tree | 63fe35990e2ebbd07ed3bd229da15ef2b39e7211 /ishtar_common/utils.py | |
parent | 1d271b86456cd182efb4646ce84c213c13b912ff (diff) | |
download | Ishtar-882cf2378f7b1af9d8f08a287c2f9fc96dd3742e.tar.bz2 Ishtar-882cf2378f7b1af9d8f08a287c2f9fc96dd3742e.zip |
Imports: a web link can be put for images
Diffstat (limited to 'ishtar_common/utils.py')
-rw-r--r-- | ishtar_common/utils.py | 15 |
1 files changed, 15 insertions, 0 deletions
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 |