aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSix <unknown>2011-05-19 00:09:05 -0400
committerSix <unknown>2011-05-19 00:09:05 -0400
commiteed3f81529d7f0109b554031c9121cb5be1a2137 (patch)
tree89f9afbeda36a5e0e3b7e444c04c01e3f26b2f34
parent59534cc14e8d58554b40ce68769c834791a4be96 (diff)
downloadd2-eed3f81529d7f0109b554031c9121cb5be1a2137.tar.bz2
d2-eed3f81529d7f0109b554031c9121cb5be1a2137.tar.xz
d2-eed3f81529d7f0109b554031c9121cb5be1a2137.zip
added new tables for room and floor
-rw-r--r--lib/d2/app/model/static.py5
-rw-r--r--lib/d2/db.py68
2 files changed, 71 insertions, 2 deletions
diff --git a/lib/d2/app/model/static.py b/lib/d2/app/model/static.py
index 9ba90d4..93c4af2 100644
--- a/lib/d2/app/model/static.py
+++ b/lib/d2/app/model/static.py
@@ -2,6 +2,7 @@ import hashlib
2from d2.db import DetailType 2from d2.db import DetailType
3from d2.db import OccupantType 3from d2.db import OccupantType
4from d2.db import Occupant 4from d2.db import Occupant
5from d2.config import Config
5from collections import namedtuple 6from collections import namedtuple
6 7
7class StaticData(object): 8class StaticData(object):
@@ -15,7 +16,9 @@ class StaticData(object):
15 self._occupant = occupant 16 self._occupant = occupant
16 17
17 @classmethod 18 @classmethod
18 def load(cls, db, detail_type=None, occupant_type=None, occupant=None): 19 def load(cls, db=None, detail_type=None, occupant_type=None,
20 occupant=None):
21 db = db or Config.load().db
19 detail_type = detail_type or DetailType 22 detail_type = detail_type or DetailType
20 occupant_type = occupant_type or OccupantType 23 occupant_type = occupant_type or OccupantType
21 occupant = occupant or Occupant 24 occupant = occupant or Occupant
diff --git a/lib/d2/db.py b/lib/d2/db.py
index 73262d3..55d0d47 100644
--- a/lib/d2/db.py
+++ b/lib/d2/db.py
@@ -76,6 +76,72 @@ class Location(Base):
76 obj.id = data['id'] 76 obj.id = data['id']
77 return obj 77 return obj
78 78
79class Floor(Base):
80 """Database table object for storing different floor names
81 """
82 __tablename__ = PREFIX + "floor"
83 id = Column(Integer, primary_key=True)
84 location_id = Column(Integer, ForeignKey(PREFIX + 'location.id'),
85 index=True)
86 name = Column(Unicode)
87
88 def __init__(self, name):
89 self.name = name
90
91 def __repr__(self):
92 out = "<Floor("\
93 "name={obj.name!r}, "\
94 ")>"
95 return out.format(obj=self)
96
97 def as_dict(self):
98 out = OrderedDict()
99 out['id'] = self.id
100 out['name'] = self.name
101 out['location_id']= self.location_id
102 return out
103
104 @classmethod
105 def from_dict(cls, data):
106 obj = cls(data['name'])
107 obj.location_id = data['location_id']
108 if 'id' in data:
109 obj.id = data['id']
110 return obj
111
112class Room(Base):
113 """Database table object for storing different room names
114 """
115 __tablename__ = PREFIX + "room"
116 id = Column(Integer, primary_key=True)
117 floor_id = Column(Integer, ForeignKey(PREFIX + 'floor.id'),
118 index=True)
119 name = Column(Unicode)
120
121 def __init__(self, name):
122 self.name = name
123
124 def __repr__(self):
125 out = "<Room("\
126 "name={obj.name!r}, "\
127 ")>"
128 return out.format(obj=self)
129
130 def as_dict(self):
131 out = OrderedDict()
132 out['id'] = self.id
133 out['name'] = self.namem
134 out['floor_id']= self.location_id
135 return out
136
137 @classmethod
138 def from_dict(cls, data):
139 obj = cls(data['name'])
140 obj.floor_id = data['floor_id']
141 if 'id' in data:
142 obj.id = data['id']
143 return obj
144
79 145
80class Map(Base): 146class Map(Base):
81 """Database table object for storing the different maps used 147 """Database table object for storing the different maps used
@@ -140,7 +206,7 @@ class MapLayer(Base):
140 id = Column(Integer, primary_key=True) 206 id = Column(Integer, primary_key=True)
141 map_id = Column(Integer, ForeignKey(PREFIX + 'map.id'), 207 map_id = Column(Integer, ForeignKey(PREFIX + 'map.id'),
142 index=True) 208 index=True)
143 detail_type_id = Column(Integer, ForeignKey(PREFIX + 'detail_type.id'), 209 detail_type_id = Column(Integer, ForeignKey(PREFIX + 'detail_type.id'),
144 index=True) 210 index=True)
145 filename_svg = Column(Unicode) 211 filename_svg = Column(Unicode)
146 width = Column(Integer) 212 width = Column(Integer)