diff options
| -rw-r--r-- | archaeological_finds/forms_treatments.py | 28 | ||||
| -rw-r--r-- | archaeological_finds/migrations/0049_auto_20181210_1518.py | 1 | ||||
| -rw-r--r-- | archaeological_finds/models_treatments.py | 31 | 
3 files changed, 30 insertions, 30 deletions
| diff --git a/archaeological_finds/forms_treatments.py b/archaeological_finds/forms_treatments.py index 8ae0dbd36..59df12df2 100644 --- a/archaeological_finds/forms_treatments.py +++ b/archaeological_finds/forms_treatments.py @@ -195,10 +195,20 @@ class BaseTreatmentForm(CustomForm, ManageOldType):      def clean(self, *args, **kwargs):          data = self.cleaned_data -        treatment_types = data.get('treatment_type', []) +        try: +            treatment_types = [ +                models.TreatmentType.objects.get( +                    pk=pk, available=True, upstream_is_many=False, +                    downstream_is_many=False) +                for pk in data.get('treatment_type', [])] +        except models.TreatmentType.DoesNotExist: +            raise forms.ValidationError(_(u"Unknow treatment type")) +          change_current_location = [ -            unicode(tp) for tp in treatment_types if tp.change_current_location] +            unicode(tp) for tp in treatment_types +            if tp.change_current_location +        ]          restore_reference_location = [              unicode(tp) for tp in treatment_types              if tp.restore_reference_location @@ -214,7 +224,7 @@ class BaseTreatmentForm(CustomForm, ManageOldType):                  raise forms.ValidationError(                      unicode(                          _(u"{} is not compatible with {} " -                          u"treatments.")).format( +                          u"treatment(s).")).format(                          u' ; '.join(restore_reference_location),                          u' ; '.join(change_ref_location),                      ) @@ -223,22 +233,12 @@ class BaseTreatmentForm(CustomForm, ManageOldType):                  raise forms.ValidationError(                      unicode(                          _(u"{} is not compatible with {} " -                          u"treatments.")).format( +                          u"treatment(s).")).format(                          u' ; '.join(restore_reference_location),                          u' ; '.join(change_current_location)                      )                  ) -        if change_ref_location and change_current_location: -            raise forms.ValidationError( -                unicode( -                    _(u"{} is not compatible with {} " -                      u"treatments.")).format( -                    u' ; '.join(change_ref_location), -                    u' ; '.join(change_current_location) -                ) -            ) -          if data.get('container', None) \                  and not change_ref_location\                  and not change_current_location: diff --git a/archaeological_finds/migrations/0049_auto_20181210_1518.py b/archaeological_finds/migrations/0049_auto_20181210_1518.py index d2510c7fd..28f790ab0 100644 --- a/archaeological_finds/migrations/0049_auto_20181210_1518.py +++ b/archaeological_finds/migrations/0049_auto_20181210_1518.py @@ -21,6 +21,7 @@ def migrate_treatment_types(apps, schema):      if q.count():          packaging = q.all()[0]          packaging.change_reference_location = True +        packaging.change_current_location = True          packaging.save()      q = TreatmentType.objects.filter(txt_idx="virtual-reassembly")      if q.count(): diff --git a/archaeological_finds/models_treatments.py b/archaeological_finds/models_treatments.py index ee4fde0f0..ba1c29dc8 100644 --- a/archaeological_finds/models_treatments.py +++ b/archaeological_finds/models_treatments.py @@ -491,30 +491,29 @@ class Treatment(DashboardFormItem, ValueGetter, BaseHistorizedItem,          if not self.container:              return -        container_attr = None +        container_attrs = []          for tp in treatment_types:              if tp.change_current_location: -                if container_attr == 'container_ref': -                    # non consistent treatment -                    return -                container_attr = 'container' +                if 'container' in container_attrs: +                    continue +                container_attrs.append('container')              if tp.change_reference_location: -                if container_attr == 'container': -                    # non consistent treatment -                    return -                container_attr = 'container_ref' +                if 'container_ref' in container_attrs: +                    continue +                container_attrs.append('container_ref') -        if not container_attr: +        if not container_attrs:              # non consistent treatment              return          for find in q.all(): -            if getattr(find, container_attr) != self.container: -                setattr(find, container_attr, self.container) -                if find.pk in updated: -                    # don't record twice history -                    find.skip_history_when_saving = True -                find.save() +            for container_attr in container_attrs: +                if getattr(find, container_attr) != self.container: +                    setattr(find, container_attr, self.container) +                    if find.pk in updated: +                        # don't record twice history +                        find.skip_history_when_saving = True +                    find.save()      @property      def associated_filename(self): | 
