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.py54
1 files changed, 44 insertions, 10 deletions
diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py
index bc2169009..e741f5644 100644
--- a/archaeological_operations/models.py
+++ b/archaeological_operations/models.py
@@ -227,7 +227,7 @@ class Operation(ClosedItem, BaseHistorizedItem, ImageModel, OwnPerms,
'context_record__base_finds__find__upstream_treatment__id'
}
- EXTRA_FULL_FIELDS_LABELS = {
+ COL_LABELS = {
'full_code_patriarche': u"Code patriarche",
'associated_file_short_label': _(u"Associated file (label)"),
'operator__name': _(u"Operator name"),
@@ -331,6 +331,7 @@ class Operation(ClosedItem, BaseHistorizedItem, ImageModel, OwnPerms,
operator_reference = models.CharField(
_(u"Operator reference"), max_length=20, null=True, blank=True)
common_name = models.TextField(_(u"Generic name"), null=True, blank=True)
+ address = models.TextField(_(u"Address / Locality"), null=True, blank=True)
comment = models.TextField(_(u"General comment"), null=True, blank=True)
scientific_documentation_comment = models.TextField(
_(u"Comment about scientific documentation"), null=True, blank=True)
@@ -404,6 +405,10 @@ class Operation(ClosedItem, BaseHistorizedItem, ImageModel, OwnPerms,
return _(u"OPE")
@property
+ def external_id(self):
+ return self.code_patriarche
+
+ @property
def short_label(self):
if settings.COUNTRY == 'fr':
return self.reference
@@ -417,6 +422,10 @@ class Operation(ClosedItem, BaseHistorizedItem, ImageModel, OwnPerms,
def show_url(self):
return reverse('show-operation', args=[self.pk, ''])
+ def towns_codes(self):
+ return [u"{} ({})".format(town.name, town.numero_insee) for town in
+ self.towns.all()]
+
def has_finds(self):
from archaeological_finds.models import BaseFind
return BaseFind.objects.filter(context_record__operation=self).count()
@@ -498,6 +507,12 @@ class Operation(ClosedItem, BaseHistorizedItem, ImageModel, OwnPerms,
return FindSource.objects.filter(
find__base_finds__context_record__operation=self)
+ def containers_q(self):
+ from archaeological_warehouse.models import Container
+ return Container.objects.filter(
+ finds__base_finds__context_record__operation=self
+ )
+
associated_file_short_label_lbl = _(u"Archaeological file")
full_code_patriarche_lbl = _(u"Code patriarche")
@@ -843,8 +858,8 @@ class OperationByDepartment(models.Model):
class OperationSource(Source):
SHOW_URL = 'show-operationsource'
MODIFY_URL = 'operation_source_modify'
- TABLE_COLS = ['operation.year', 'operation.operation_code', 'index'] + \
- Source.TABLE_COLS
+ TABLE_COLS = ['operation__code_patriarche', 'operation__year',
+ 'operation__operation_code', 'code'] + Source.TABLE_COLS
# search parameters
BOOL_FIELDS = ['duplicate']
@@ -859,6 +874,11 @@ class OperationSource(Source):
'operation__code_patriarche': 'operation__code_patriarche',
'operation__operation_type': 'operation__operation_type__pk',
'operation__year': 'operation__year'}
+ COL_LABELS = {
+ 'operation__year': _(u"Operation year"),
+ 'operation__operation_code': _(u"Operation code"),
+ 'code': _(u"Document code")
+ }
# fields
operation = models.ForeignKey(Operation, verbose_name=_(u"Operation"),
@@ -886,6 +906,11 @@ class OperationSource(Source):
def owner(self):
return self.operation
+ @property
+ def code(self):
+ return u"{}-{:04d}".format(self.operation.code_patriarche or '',
+ self.index)
+
class ActType(GeneralType):
TYPE = (('F', _(u'Archaeological file')),
@@ -969,6 +994,7 @@ class AdministrativeAct(BaseHistorizedItem, OwnPerms, ValueGetter):
REVERSED_BOOL_FIELDS = ['index__isnull']
RELATIVE_SESSION_NAMES = [('operation', 'operation__pk'),
('file', 'associated_file__pk')]
+ COL_LABELS = {'full_ref': _(u"Ref.")}
# fields
act_type = models.ForeignKey(ActType, verbose_name=_(u"Act type"))
@@ -1647,7 +1673,7 @@ class OperationDashboard:
.annotate(number=Sum('surface')).all()
val = 0
if area_res:
- val = area_res[0].number
+ val = (area_res[0].number or 0) / 10000.0
dct_res[res_key].append(val)
# TODO...
res_keys = [('manday_realised', current_realisation_year_ope)]
@@ -1682,7 +1708,11 @@ class OperationDashboard:
.annotate(area=Sum('surface'))\
.order_by('scientist__attached_to__name').all()
# TODO: man-days, man-days/hectare
- dct_res[res_key] = org_res
+
+ dct_res[res_key] = []
+ for vals in org_res:
+ vals['area'] = (vals['area'] or 0) / 10000.0
+ dct_res[res_key].append(vals)
year_ope = Operation.objects.filter(**operation_type)
res_keys = ['org_by_year']
@@ -1717,7 +1747,7 @@ class OperationDashboard:
cost=Sum('cost'))
years_dct = {}
for yr in org_res.all():
- area = yr['area'] if yr['area'] else 0
+ area = (yr['area'] if yr['area'] else 0) / 10000.0
cost = yr['cost'] if yr['cost'] else 0
years_dct[yr[key_date]] = (area, cost)
r_years = []
@@ -1748,7 +1778,8 @@ class OperationDashboard:
self.survey['effective'] = []
for yr in self.years:
year_res = Operation.objects\
- .filter(scientist__isnull=False, year=yr)\
+ .filter(scientist__isnull=False, year=yr,
+ operation_type__txt_idx__in=ope_types)\
.annotate(number=Sum('surface'), mean=Avg('surface'))
nb = year_res[0].number if year_res.count() else 0
nb = nb if nb else 0
@@ -1820,9 +1851,12 @@ class OperationDashboard:
dct_years = {}
for v in vals:
values = []
- for value in (v['number'], v['area'], v['cost'],
- v['fnap']):
- values.append(value if value else 0)
+ for k in ('number', 'area', 'cost', 'fnap'):
+ value = v[k] or 0
+ if k == 'area':
+ value /= 10000.0
+ values.append(value)
+
dct_years[v['operation__year']] = values
years = []
for y in self.years: