diff options
Diffstat (limited to 'archaeological_operations/models.py')
-rw-r--r-- | archaeological_operations/models.py | 50 |
1 files changed, 33 insertions, 17 deletions
diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index c4fd0d96e..b982e7d45 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Copyright (C) 2012-2016 Étienne Loks <etienne.loks_AT_peacefrogsDOTnet> +# Copyright (C) 2012-2017 Étienne Loks <etienne.loks_AT_peacefrogsDOTnet> # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as @@ -86,9 +86,9 @@ class ArchaeologicalSite(BaseHistorizedItem): name = models.CharField(_(u"Name"), max_length=200, null=True, blank=True) periods = models.ManyToManyField(Period, verbose_name=_(u"Periods"), - blank=True, null=True) + blank=True) remains = models.ManyToManyField("RemainType", verbose_name=_(u'Remains'), - blank=True, null=True) + blank=True) class Meta: verbose_name = _(u"Archaeological site") @@ -270,7 +270,7 @@ class Operation(ClosedItem, BaseHistorizedItem, ImageModel, OwnPerms, on_delete=models.SET_NULL, related_name='operation_responsability') collaborators = models.ManyToManyField( - Person, blank=True, null=True, verbose_name=_(u"Collaborators"), + Person, blank=True, verbose_name=_(u"Collaborators"), related_name='operation_collaborator' ) year = models.IntegerField(_(u"Year"), null=True, blank=True) @@ -284,13 +284,13 @@ class Operation(ClosedItem, BaseHistorizedItem, ImageModel, OwnPerms, verbose_name=_(u"Operation type")) surface = models.IntegerField(_(u"Surface (m2)"), blank=True, null=True) remains = models.ManyToManyField("RemainType", verbose_name=_(u'Remains'), - null=True, blank=True) + blank=True) towns = models.ManyToManyField(Town, verbose_name=_(u"Towns"), related_name='operations') cost = models.IntegerField(_(u"Cost (euros)"), blank=True, null=True) # preventive periods = models.ManyToManyField(Period, verbose_name=_(u"Periods"), - null=True, blank=True) + blank=True) # preventive scheduled_man_days = models.IntegerField(_(u"Scheduled man-days"), blank=True, null=True) @@ -343,7 +343,7 @@ class Operation(ClosedItem, BaseHistorizedItem, ImageModel, OwnPerms, null=True, blank=True) archaeological_sites = models.ManyToManyField( ArchaeologicalSite, verbose_name=_(u"Archaeological sites"), - null=True, blank=True) + blank=True) virtual_operation = models.BooleanField( _(u"Virtual operation"), default=False, help_text=_( @@ -573,12 +573,12 @@ class Operation(ClosedItem, BaseHistorizedItem, ImageModel, OwnPerms, return round(float(self.cost) / self.surface, 2) @classmethod - def get_query_owns(cls, user): + def get_query_owns(cls, ishtaruser): return ( - Q(in_charge=user.ishtaruser.person) | - Q(scientist=user.ishtaruser.person) | - Q(collaborators__pk=user.ishtaruser.person.pk) | - Q(history_creator=user)) & Q(end_date__isnull=True) + Q(in_charge=ishtaruser.person) | + Q(scientist=ishtaruser.person) | + Q(collaborators__pk=ishtaruser.person.pk) | + Q(history_creator=ishtaruser.user_ptr)) & Q(end_date__isnull=True) def is_active(self): return not bool(self.end_date) @@ -846,6 +846,22 @@ class OperationByDepartment(models.Model): """ Database view for dashboard """ + CREATE_SQL = """ + CREATE VIEW operation_department (id, department_id, operation_id) as + select town."id", town."departement_id", + operation_towns."operation_id" + from ishtar_common_town town + inner join archaeological_operations_operation_towns + operation_towns + on operation_towns."town_id"=town."id" + order by town."departement_id"; + CREATE RULE operation_department_delete + AS ON DELETE TO operation_department DO INSTEAD(); + """ + DELETE_SQL = """ + DROP VIEW operation_department; + """ + operation = models.ForeignKey(Operation, verbose_name=_(u"Operation")) department = models.ForeignKey(Department, verbose_name=_(u"Department"), blank=True, null=True) @@ -912,10 +928,10 @@ class OperationSource(Source): self.index) @classmethod - def get_query_owns(cls, user): - return (Q(operation__in_charge=user.ishtaruser.person) | - Q(operation__scientist=user.ishtaruser.person) | - Q(operation__collaborators__pk=user.ishtaruser.person.pk)) \ + def get_query_owns(cls, ishtaruser): + return (Q(operation__in_charge=ishtaruser.person) | + Q(operation__scientist=ishtaruser.person) | + Q(operation__collaborators__pk=ishtaruser.person.pk)) \ & Q(operation__end_date__isnull=True) @@ -929,7 +945,7 @@ class ActType(GeneralType): choices=TYPE) code = models.CharField(_(u"Code"), max_length=10, blank=True, null=True) associated_template = models.ManyToManyField( - DocumentTemplate, blank=True, null=True, + DocumentTemplate, blank=True, verbose_name=_(u"Associated template"), related_name='acttypes') indexed = models.BooleanField(_(u"Indexed"), default=False) |