diff options
| 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 | 
| commit | d2d30785cb2e966efa00421259d0d5bd01e6823b (patch) | |
| tree | 4fe160ea6211e022c18d5eff729ea8fa10ad5322 | |
| parent | 390c95c4cb2b88b384e335b2c465fc8622eded56 (diff) | |
| download | Ishtar-d2d30785cb2e966efa00421259d0d5bd01e6823b.tar.bz2 Ishtar-d2d30785cb2e966efa00421259d0d5bd01e6823b.zip | |
Document: fix form when an old file has disappear
| -rw-r--r-- | ishtar_common/widgets.py | 15 | 
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: | 
