summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2019-06-17 18:15:04 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2019-06-17 18:15:04 +0200
commit5dfd9d0e07d5b3e92ed07b69bec8f93d970ea290 (patch)
tree4fe160ea6211e022c18d5eff729ea8fa10ad5322
parent36e8b187b7c179048836425c420c4cc7ca3dd028 (diff)
downloadIshtar-5dfd9d0e07d5b3e92ed07b69bec8f93d970ea290.tar.bz2
Ishtar-5dfd9d0e07d5b3e92ed07b69bec8f93d970ea290.zip
Document: fix form when an old file has disappear
-rw-r--r--ishtar_common/widgets.py15
1 files changed, 10 insertions, 5 deletions
diff --git a/ishtar_common/widgets.py b/ishtar_common/widgets.py
index b13e9fe2e..14d153651 100644
--- a/ishtar_common/widgets.py
+++ b/ishtar_common/widgets.py
@@ -421,11 +421,16 @@ class ImageFileInput(ClearableFileInput):
if self.is_initial(value):
return value
# try to display posted images
- if hasattr(value, 'file'):
- full_path = str(value.file)
- if full_path.startswith(settings.MEDIA_ROOT):
- value.url = settings.MEDIA_URL + full_path[
- len(settings.MEDIA_ROOT):]
+ try:
+ has_file = hasattr(value, 'file')
+ except ValueError:
+ has_file = False
+ if has_file:
+ if hasattr(value, 'file'):
+ full_path = str(value.file)
+ if full_path.startswith(settings.MEDIA_ROOT):
+ value.url = settings.MEDIA_URL + full_path[
+ len(settings.MEDIA_ROOT):]
elif value:
full_path = settings.MEDIA_ROOT + str(value)
try: