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.py317
1 files changed, 161 insertions, 156 deletions
diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py
index c7a8c94ac..9f81a0e1c 100644
--- a/archaeological_operations/models.py
+++ b/archaeological_operations/models.py
@@ -134,8 +134,9 @@ class ArchaeologicalSite(BaseHistorizedItem):
class Operation(BaseHistorizedItem, OwnPerms, ValueGetter, ShortMenuItem):
TABLE_COLS = ['year_index', 'operation_type', 'remains', 'towns',
- 'associated_file_short_label', 'start_date',
- 'excavation_end_date']
+ 'start_date', 'excavation_end_date']
+ if FILES_AVAILABLE:
+ TABLE_COLS.insert(4, 'associated_file_short_label')
start_date = models.DateField(_(u"Start date"), null=True, blank=True)
excavation_end_date = models.DateField(_(u"Excavation end date"), null=True,
blank=True)
@@ -322,7 +323,7 @@ class Operation(BaseHistorizedItem, OwnPerms, ValueGetter, ShortMenuItem):
associated_file_short_label_lbl = _(u"Archaeological file")
@property
def associated_file_short_label(self):
- if not self.associated_file:
+ if not FILES_AVAILABLE or not self.associated_file:
return ""
return self.associated_file.short_label
@@ -434,7 +435,7 @@ def operation_post_save(sender, **kwargs):
operation.fnap_financing = fnap_percent
operation.save()
cached_label_changed(sender, **kwargs)
- if operation.associated_file:
+ if FILES_AVAILABLE and operation.associated_file:
operation.associated_file.update_short_menu_class()
post_save.connect(operation_post_save, sender=Operation)
@@ -491,161 +492,163 @@ class ActType(GeneralType):
verbose_name_plural = _(u"Act types")
ordering = ('label',)
-class AdministrativeAct(BaseHistorizedItem, OwnPerms, ValueGetter):
- TABLE_COLS = ['full_ref', 'year', 'index', 'act_type', 'signature_date',
- 'associated_file', 'operation']
- TABLE_COLS_FILE = ['full_ref', 'year', 'index', 'act_type', 'associated_file',
- 'associated_file.towns',]
- TABLE_COLS_OPE = ['full_ref', 'year', 'index', 'act_type', 'operation',
- 'operation.towns']
- act_type = models.ForeignKey(ActType, verbose_name=_(u"Act type"))
- in_charge = models.ForeignKey(Person, blank=True, null=True,
- related_name='adminact_operation_in_charge',
- verbose_name=_(u"Person in charge of the operation"),
- on_delete=models.SET_NULL,)
- index = models.IntegerField(verbose_name=_(u"Index"), blank=True, null=True)
- operator = models.ForeignKey(Organization, blank=True, null=True,
- verbose_name=_(u"Archaeological preventive operator"),
- related_name='adminact_operator',
- on_delete=models.SET_NULL)
- scientist = models.ForeignKey(Person, blank=True, null=True,
- related_name='adminact_scientist', on_delete=models.SET_NULL,
- verbose_name=_(u"Scientist in charge"))
- signatory = models.ForeignKey(Person, blank=True, null=True,
- related_name='signatory', verbose_name=_(u"Signatory"),
- on_delete=models.SET_NULL,)
- operation = models.ForeignKey(Operation, blank=True, null=True,
- related_name='administrative_act', verbose_name=_(u"Operation"))
- if FILES_AVAILABLE:
- associated_file = models.ForeignKey('archaeological_files.File',
- blank=True, null=True,
- related_name='administrative_act',
- verbose_name=_(u"Archaelogical file"))
- signature_date = models.DateField(_(u"Signature date"), blank=True,
+AdministrativeAct = None
+if FILES_AVAILABLE:
+ class AdministrativeAct(BaseHistorizedItem, OwnPerms, ValueGetter):
+ TABLE_COLS = ['full_ref', 'year', 'index', 'act_type', 'signature_date',
+ 'associated_file', 'operation']
+ TABLE_COLS_FILE = ['full_ref', 'year', 'index', 'act_type', 'associated_file',
+ 'associated_file.towns',]
+ TABLE_COLS_OPE = ['full_ref', 'year', 'index', 'act_type', 'operation',
+ 'operation.towns']
+ act_type = models.ForeignKey(ActType, verbose_name=_(u"Act type"))
+ in_charge = models.ForeignKey(Person, blank=True, null=True,
+ related_name='adminact_operation_in_charge',
+ verbose_name=_(u"Person in charge of the operation"),
+ on_delete=models.SET_NULL,)
+ index = models.IntegerField(verbose_name=_(u"Index"), blank=True, null=True)
+ operator = models.ForeignKey(Organization, blank=True, null=True,
+ verbose_name=_(u"Archaeological preventive operator"),
+ related_name='adminact_operator',
+ on_delete=models.SET_NULL)
+ scientist = models.ForeignKey(Person, blank=True, null=True,
+ related_name='adminact_scientist', on_delete=models.SET_NULL,
+ verbose_name=_(u"Scientist in charge"))
+ signatory = models.ForeignKey(Person, blank=True, null=True,
+ related_name='signatory', verbose_name=_(u"Signatory"),
+ on_delete=models.SET_NULL,)
+ operation = models.ForeignKey(Operation, blank=True, null=True,
+ related_name='administrative_act', verbose_name=_(u"Operation"))
+ if FILES_AVAILABLE:
+ associated_file = models.ForeignKey('archaeological_files.File',
+ blank=True, null=True,
+ related_name='administrative_act',
+ verbose_name=_(u"Archaelogical file"))
+ signature_date = models.DateField(_(u"Signature date"), blank=True,
+ null=True)
+ year = models.IntegerField(_(u"Year"), blank=True, null=True)
+ act_object = models.TextField(_(u"Object"), max_length=300, blank=True,
null=True)
- year = models.IntegerField(_(u"Year"), blank=True, null=True)
- act_object = models.TextField(_(u"Object"), max_length=300, blank=True,
- null=True)
- if settings.COUNTRY == 'fr':
- ref_sra = models.CharField(u"Référence SRA", max_length=15, blank=True,
- null=True)
- history = HistoricalRecords()
- _prefix = 'adminact_'
-
- class Meta:
- ordering = ('year', 'index', 'act_type')
- verbose_name = _(u"Administrative act")
- verbose_name_plural = _(u"Administrative acts")
- permissions = (
- ("view_administrativeact",
- ugettext(u"Can view all Administrative act")),
- ("view_own_administrativeact",
- ugettext(u"Can view own Administrative act")),
- ("add_own_administrativeact",
- ugettext(u"Can add own Administrative act")),
- ("change_own_administrativeact",
- ugettext(u"Can change own Administrative act")),
- ("delete_own_administrativeact",
- ugettext(u"Can delete own Administrative act")),
- )
-
- def __unicode__(self):
- return settings.JOINT.join([unicode(item)
- for item in [self.operation, self.associated_file, self.act_object]
- if item])
-
- full_ref_lbl = _(u"Ref.")
- @property
- def full_ref(self):
- lbl = []
- if self.year:
- lbl.append(unicode(self.year))
- if self.index:
- lbl.append(u"n°%d" %self.index)
- if settings.COUNTRY == 'fr' and self.ref_sra:
- lbl.append(u"[%s]" % self.ref_sra)
- return u" ".join(lbl)
-
- @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")
+ if settings.COUNTRY == 'fr':
+ ref_sra = models.CharField(u"Référence SRA", max_length=15, blank=True,
+ null=True)
+ history = HistoricalRecords()
+ _prefix = 'adminact_'
+
+ class Meta:
+ ordering = ('year', 'index', 'act_type')
+ verbose_name = _(u"Administrative act")
+ verbose_name_plural = _(u"Administrative acts")
+ permissions = (
+ ("view_administrativeact",
+ ugettext(u"Can view all Administrative act")),
+ ("view_own_administrativeact",
+ ugettext(u"Can view own Administrative act")),
+ ("add_own_administrativeact",
+ ugettext(u"Can add own Administrative act")),
+ ("change_own_administrativeact",
+ ugettext(u"Can change own Administrative act")),
+ ("delete_own_administrativeact",
+ ugettext(u"Can delete own Administrative act")),
+ )
- @property
- def related_item(self):
- return self.operation if self.operation else self.associated_file
-
- def get_filename(self):
- filename = self.related_item.associated_filename
- filename = u"-".join(filename.split('-')[:-1]) # remove date
- if self.act_type.code:
- filename += u"-" + self.act_type.code
- if self.signature_date and self.index:
- filename += u"-%d-%d" % (self.signature_date.year,
- self.index)
- if self.signature_date:
- filename += u"-" + self.signature_date.strftime('%Y%m%d')
- return filename
-
- def publish(self, template_pk=None):
- if not self.act_type.associated_template.count():
- return
- if not template_pk:
- template = self.act_type.associated_template.all()[0]
- else:
- q = self.act_type.associated_template.filter(pk=template_pk)
- if not q.count():
+ def __unicode__(self):
+ return settings.JOINT.join([unicode(item)
+ for item in [self.operation, self.associated_file, self.act_object]
+ if item])
+
+ full_ref_lbl = _(u"Ref.")
+ @property
+ def full_ref(self):
+ lbl = []
+ if self.year:
+ lbl.append(unicode(self.year))
+ if self.index:
+ lbl.append(u"n°%d" %self.index)
+ if settings.COUNTRY == 'fr' and self.ref_sra:
+ lbl.append(u"[%s]" % self.ref_sra)
+ return u" ".join(lbl)
+
+ @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")
+
+ @property
+ def related_item(self):
+ return self.operation if self.operation else self.associated_file
+
+ def get_filename(self):
+ filename = self.related_item.associated_filename
+ filename = u"-".join(filename.split('-')[:-1]) # remove date
+ if self.act_type.code:
+ filename += u"-" + self.act_type.code
+ if self.signature_date and self.index:
+ filename += u"-%d-%d" % (self.signature_date.year,
+ self.index)
+ if self.signature_date:
+ filename += u"-" + self.signature_date.strftime('%Y%m%d')
+ return filename
+
+ def publish(self, template_pk=None):
+ if not self.act_type.associated_template.count():
return
- template = q.all()[0]
- return template.publish(self)
-
- def _get_index(self):
- if not self.index:
- c_index = 1
- q = AdministrativeAct.objects.filter(act_type__indexed=True,
- signature_date__year=self.year,
- index__isnull=False).order_by("-index")
- if q.count():
- c_index = q.all()[0].index + 1
- self.index = c_index
- conflict = AdministrativeAct.objects.filter(act_type__indexed=True,
- signature_date__year=self.year,
- index=self.index)
- if self.pk:
- conflict = conflict.exclude(pk=self.pk)
- if conflict.count():
- if self.pk:
- raise ValidationError(_(u"This index already exists for "
- u"this year"))
+ if not template_pk:
+ template = self.act_type.associated_template.all()[0]
else:
- self._get_index()
-
- def clean(self, *args, **kwargs):
- if not self.signature_date:
- return super(AdministrativeAct, self).clean(*args, **kwargs)
- self.year = self.signature_date.year
- if not self.act_type.indexed:
- return super(AdministrativeAct, self).clean(*args, **kwargs)
- self._get_index()
- super(AdministrativeAct, self).clean(*args, **kwargs)
-
- 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)
- if hasattr(self, 'associated_file') and self.associated_file:
- self.associated_file.update_has_admin_act()
- self.associated_file.update_short_menu_class()
+ q = self.act_type.associated_template.filter(pk=template_pk)
+ if not q.count():
+ return
+ template = q.all()[0]
+ return template.publish(self)
+
+ def _get_index(self):
+ if not self.index:
+ c_index = 1
+ q = AdministrativeAct.objects.filter(act_type__indexed=True,
+ signature_date__year=self.year,
+ index__isnull=False).order_by("-index")
+ if q.count():
+ c_index = q.all()[0].index + 1
+ self.index = c_index
+ conflict = AdministrativeAct.objects.filter(act_type__indexed=True,
+ signature_date__year=self.year,
+ index=self.index)
+ if self.pk:
+ conflict = conflict.exclude(pk=self.pk)
+ if conflict.count():
+ if self.pk:
+ raise ValidationError(_(u"This index already exists for "
+ u"this year"))
+ else:
+ self._get_index()
+
+ def clean(self, *args, **kwargs):
+ if not self.signature_date:
+ return super(AdministrativeAct, self).clean(*args, **kwargs)
+ self.year = self.signature_date.year
+ if not self.act_type.indexed:
+ return super(AdministrativeAct, self).clean(*args, **kwargs)
+ self._get_index()
+ super(AdministrativeAct, self).clean(*args, **kwargs)
+
+ 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)
+ if hasattr(self, 'associated_file') and self.associated_file:
+ self.associated_file.update_has_admin_act()
+ self.associated_file.update_short_menu_class()
def strip_zero(value):
for idx, nb in enumerate(value):
@@ -720,7 +723,9 @@ class Parcel(LightHistorizedItem):
return res
def long_label(self):
- items = [unicode(self.operation or self.associated_file)]
+ items = [unicode(self.operation) or
+ (FILES_AVAILABLE and unicode(self.associated_file)) or
+ ""]
items += [unicode(item) for item in [self.section, self.parcel_number]
if item]
return settings.JOINT.join(items)