summaryrefslogtreecommitdiff
path: root/archaeological_operations/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'archaeological_operations/models.py')
-rw-r--r--archaeological_operations/models.py28
1 files changed, 23 insertions, 5 deletions
diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py
index 7648dd6bf..bbffe023f 100644
--- a/archaeological_operations/models.py
+++ b/archaeological_operations/models.py
@@ -25,6 +25,7 @@ from django.contrib.gis.db import models
from django.core.urlresolvers import reverse
from django.db.models import Q, Count, Sum, Max, Avg
from django.db.models.signals import post_save, m2m_changed
+from django.forms import ValidationError
from django.utils.translation import ugettext_lazy as _, ugettext
from ishtar_common.utils import cached_label_changed
@@ -390,8 +391,8 @@ class ActType(GeneralType):
ordering = ('label',)
class AdministrativeAct(BaseHistorizedItem, OwnPerms, ValueGetter):
- TABLE_COLS = ['act_type', 'associated_file', 'operation',
- 'associated_file.towns', 'operation.towns']
+ TABLE_COLS = ['year', 'index', 'act_type', 'signature_date',
+ 'associated_file', 'operation']
TABLE_COLS_FILE = ['act_type', 'associated_file', 'associated_file.towns',]
TABLE_COLS_OPE = ['act_type', 'operation', 'operation.towns']
act_type = models.ForeignKey(ActType, verbose_name=_(u"Act type"))
@@ -441,6 +442,22 @@ class AdministrativeAct(BaseHistorizedItem, OwnPerms, ValueGetter):
for item in [self.operation, self.associated_file, self.act_object]
if item])
+ @property
+ def year(self):
+ if not self.signature_date:
+ return None
+ return self.signature_date.year
+ year_lbl = _(u"Year")
+
+ @property
+ def towns(self):
+ if self.associated_file:
+ return self.associated_file.towns.all()
+ elif self.operation:
+ return self.operation.towns.all()
+ return []
+ towns_lbl = _(u"Towns")
+
def get_filename(self, operation=False):
filename = ''
if operation and self.operation:
@@ -473,13 +490,14 @@ class AdministrativeAct(BaseHistorizedItem, OwnPerms, ValueGetter):
if not self.index:
c_index = 1
q = AdministrativeAct.objects.filter(act_type__indexed=True,
- signature_date__year=year).order_by("-index")
+ signature_date__year=year,
+ index__isnull=False).order_by("-index")
if q.count():
- c_index = q.all()[0].index
+ c_index = q.all()[0].index + 1
self.index = c_index
if self.act_type.indexed:
conflict = AdministrativeAct.objects.filter(act_type__indexed=True,
- signature_date__year=year
+ signature_date__year=year,
index=self.index)
if self.pk:
conflict = conflict.exclude(pk=self.pk)