summaryrefslogtreecommitdiff
path: root/archaeological_warehouse/forms.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2019-04-10 14:12:18 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2019-04-24 19:42:35 +0200
commit8ea4687b4cecab29affd1e451f8956d8950c2d04 (patch)
treefef7928af296fc1e5005c101c6426af7bcf12ae6 /archaeological_warehouse/forms.py
parent6ae64bba6ae83ffa6caa497e895b8a1f568a484c (diff)
downloadIshtar-8ea4687b4cecab29affd1e451f8956d8950c2d04.tar.bz2
Ishtar-8ea4687b4cecab29affd1e451f8956d8950c2d04.zip
Popup: BS style - Container: improve creation form
- prevent container creation when the same reference exists - autocopy reference to location
Diffstat (limited to 'archaeological_warehouse/forms.py')
-rw-r--r--archaeological_warehouse/forms.py27
1 files changed, 22 insertions, 5 deletions
diff --git a/archaeological_warehouse/forms.py b/archaeological_warehouse/forms.py
index 99855bf0b..05e0860cb 100644
--- a/archaeological_warehouse/forms.py
+++ b/archaeological_warehouse/forms.py
@@ -183,6 +183,8 @@ class WarehouseForm(CustomForm, ManageOldType, forms.Form):
if 'person_in_charge' in dct and dct['person_in_charge']:
dct['person_in_charge'] = models.Person.objects.get(
pk=dct['person_in_charge'])
+ if not dct.get("spatial_reference_system", None):
+ dct.pop("spatial_reference_system")
new_item = models.Warehouse(**dct)
new_item.save()
return new_item
@@ -205,14 +207,14 @@ class ContainerForm(CustomForm, ManageOldType, forms.Form):
old_reference = forms.CharField(label=_(u"Old reference"), required=False,
max_length=200)
container_type = forms.ChoiceField(label=_(u"Container type"), choices=[])
- location = forms.IntegerField(
- label=_(u"Current location (warehouse)"),
+ responsible = forms.IntegerField(
+ label=_(u"Responsible warehouse"),
widget=widgets.JQueryAutoComplete(
reverse_lazy('autocomplete-warehouse'),
associated_model=models.Warehouse, new=True),
validators=[valid_id(models.Warehouse)])
- responsible = forms.IntegerField(
- label=_(u"Responsible warehouse"),
+ location = forms.IntegerField(
+ label=_(u"Current location (warehouse)"),
widget=widgets.JQueryAutoComplete(
reverse_lazy('autocomplete-warehouse'),
associated_model=models.Warehouse, new=True),
@@ -223,11 +225,26 @@ class ContainerForm(CustomForm, ManageOldType, forms.Form):
FieldType('container_type', models.ContainerType),
]
+ class Media:
+ js = ('forms/container.js',)
+
def __init__(self, *args, **kwargs):
if 'limits' in kwargs:
kwargs.pop('limits')
super(ContainerForm, self).__init__(*args, **kwargs)
+ def clean(self):
+ cleaned_data = self.cleaned_data
+ warehouse = cleaned_data.get("location")
+ q = models.Container.objects.filter(
+ reference=cleaned_data.get("reference"), location__pk=warehouse)
+ if 'pk' in cleaned_data and cleaned_data['pk']:
+ q = q.exclude(pk=int(cleaned_data['pk']))
+ if q.count():
+ raise forms.ValidationError(_(u"This reference already exists for "
+ u"this warehouse."))
+ return cleaned_data
+
def save(self, user):
dct = self.cleaned_data
dct['history_modifier'] = user
@@ -256,7 +273,7 @@ class ContainerModifyForm(ContainerForm):
def clean(self):
# manage unique ID
- cleaned_data = self.cleaned_data
+ cleaned_data = super(ContainerModifyForm, self).clean()
index = cleaned_data.get("index")
warehouse = cleaned_data.get("location")
q = models.Container.objects.filter(