diff options
| author | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-08-29 11:15:25 +0200 | 
|---|---|---|
| committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-08-29 11:15:25 +0200 | 
| commit | 9ce6bdd133dddfc291a814a3adc5ae344203092b (patch) | |
| tree | 42b8ba3dc8113fd9b4b7fd90cfd43bde1d334a65 | |
| parent | 44f79d80f9cc06ddc3c42fd987ed2019ed7abe8b (diff) | |
| download | Ishtar-9ce6bdd133dddfc291a814a3adc5ae344203092b.tar.bz2 Ishtar-9ce6bdd133dddfc291a814a3adc5ae344203092b.zip | |
Wizards: fix image and file initialization on modify
| -rw-r--r-- | archaeological_finds/models_finds.py | 2 | ||||
| -rw-r--r-- | ishtar_common/wizards.py | 24 | 
2 files changed, 17 insertions, 9 deletions
| diff --git a/archaeological_finds/models_finds.py b/archaeological_finds/models_finds.py index 6154fb74d..59b8eb1d0 100644 --- a/archaeological_finds/models_finds.py +++ b/archaeological_finds/models_finds.py @@ -792,7 +792,7 @@ class Find(BulkUpdatedItem, ValueGetter, BaseHistorizedItem, ImageModel,          bf = self.get_first_base_find()          if not bf or not bf.context_record or not bf.context_record.operation:              return "" -        return "{}-{}".format( +        return u"{}-{}".format(              bf.context_record.operation.get_reference(),              self.index) diff --git a/ishtar_common/wizards.py b/ishtar_common/wizards.py index ca18d6697..ece1029e6 100644 --- a/ishtar_common/wizards.py +++ b/ishtar_common/wizards.py @@ -278,6 +278,7 @@ class Wizard(NamedUrlWizardView):                      # simulate a non empty data for form that might be                      # valid when empty                      prefixed_values['__non_empty_data'] = '' +                self.prepare_serialization(prefixed_values)                  storage.set_step_data(next_step, prefixed_values)              if step == next_step:                  current_step_passed = True @@ -990,6 +991,19 @@ class Wizard(NamedUrlWizardView):          data[key] = value          storage.set_step_data(form_key, data) +    @classmethod +    def prepare_serialization(cls, data): +        """ +        Image and file cannot be passed as object +        """ +        for k in data: +            if isinstance(data[k], ImageFieldFile) \ +                    or isinstance(data[k], FileField): +                try: +                    data[k] = data[k].path +                except ValueError: +                    pass +      def session_get_value(self, form_key, key, multi=False, multi_value=False):          """Get the value of a specific form"""          if not self.session_has_key(form_key, key, multi): @@ -1118,15 +1132,9 @@ class Wizard(NamedUrlWizardView):                      continue                  if hasattr(value, 'pk'):                      value = value.pk -                if isinstance(value, ImageFieldFile) \ +                if value in (True, False) \ +                        or isinstance(value, ImageFieldFile) \                          or isinstance(value, FileField): -                    try: -                        initial[base_field] = value.path -                    except ValueError: -                        pass -                elif value in (True, False) or \ -                   isinstance(value, FileField) or \ -                   isinstance(value, ImageFile):                      initial[base_field] = value                  elif value is not None:                      initial[base_field] = unicode(value) | 
