summaryrefslogtreecommitdiff
path: root/ishtar/furnitures/models.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@peacefrogs.net>2011-02-11 01:03:00 +0100
committerÉtienne Loks <etienne.loks@peacefrogs.net>2011-02-11 01:03:00 +0100
commitcfb18b8ba86967121d4ec552b410f346441ae8d6 (patch)
treeaf9ff9bcf86038fdb7d434341c57d3f6b2a887d1 /ishtar/furnitures/models.py
parent05644cc3f86c2635374a6b6e442084f8254f3a8f (diff)
downloadIshtar-cfb18b8ba86967121d4ec552b410f346441ae8d6.tar.bz2
Ishtar-cfb18b8ba86967121d4ec552b410f346441ae8d6.zip
Operation are linked to periods (closes #155)
Diffstat (limited to 'ishtar/furnitures/models.py')
-rw-r--r--ishtar/furnitures/models.py27
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")