diff options
Diffstat (limited to 'ishtar/furnitures/models.py')
-rw-r--r-- | ishtar/furnitures/models.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/ishtar/furnitures/models.py b/ishtar/furnitures/models.py index 0ce4ef057..3112d00f6 100644 --- a/ishtar/furnitures/models.py +++ b/ishtar/furnitures/models.py @@ -373,6 +373,7 @@ class Operation(BaseHistorizedItem, OwnPerms): remains = models.ManyToManyField("RemainType", verbose_name=_(u'Remains')) towns = models.ManyToManyField("Town", verbose_name=_(u"Towns")) cost = models.IntegerField(_(u"Cost"), blank=True, null=True) + periods = models.ManyToManyField('Period', verbose_name=_(u"Periods")) if settings.COUNTRY == 'fr': code_patriarche = models.IntegerField(u"Code PATRIARCHE", null=True, blank=True) @@ -450,6 +451,32 @@ class Period(GeneralType) : def __unicode__(self): return self.label + @classmethod + def get_types(cls, dct={}): + dct['available'] = True + yield ('', '--') + items = cls.objects.filter(**dct).all() + if not items: + return + items = sorted(items, key=lambda x: x.parent) + idx, childs = 0, {None:[]} + while idx < len(items) and not items[idx].parent: + childs[items[idx]] = [] + idx += 1 + while idx < len(items): + if items[idx].parent in childs: + childs[items[idx].parent].append(items[idx]) + else: + childs[None].append(items[idx]) + idx += 1 + for parent in sorted(childs.keys(), + key=lambda x:hasattr(x, 'order') and x.order): + if parent: + yield (parent.id, _(parent.label)) + prefix = parent and "-- " or "" + for child in sorted(childs[parent], key=lambda x:x.order): + yield (child.id, _(prefix + child.label)) + class DatingType(GeneralType): class Meta: verbose_name = _(u"Dating type") |