diff options
| -rw-r--r-- | archaeological_warehouse/forms.py | 11 | ||||
| -rw-r--r-- | archaeological_warehouse/models.py | 6 | ||||
| -rw-r--r-- | archaeological_warehouse/templates/ishtar/sheet_container.html | 1 | 
3 files changed, 16 insertions, 2 deletions
| diff --git a/archaeological_warehouse/forms.py b/archaeological_warehouse/forms.py index 110f01c9b..050a62e7d 100644 --- a/archaeological_warehouse/forms.py +++ b/archaeological_warehouse/forms.py @@ -330,11 +330,16 @@ class ContainerForm(CustomForm, ManageOldType, forms.Form):              container_type_id=cleaned_data.get("container_type"),              parent_id=cleaned_data.get("parent")          ) +        pk = None          if 'pk' in cleaned_data and cleaned_data['pk']: -            q = q.exclude(pk=int(cleaned_data['pk'])) +            pk = int(cleaned_data['pk']) +            q = q.exclude(pk=pk)          if q.count():              raise forms.ValidationError(_("This reference already exists for "                                            "this warehouse.")) +        if pk and pk == int(cleaned_data.get("parent")): +            raise forms.ValidationError(_("A container cannot be a parent of " +                                          "himself."))          return cleaned_data      def save(self, user): @@ -643,6 +648,10 @@ class QAContainerFormMulti(QAForm):                  "qaparent"]          new_tuples = []          for item in self.items: +            if new_values.get("parent_id", None) and int( +                    new_values["parent_id"]) == item.pk: +                raise forms.ValidationError( +                    _("A container cannot be a parent of himself."))              vals = {                  "container_type_id": item.container_type_id,                  "location_id": item.location_id, diff --git a/archaeological_warehouse/models.py b/archaeological_warehouse/models.py index 5d06cefda..e67fe2bd2 100644 --- a/archaeological_warehouse/models.py +++ b/archaeological_warehouse/models.py @@ -1357,6 +1357,8 @@ class Container(DocumentItem, Merge, LightHistorizedItem,          return actions      def pre_save(self): +        if self.parent == self: +            self.parent = None          if not self.collection_id and not self.collection:              if self.location_id:                  self.collection_id = self.location_id @@ -1431,10 +1433,11 @@ class Container(DocumentItem, Merge, LightHistorizedItem,  def container_post_save(sender, **kwargs):      cached_label_and_geo_changed(sender=sender, **kwargs) +    #TODO: to be deleted??? +    """      if not kwargs.get('instance'):          return      instance = kwargs.get('instance') -    #TODO: to be deleted???      for loca in ContainerLocalisation.objects.filter(              container=instance).exclude(              division__warehouse=instance.location).all(): @@ -1446,6 +1449,7 @@ def container_post_save(sender, **kwargs):              continue          loca.division = q.all()[0]          loca.save() +    """  def container_pre_delete(sender, **kwargs): diff --git a/archaeological_warehouse/templates/ishtar/sheet_container.html b/archaeological_warehouse/templates/ishtar/sheet_container.html index 0d36c253e..dd3c5b5ab 100644 --- a/archaeological_warehouse/templates/ishtar/sheet_container.html +++ b/archaeological_warehouse/templates/ishtar/sheet_container.html @@ -120,6 +120,7 @@          {% if container_type.length or container_type.width or container_type.height or container_type.volume or container_type.reference %}          <h4>{% trans "Container type" %}</h4>          <div class='row'> +            {% field_flex "Type" container_type.label %}              {% field_flex "Length (mm)" container_type.length %}              {% field_flex "Width (mm)" container_type.width %}              {% field_flex "Height (mm)" container_type.height %} | 
