diff options
Diffstat (limited to 'archaeological_operations/models.py')
| -rw-r--r-- | archaeological_operations/models.py | 29 | 
1 files changed, 29 insertions, 0 deletions
| diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index 2956444f8..65f544721 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -37,10 +37,39 @@ from ishtar_common.models import GeneralType, BaseHistorizedItem, \  FILES_AVAILABLE = 'archaeological_files' in settings.INSTALLED_APPS  class OperationType(GeneralType): +    order = models.IntegerField(_(u"Order"), default=1)      preventive = models.BooleanField(_(u"Is preventive"), default=True)      class Meta:          verbose_name = _(u"Operation type")          verbose_name_plural = _(u"Operation types") +        ordering = ['-preventive', 'order', 'label'] + +    @classmethod +    def get_types(cls, dct={}, instances=False, exclude=[], empty_first=True, +                 default=None): +        tuples = [] +        dct['available'] = True +        if not instances and empty_first and not default: +            tuples.append(('', '--')) +        if default: +            try: +                default = cls.objects.get(txt_idx=default) +                tuples.append((default.pk, _(unicode(default)))) +            except cls.DoesNotExist: +                pass +        items = cls.objects.filter(**dct) +        current_preventive, current_lst = None, None +        for item in items.order_by(*cls._meta.ordering).all(): +            if not current_lst or item.preventive != current_preventive: +                if current_lst: +                    tuples.append(current_lst) +                current_lst = [_(u"Preventive") if item.preventive else\ +                               _(u"Research"), []] +                current_preventive = item.preventive +            current_lst[1].append((item.pk, _(unicode(item)))) +        if current_lst: +            tuples.append(current_lst) +        return tuples      @classmethod      def is_preventive(cls, ope_type_id, key=''): | 
