From 232d53380a6625c0337fde697866d4c357ef62c3 Mon Sep 17 00:00:00 2001 From: oyvinlek Date: Sat, 5 Mar 2011 22:20:08 +0000 Subject: [PATCH] La til medlemsfunksjoner i Placement-klassen. --- python/web/library/models.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/python/web/library/models.py b/python/web/library/models.py index 1621df8..3f4526f 100644 --- a/python/web/library/models.py +++ b/python/web/library/models.py @@ -206,3 +206,35 @@ class Placement(models.Model): def __unicode__(self): return self.category.name+" at "+self.shelf + + def as_list(self): + shelf = self.shelf + return [self.category, shelf[0], int(shelf[1]), int(shelf[2])] + + def get_shelf(self): + return self.shelf[0] + + def get_row(self): + return int(self.shelf[2]) + + def get_column(self): + return int(self.shelf[1]) + + @staticmethod + def shelf_as_list(shelfname): + placements = Placement.objects.filter(shelf__startswith=shelfname) + rows = max(map(lambda x: x.get_row(), placements)) + columns = max(map(lambda x: x.get_column(), placements)) + shelf_list = [ [[] for i in xrange(rows+1)] for j in xrange(columns+1)] + for placement in placements: + shelf_list[placement.get_column()][placement.get_row()].append(placement.category) + return shelf_list + + @staticmethod + def get_all_shelves(): + shelves = set() + for item in Placement.objects.all(): + shelves.add(item.get_shelf()) + return list(shelves) + +