summaryrefslogtreecommitdiff
path: root/archaeological_operations
diff options
context:
space:
mode:
Diffstat (limited to 'archaeological_operations')
-rw-r--r--archaeological_operations/forms.py8
-rw-r--r--archaeological_operations/models.py26
2 files changed, 21 insertions, 13 deletions
diff --git a/archaeological_operations/forms.py b/archaeological_operations/forms.py
index a426eaf09..efbd279ed 100644
--- a/archaeological_operations/forms.py
+++ b/archaeological_operations/forms.py
@@ -268,7 +268,7 @@ class OperationFormSelection(forms.Form):
raise forms.ValidationError(_(u"You should select an operation."))
return cleaned_data
-class OperationCodeInput(forms.HiddenInput):
+class OperationCodeInput(forms.TextInput):
"""Manage auto complete when changing year in form"""
def render(self, *args, **kwargs):
name, value = args
@@ -349,8 +349,8 @@ class OperationFormGeneral(forms.Form):
validators=[validators.MinValueValidator(1900),
validators.MaxValueValidator(2100)])
operation_code = forms.IntegerField(label=_(u"Operation code"),
- initial=models.Operation.get_available_operation_code,
- widget=OperationCodeInput)
+ initial=models.Operation.get_available_operation_code,
+ widget=OperationCodeInput(attrs={'readonly':'readonly'}))
common_name = forms.CharField(label=_(u"Generic name"), required=False,
max_length=120, widget=forms.Textarea)
operator_reference = forms.CharField(label=_(u"Operator reference"),
@@ -383,6 +383,8 @@ class OperationFormGeneral(forms.Form):
super(OperationFormGeneral, self).__init__(*args, **kwargs)
self.fields['operation_type'].choices = models.OperationType.get_types()
self.fields['operation_type'].help_text = models.OperationType.get_help()
+ if kwargs and kwargs['data']: # data POSTED
+ self.fields['operation_code'].widget.attrs.pop('readonly')
def clean(self):
cleaned_data = self.cleaned_data
diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py
index 8b083d4be..c6e55f03b 100644
--- a/archaeological_operations/models.py
+++ b/archaeological_operations/models.py
@@ -573,14 +573,7 @@ class AdministrativeAct(BaseHistorizedItem, OwnPerms, ValueGetter):
template = q.all()[0]
return template.publish(self)
- def save(self, *args, **kwargs):
- if not self.signature_date:
- return super(AdministrativeAct, self).save(*args, **kwargs)
- self.year = self.signature_date.year
-
- if not self.act_type.indexed:
- return super(AdministrativeAct, self).save(*args, **kwargs)
-
+ def _get_index(self):
if not self.index:
c_index = 1
q = AdministrativeAct.objects.filter(act_type__indexed=True,
@@ -595,8 +588,21 @@ class AdministrativeAct(BaseHistorizedItem, OwnPerms, ValueGetter):
if self.pk:
conflict = conflict.exclude(pk=self.pk)
if conflict.count():
- raise ValidationError(_(u"This index already exists for "
- u"this year"))
+ if self.pk:
+ raise ValidationError(_(u"This index already exists for "
+ u"this year"))
+ else:
+ self._get_index()
+
+ def save(self, *args, **kwargs):
+ if not self.signature_date:
+ return super(AdministrativeAct, self).save(*args, **kwargs)
+ self.year = self.signature_date.year
+
+ if not self.act_type.indexed:
+ return super(AdministrativeAct, self).save(*args, **kwargs)
+
+ self._get_index()
super(AdministrativeAct, self).save(*args, **kwargs)
class Parcel(LightHistorizedItem):