diff options
author | Étienne Loks <etienne.loks@peacefrogs.net> | 2014-02-20 13:09:03 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@peacefrogs.net> | 2014-02-20 13:09:03 +0100 |
commit | c7a866fa44e6d46662337a9d7834a099f6e3cc22 (patch) | |
tree | 6ee2b89fc33d08825d3b3d347a916086df5722aa /archaeological_operations/models.py | |
parent | 9f3ff1e55ac1ae4055093c8571d1e7ef49684fdd (diff) | |
download | Ishtar-c7a866fa44e6d46662337a9d7834a099f6e3cc22.tar.bz2 Ishtar-c7a866fa44e6d46662337a9d7834a099f6e3cc22.zip |
Operations: in_charge -> scientist - new field in_charge (refs #1600)
* model update
* forms update
* templates update
* search update
* operation owned update
Diffstat (limited to 'archaeological_operations/models.py')
-rw-r--r-- | archaeological_operations/models.py | 57 |
1 files changed, 31 insertions, 26 deletions
diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index 6915f4440..6a90b92b7 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -112,6 +112,9 @@ class Operation(BaseHistorizedItem, OwnPerms, ValueGetter): end_date = models.DateField(_(u"Closing date"), null=True, blank=True) report_delivery_date = models.DateField(_(u"Report delivery date"), null=True, blank=True) + scientist = models.ForeignKey(Person, blank=True, null=True, + verbose_name=_(u"In charge scientist"), + related_name='operation_scientist_responsability') in_charge = models.ForeignKey(Person, blank=True, null=True, verbose_name=_(u"In charge"), related_name='operation_responsability') @@ -317,8 +320,8 @@ class Operation(BaseHistorizedItem, OwnPerms, ValueGetter): @classmethod def get_query_owns(cls, user): - return Q(in_charge=user.person)|Q(history_modifier=user)\ - & Q(end_date__isnull=True) + return Q(in_charge=user.person)|Q(scientist=user.person)|\ + Q(history_modifier=user) & Q(end_date__isnull=True) def is_active(self): return not bool(self.end_date) @@ -403,9 +406,9 @@ class AdministrativeAct(BaseHistorizedItem, OwnPerms, ValueGetter): 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")) - scientific = models.ForeignKey(Person, blank=True, null=True, + scientist = models.ForeignKey(Person, blank=True, null=True, related_name='+', - verbose_name=_(u"Person in charge of the scientific part")) + verbose_name=_(u"Scientist in charge")) signatory = models.ForeignKey(Person, blank=True, null=True, related_name='+', verbose_name=_(u"Signatory")) operation = models.ForeignKey(Operation, blank=True, null=True, @@ -600,8 +603,8 @@ class OperationDashboard: 'documented', 'closed', 'documented_closed'] filters = { 'recorded':{}, - 'effective':{'in_charge__isnull':False}, - 'active':{'in_charge__isnull':False, 'end_date__isnull':True}, + 'effective':{'scientist__isnull':False}, + 'active':{'scientist__isnull':False, 'end_date__isnull':True}, 'field':{'excavation_end_date__isnull':True}, 'documented':{'source__isnull':False}, 'documented_closed':{'source__isnull':False, @@ -693,7 +696,7 @@ class OperationDashboard: self.effective = [] for typ in self.types: - year_res = Operation.objects.filter(**{'in_charge__isnull':False, + year_res = Operation.objects.filter(**{'scientist__isnull':False, 'operation_type':typ}).\ values('year').\ annotate(number=Count('pk')).\ @@ -840,11 +843,11 @@ class OperationDashboard: if dct_res == self.survey: res_keys.append(('org', current_year_ope)) for res_key, base_ope in res_keys: - org_res = base_ope.filter(in_charge__attached_to__isnull=False)\ - .values('in_charge__attached_to', - 'in_charge__attached_to__name')\ + org_res = base_ope.filter(scientist__attached_to__isnull=False)\ + .values('scientist__attached_to', + 'scientist__attached_to__name')\ .annotate(area=Sum('surface'))\ - .order_by('in_charge__attached_to__name').all() + .order_by('scientist__attached_to__name').all() # TODO: man-days, man-days/hectare dct_res[res_key] = org_res @@ -853,12 +856,12 @@ class OperationDashboard: res_keys = ['org_by_year'] if dct_res == self.survey: res_keys.append('org_by_year_realised') - q = year_ope.values('in_charge__attached_to', - 'in_charge__attached_to__name').\ - filter(in_charge__attached_to__isnull=False).\ - order_by('in_charge__attached_to__name').distinct() - org_list = [(org['in_charge__attached_to'], - org['in_charge__attached_to__name']) for org in q] + q = year_ope.values('scientist__attached_to', + 'scientist__attached_to__name').\ + filter(scientist__attached_to__isnull=False).\ + order_by('scientist__attached_to__name').distinct() + org_list = [(org['scientist__attached_to'], + org['scientist__attached_to__name']) for org in q] org_list_dct = dict(org_list) for res_key in res_keys: dct_res[res_key] = [] @@ -866,7 +869,7 @@ class OperationDashboard: if res_key == 'org_by_year_realised': years = self.realisation_years for org_id, org_label in org_list: - org_res = year_ope.filter(in_charge__attached_to__pk=org_id) + org_res = year_ope.filter(scientist__attached_to__pk=org_id) key_date = '' if res_key == 'org_by_year': org_res = org_res.values('year') @@ -910,10 +913,12 @@ class OperationDashboard: if dct_res == self.survey: self.survey['effective'] = [] for yr in self.years: - year_res = Operation.objects.filter(in_charge__isnull=False, - year=yr).\ - annotate(number=Sum('surface'), - mean=Avg('surface')) + year_res = Operation.objects.filter( + scientist__isnull=False, + year=yr + ).annotate( + number=Sum('surface'), + mean=Avg('surface')) nb = year_res[0].number if year_res.count() else 0 nb = nb if nb else 0 mean = year_res[0].mean if year_res.count() else 0 @@ -971,7 +976,7 @@ class OperationDashboard: for dpt_id, dpt_label in self.departments: vals = OperationByDepartment.objects\ .filter(department__pk=dpt_id, - operation__in_charge__isnull=False, + operation__scientist__isnull=False, operation__operation_type__txt_idx__in=ope_types)\ .values('department__pk', 'operation__year')\ .annotate(number=Count('operation'), @@ -997,7 +1002,7 @@ class OperationDashboard: OperationTown = Operation.towns.through query = OperationTown.objects\ - .filter(operation__in_charge__isnull=False, + .filter(operation__scientist__isnull=False, operation__operation_type__txt_idx__in=ope_types)\ .values('town__name', 'town__departement__number')\ .annotate(nb=Count('operation'))\ @@ -1010,7 +1015,7 @@ class OperationDashboard: if dct_res == self.survey: query = OperationTown.objects\ - .filter(operation__in_charge__isnull=False, + .filter(operation__scientist__isnull=False, operation__operation_type__txt_idx__in=ope_types, operation__surface__isnull=False)\ .values('town__name', 'town__departement__number')\ @@ -1023,7 +1028,7 @@ class OperationDashboard: r['nb'])) else: query = OperationTown.objects\ - .filter(operation__in_charge__isnull=False, + .filter(operation__scientist__isnull=False, operation__operation_type__txt_idx__in=ope_types, operation__cost__isnull=False)\ .values('town__name', 'town__departement__number')\ |