diff options
Diffstat (limited to 'lib/d2/app/adapters/forge.py')
-rw-r--r-- | lib/d2/app/adapters/forge.py | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/lib/d2/app/adapters/forge.py b/lib/d2/app/adapters/forge.py index 3590d23..792725f 100644 --- a/lib/d2/app/adapters/forge.py +++ b/lib/d2/app/adapters/forge.py | |||
@@ -41,12 +41,12 @@ class ForgeAdapter(BaseAdapter): | |||
41 | self._db.session.add(obj_empty) | 41 | self._db.session.add(obj_empty) |
42 | self._db.session.commit() | 42 | self._db.session.commit() |
43 | 43 | ||
44 | def add_occupant_to_plot(self, plot_id, occupant_id, | 44 | def add_occupant_to_plot(self, plot_id, occupant_id, |
45 | date_start=None, date_end=None): | 45 | date_start=None, date_end=None): |
46 | """ add an occupant to a plot | 46 | """ add an occupant to a plot |
47 | """ | 47 | """ |
48 | if self._is_empty_plot(plot_id, date_start): | 48 | if self._is_empty_plot(plot_id, date_start): |
49 | empty_record = self._fetch_forge_by_plot_and_occupant_id(plot_id, | 49 | empty_record = self._fetch_forge_by_plot_and_occupant_id(plot_id, |
50 | self._static.occupant.empty, date_start) | 50 | self._static.occupant.empty, date_start) |
51 | self._set_override(empty_record) | 51 | self._set_override(empty_record) |
52 | self._set_end(empty_record, date_end) | 52 | self._set_end(empty_record, date_end) |
@@ -64,30 +64,42 @@ class ForgeAdapter(BaseAdapter): | |||
64 | self._db.session.add(obj) | 64 | self._db.session.add(obj) |
65 | self._db.session.commit() | 65 | self._db.session.commit() |
66 | return obj | 66 | return obj |
67 | 67 | ||
68 | def remove_occupant_from_plot(self, plot_id, occupant_id, | 68 | def remove_occupant_from_plot(self, plot_id, occupant_id, |
69 | date_start=None, date_end=None): | 69 | date_start=None, date_end=None): |
70 | """ remove an occupant from a plot | 70 | """ remove an occupant from a plot |
71 | """ | 71 | """ |
72 | forge_record = self._fetch_forge_by_plot_and_occupant_id(plot_id, | 72 | forge_record = self._fetch_forge_by_plot_and_occupant_id(plot_id, |
73 | occupant_id, date_start) | 73 | occupant_id, date_start) |
74 | if forge_record: | 74 | if forge_record: |
75 | self._set_override(forge_record) | 75 | self._set_override(forge_record) |
76 | self._set_end(forge_record, date_end) | 76 | self._set_end(forge_record, date_end) |
77 | 77 | ||
78 | # if no more occupants in plot_id, mark it as empty | 78 | # if no more occupants in plot_id, mark it as empty |
79 | records = self._fetch_forge_by_plot_id(plot_id, date_start) | 79 | records = self._fetch_forge_by_plot_id(plot_id, date_start) |
80 | if not records: | 80 | if not records: |
81 | self.add_empty_user(plot_id) | 81 | self.add_empty_user(plot_id) |
82 | 82 | ||
83 | def get_forge_by_occupant_id(self, occupant_id, date_start=None): | 83 | def get_forge_by_occupant_id(self, occupant_id, date_start=None): |
84 | date_start = self.build_date(date_start) | 84 | if occupant_id: |
85 | return self._fetch_forge_by_occupant_id(occupant_id, date_start) | 85 | date_start = self.build_date(date_start) |
86 | 86 | return self._fetch_forge_by_occupant_id(occupant_id, date_start) | |
87 | return [] | ||
88 | |||
87 | def get_forge_by_plot_id(self, plot_id, date_start=None): | 89 | def get_forge_by_plot_id(self, plot_id, date_start=None): |
88 | date_start = self.build_date(date_start) | 90 | date_start = self.build_date(date_start) |
89 | return self._fetch_forge_by_plot_id(plot_id, date_start) | 91 | return self._fetch_forge_by_plot_id(plot_id, date_start) |
90 | 92 | ||
93 | def get_occupant_other_plots(self, plot_id=None, occupant_id=None, | ||
94 | date_start=None): | ||
95 | out = [] | ||
96 | date_start = self.build_date(date_start) | ||
97 | results = self._fetch_forge_by_occupant_id(occupant_id, date_start) | ||
98 | for row in results: | ||
99 | if not row.plot_id == plot_id: | ||
100 | out.append(row) | ||
101 | return out | ||
102 | |||
91 | def get_all(self, date_start=None): | 103 | def get_all(self, date_start=None): |
92 | date_start = self.build_date(date_start) | 104 | date_start = self.build_date(date_start) |
93 | records = self._fetch_all(date_start) | 105 | records = self._fetch_all(date_start) |
@@ -114,8 +126,8 @@ class ForgeAdapter(BaseAdapter): | |||
114 | self._db.session.commit() | 126 | self._db.session.commit() |
115 | 127 | ||
116 | def _is_empty_plot(self, plot_id, date_start): | 128 | def _is_empty_plot(self, plot_id, date_start): |
117 | """ return True if and only if one record exists for the given plot_id | 129 | """ return True if and only if one record exists for the given plot_id |
118 | and the occupant_id in that record is empty user id | 130 | and the occupant_id in that record is empty user id |
119 | """ | 131 | """ |
120 | is_empty = True | 132 | is_empty = True |
121 | records = self._fetch_forge_by_plot_id(plot_id, date_start) | 133 | records = self._fetch_forge_by_plot_id(plot_id, date_start) |
@@ -131,7 +143,7 @@ class ForgeAdapter(BaseAdapter): | |||
131 | 143 | ||
132 | return is_empty | 144 | return is_empty |
133 | 145 | ||
134 | def _fetch_forge_by_plot_and_occupant_id(self, plot_id, | 146 | def _fetch_forge_by_plot_and_occupant_id(self, plot_id, |
135 | occupant_id, date_start): | 147 | occupant_id, date_start): |
136 | date_start = self.build_date(date_start) | 148 | date_start = self.build_date(date_start) |
137 | return self._db.session.query(self._forge | 149 | return self._db.session.query(self._forge |