diff options
author | Six <unknown> | 2011-05-11 22:34:21 -0400 |
---|---|---|
committer | Six <unknown> | 2011-05-11 22:34:21 -0400 |
commit | af5fbd98eb4246e74207b055a9a1f6e55e3a975c (patch) | |
tree | dc664be7ed4dbbc1d7e537eb90a71769e7360b3b | |
parent | 05bff8a5f3de37103755f6a20caaa8c1a6202d88 (diff) | |
download | d2-af5fbd98eb4246e74207b055a9a1f6e55e3a975c.tar.bz2 d2-af5fbd98eb4246e74207b055a9a1f6e55e3a975c.tar.xz d2-af5fbd98eb4246e74207b055a9a1f6e55e3a975c.zip |
multiple rows for network jacks and misc changes
-rw-r--r-- | INSTALL | 12 | ||||
-rw-r--r-- | lib/d2/app/adapters/detail.py | 52 | ||||
-rw-r--r-- | lib/d2/bin/d2_db_setup.py | 2 |
3 files changed, 60 insertions, 6 deletions
@@ -1,3 +1,14 @@ | |||
1 | D2 Needs the following dependancies installed: | ||
2 | |||
3 | UBUNTU: | ||
4 | apt-get install libldap2-dev libsasl2-dev libssl-dev libxml2 libxslt1-dev \ | ||
5 | libcurl4-gnutls-dev | ||
6 | |||
7 | |||
8 | |||
9 | |||
10 | THE FOLLOWING IS OPTIONAL: | ||
11 | |||
1 | D2 uses mapnick; which needs a ton of libs installed locally to work | 12 | D2 uses mapnick; which needs a ton of libs installed locally to work |
2 | 13 | ||
3 | UBUNTU: | 14 | UBUNTU: |
@@ -16,3 +27,4 @@ FEDORA: | |||
16 | 27 | ||
17 | 28 | ||
18 | MAC: | 29 | MAC: |
30 | |||
diff --git a/lib/d2/app/adapters/detail.py b/lib/d2/app/adapters/detail.py index 33cd9a1..7231faa 100644 --- a/lib/d2/app/adapters/detail.py +++ b/lib/d2/app/adapters/detail.py | |||
@@ -21,6 +21,7 @@ class DetailAdapter(BaseAdapter): | |||
21 | self._search_schema_ = None | 21 | self._search_schema_ = None |
22 | self._search_index_ = None | 22 | self._search_index_ = None |
23 | self._label_detail_type_ids_ = None | 23 | self._label_detail_type_ids_ = None |
24 | self._multiple_value_labels_ = None | ||
24 | self._make = namedtuple('detail', 'name data') | 25 | self._make = namedtuple('detail', 'name data') |
25 | 26 | ||
26 | @classmethod | 27 | @classmethod |
@@ -40,6 +41,14 @@ class DetailAdapter(BaseAdapter): | |||
40 | ] | 41 | ] |
41 | return self._label_detail_type_ids_ | 42 | return self._label_detail_type_ids_ |
42 | 43 | ||
44 | @property | ||
45 | def _multiple_value_labels(self): | ||
46 | if not self._multiple_value_labels_: | ||
47 | self._multiple_value_labels_ = [ | ||
48 | self._static.detail_type.network_jack, | ||
49 | ] | ||
50 | return self._multiple_value_labels_ | ||
51 | |||
43 | def fetch_all_occupant_details(self, occupant_id, date_start=None): | 52 | def fetch_all_occupant_details(self, occupant_id, date_start=None): |
44 | """Fetch all details for the given occupant_id | 53 | """Fetch all details for the given occupant_id |
45 | """ | 54 | """ |
@@ -81,8 +90,7 @@ class DetailAdapter(BaseAdapter): | |||
81 | else: | 90 | else: |
82 | return obj | 91 | return obj |
83 | 92 | ||
84 | def _fetch_detail(self, plot_id, occupant_id, detail_type_id, | 93 | def _fetch_detail(self, plot_id, occupant_id, detail_type_id, date_start): |
85 | date_start): | ||
86 | date_start = self.build_date(date_start) | 94 | date_start = self.build_date(date_start) |
87 | return self._db.session.query(self._detail | 95 | return self._db.session.query(self._detail |
88 | ).filter(self._detail.plot_id==plot_id | 96 | ).filter(self._detail.plot_id==plot_id |
@@ -125,15 +133,40 @@ class DetailAdapter(BaseAdapter): | |||
125 | 133 | ||
126 | def _insert_detail(self, plot_id, occupant_id, detail_type_id, data, | 134 | def _insert_detail(self, plot_id, occupant_id, detail_type_id, data, |
127 | date_start=None, date_end=None): | 135 | date_start=None, date_end=None): |
136 | |||
137 | date_start= self.build_date(date_start) | ||
138 | data = dict( | ||
139 | plot_id=plot_id, | ||
140 | occupant_id=occupant_id, | ||
141 | detail_type_id=detail_type_id, | ||
142 | data=data, | ||
143 | date_start=date_start, | ||
144 | date_end=date_end, | ||
145 | date_created=datetime.now(), | ||
146 | date_override=None | ||
147 | ) | ||
148 | obj = self._detail.from_dict(data) | ||
149 | self._db.session.add(obj) | ||
150 | self._db.session.commit() | ||
151 | return obj | ||
152 | |||
153 | def _change_detail(self, plot_id, occupant_id, detail_type_id, data, | ||
154 | date_start=None, date_end=None): | ||
155 | """ | ||
156 | TODO: FIXME | ||
157 | """ | ||
128 | if plot_id: | 158 | if plot_id: |
129 | previous_record = self.fetch_plot_detail(plot_id, detail_type_id, | 159 | previous_record = self.fetch_plot_detail(plot_id, detail_type_id, |
130 | date_start) | 160 | date_start) |
131 | else: | 161 | else: |
132 | previous_record = self.fetch_occupant_detail(occupant_id, | 162 | previous_record = self.fetch_occupant_detail(occupant_id, |
133 | detail_type_id, date_start) | 163 | detail_type_id, date_start) |
164 | |||
134 | if previous_record: | 165 | if previous_record: |
135 | self._set_override(previous_record) | 166 | self._set_override(previous_record) |
136 | self._set_end(previous_record, date_end) | 167 | self._set_end(previous_record, date_end) |
168 | else: | ||
169 | raise Exception("Missing previous recored. Unable to change.") | ||
137 | 170 | ||
138 | date_start= self.build_date(date_start) | 171 | date_start= self.build_date(date_start) |
139 | data = dict( | 172 | data = dict( |
@@ -227,12 +260,21 @@ class DetailAdapter(BaseAdapter): | |||
227 | and detail.data): | 260 | and detail.data): |
228 | name = detail.detail_type.name | 261 | name = detail.detail_type.name |
229 | key = name.lower().strip().replace(u' ', u'_') | 262 | key = name.lower().strip().replace(u' ', u'_') |
230 | keys.append(key) | 263 | if detail.detail_type_id in self._multiple_value_labels: |
231 | hold[key] = self._make(name, detail.data) | 264 | if key in hold: |
265 | data = hold[key].data | ||
266 | data.append(detail.data) | ||
267 | hold[key] = hold[key]._replace(data=data) | ||
268 | else: | ||
269 | keys.append(key) | ||
270 | data = [detail.data] | ||
271 | hold[key] = self._make(name, data) | ||
272 | else: | ||
273 | keys.append(key) | ||
274 | hold[key] = self._make(name, detail.data) | ||
232 | keys.sort() | 275 | keys.sort() |
233 | keys = [u'label', u'id', u'id_type'] + keys | 276 | keys = [u'label', u'id', u'id_type'] + keys |
234 | for key in keys: | 277 | for key in keys: |
235 | vals.append(hold[key]) | 278 | vals.append(hold[key]) |
236 | make = namedtuple('details', keys) | 279 | make = namedtuple('details', keys) |
237 | return make(*vals) | 280 | return make(*vals) |
238 | |||
diff --git a/lib/d2/bin/d2_db_setup.py b/lib/d2/bin/d2_db_setup.py index 139f662..42963cc 100644 --- a/lib/d2/bin/d2_db_setup.py +++ b/lib/d2/bin/d2_db_setup.py | |||
@@ -226,7 +226,7 @@ class PopulateEmptyOccupant(object): | |||
226 | if not self._get(occupant_type_id_for_empty): | 226 | if not self._get(occupant_type_id_for_empty): |
227 | data = dict(occupant_type_id = occupant_type_id_for_empty, | 227 | data = dict(occupant_type_id = occupant_type_id_for_empty, |
228 | key = self.KEY, | 228 | key = self.KEY, |
229 | active = 1) | 229 | active = True) |
230 | obj = Occupant.from_dict(data) | 230 | obj = Occupant.from_dict(data) |
231 | self._db.session.add(obj) | 231 | self._db.session.add(obj) |
232 | self._db.session.commit() | 232 | self._db.session.commit() |