diff options
Diffstat (limited to 'archaeological_operations/models.py')
| -rw-r--r-- | archaeological_operations/models.py | 41 | 
1 files changed, 30 insertions, 11 deletions
| diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index b82854f20..2db101104 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -137,8 +137,36 @@ QUALITY = (('ND', _(u"Not documented")),             ('R', _(u"Reliable")),) -class Operation(BaseHistorizedItem, OwnPerms, ValueGetter, ShortMenuItem, -                DashboardFormItem): +class ClosedItem(object): +    def closing(self): +        if self.is_active(): +            return +        in_history = False +        date = self.end_date +        # last action is closing? +        for idx, item in enumerate( +                self.history.order_by('-history_date').all()): +            if not idx: +                # last action +                continue +            if not item.end_date or item.end_date != self.end_date: +                break +            in_history = True +        user = None +        if in_history: +            if item.history_modifier_id: +                q = IshtarUser.objects.filter(pk=item.history_modifier_id) +                if q.count(): +                    user = q.all()[0] +        elif self.history_modifier_id: +            q = IshtarUser.objects.filter(pk=self.history_modifier_id) +            if q.count(): +                user = q.all()[0] +        return {'date': date, 'user': user} + + +class Operation(ClosedItem, BaseHistorizedItem, OwnPerms, ValueGetter, +                ShortMenuItem, DashboardFormItem):      QUALITY_DICT = dict(QUALITY)      SHOW_URL = 'show-operation'      TABLE_COLS = ['year_index', 'operation_type', 'remains', 'towns', @@ -423,15 +451,6 @@ class Operation(BaseHistorizedItem, OwnPerms, ValueGetter, ShortMenuItem,      def is_active(self):          return not bool(self.end_date) -    def closing(self): -        if self.is_active(): -            return -        for item in self.history.all(): -            if not item.end_date: -                break -        return {'date': item.history_date, -                'user': IshtarUser.objects.get(pk=item.history_modifier_id)} -      def save(self, *args, **kwargs):          # put a default year if start_date is defined          if self.start_date and not self.year: | 
