diff options
author | Étienne Loks <etienne.loks@proxience.com> | 2014-05-10 20:05:08 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@proxience.com> | 2014-05-10 20:05:08 +0200 |
commit | a66491533627ec4911fe7b466f174a5f704291e5 (patch) | |
tree | 6ec26ee9425c2691c2faa7678da7f65f9e82193b /archaeological_operations/models.py | |
parent | e706b4cb2a2a42e32f6572146862870d1ae54f1c (diff) | |
download | Ishtar-a66491533627ec4911fe7b466f174a5f704291e5.tar.bz2 Ishtar-a66491533627ec4911fe7b466f174a5f704291e5.zip |
Manage operation type order (refs #1685)
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=''): |