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.py46
1 files changed, 27 insertions, 19 deletions
diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py
index 2f1ea3ea3..d46d55089 100644
--- a/archaeological_operations/models.py
+++ b/archaeological_operations/models.py
@@ -645,7 +645,7 @@ class Operation(ClosedItem, BaseHistorizedItem, ImageModel, OwnPerms,
q = self.context_record.values(
'unit', 'unit__label').distinct().order_by('label')
for res in q.all():
- nbs.append((unicode(res['unit__label']),
+ nbs.append((unicode(res['unit__label'] or "-"),
self.context_record.filter(unit=res['unit']).count()))
return list(set(nbs))
@@ -659,7 +659,7 @@ class Operation(ClosedItem, BaseHistorizedItem, ImageModel, OwnPerms,
'datings__period', 'datings__period__label').distinct().order_by(
'datings__period__order')
for res in q.all():
- nbs.append((unicode(res['datings__period__label']),
+ nbs.append((unicode(res['datings__period__label'] or "-"),
self.context_record.filter(
datings__period=res['datings__period']).count()))
return nbs
@@ -690,7 +690,7 @@ class Operation(ClosedItem, BaseHistorizedItem, ImageModel, OwnPerms,
'material_types__label')
for res in q.all():
nbs.append(
- (unicode(res['material_types__label']),
+ (unicode(res['material_types__label'] or "-"),
Find.objects.filter(
base_finds__context_record__operation=self,
upstream_treatment_id__isnull=True,
@@ -733,7 +733,7 @@ class Operation(ClosedItem, BaseHistorizedItem, ImageModel, OwnPerms,
'datings__period__order')
for res in q.all():
nbs.append(
- (unicode(res['datings__period__label']),
+ (unicode(res['datings__period__label'] or "-"),
Find.objects.filter(
base_finds__context_record__operation=self,
upstream_treatment_id__isnull=True,
@@ -924,6 +924,8 @@ class OperationSource(Source):
'operation__operation_code': _(u"Operation code"),
'code': _(u"Document code")
}
+ PARENT_SEARCH_VECTORS = Source.PARENT_SEARCH_VECTORS + ['operation']
+
# fields
operation = models.ForeignKey(Operation, verbose_name=_(u"Operation"),
@@ -984,6 +986,8 @@ class ActType(GeneralType):
verbose_name = _(u"Act type")
verbose_name_plural = _(u"Act types")
ordering = ('label',)
+
+
post_save.connect(post_save_cache, sender=ActType)
post_delete.connect(post_save_cache, sender=ActType)
@@ -1049,6 +1053,12 @@ class AdministrativeAct(BaseHistorizedItem, OwnPerms, ValueGetter):
RELATIVE_SESSION_NAMES = [('operation', 'operation__pk'),
('file', 'associated_file__pk')]
COL_LABELS = {'full_ref': _(u"Ref.")}
+ BASE_SEARCH_VECTORS = ['act_type__label', 'act_object',
+ 'towns_label']
+ INT_SEARCH_VECTORS = ["year", "index"]
+ PARENT_SEARCH_VECTORS = ['operator', 'scientist', 'signatory',
+ 'associated_file', 'operation', 'treatment_file',
+ 'treatment']
# fields
act_type = models.ForeignKey(ActType, verbose_name=_(u"Act type"))
@@ -1246,25 +1256,23 @@ class AdministrativeAct(BaseHistorizedItem, OwnPerms, ValueGetter):
if 'force' in kwargs:
force = kwargs.pop('force')
- 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)
-
- if not force:
- self._get_index()
- else:
- try:
- self._get_index()
- except:
- pass
-
+ if self.signature_date:
+ self.year = self.signature_date.year
+ if self.act_type.indexed:
+ if not force:
+ self._get_index()
+ else:
+ try:
+ self._get_index()
+ except:
+ pass
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()
+ updated = self.update_search_vector()
+ if updated:
+ self.save()
def strip_zero(value):