aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSix <unknown>2011-05-24 21:59:35 -0400
committerSix <unknown>2011-05-24 21:59:35 -0400
commitb0a67d8900e5ce40d491af2efe755881ae3d51f3 (patch)
tree75ccbebf944940cb8fbb713d3cd9c1f7afb86c34
parenta69dc9f74921e6facdf7d6c322a38f8b2da43fe3 (diff)
downloadd2-b0a67d8900e5ce40d491af2efe755881ae3d51f3.tar.bz2
d2-b0a67d8900e5ce40d491af2efe755881ae3d51f3.tar.xz
d2-b0a67d8900e5ce40d491af2efe755881ae3d51f3.zip
bug fixes
-rw-r--r--lib/d2/app/adapters/detail.py11
-rw-r--r--lib/d2/app/adapters/forge.py38
-rw-r--r--lib/d2/app/adapters/plot.py9
-rw-r--r--lib/d2/app/controllers/index.py28
-rw-r--r--templates/index.html10
5 files changed, 56 insertions, 40 deletions
diff --git a/lib/d2/app/adapters/detail.py b/lib/d2/app/adapters/detail.py
index 738230b..ba2906d 100644
--- a/lib/d2/app/adapters/detail.py
+++ b/lib/d2/app/adapters/detail.py
@@ -351,10 +351,11 @@ class DetailAdapter(BaseAdapter):
351 def details(self, plot_id=None, occupant_id=None): 351 def details(self, plot_id=None, occupant_id=None):
352 """ Returns a named tuple with complete details. 352 """ Returns a named tuple with complete details.
353 """ 353 """
354 plot_id, occupant_id = self._validate(plot_id, occupant_id) 354 (plot_id_, occupant_id_) = self._validate(plot_id, occupant_id)
355 plot = self.details_to_dict(self.fetch_all_plot_details(plot_id)) 355
356 plot = self.details_to_dict(self.fetch_all_plot_details(plot_id_))
356 occupant = self.details_to_dict(self.fetch_all_occupant_details( 357 occupant = self.details_to_dict(self.fetch_all_occupant_details(
357 occupant_id)) 358 occupant_id_))
358 359
359 if plot and occupant: 360 if plot and occupant:
360 occupant[u'plot_id'] = plot[u'plot_id'] 361 occupant[u'plot_id'] = plot[u'plot_id']
@@ -368,6 +369,7 @@ class DetailAdapter(BaseAdapter):
368 369
369 for key, val in plot.items(): 370 for key, val in plot.items():
370 occupant[key] = val 371 occupant[key] = val
372
371 return self._details_dict_to_tuple(occupant) 373 return self._details_dict_to_tuple(occupant)
372 374
373 if plot: 375 if plot:
@@ -376,6 +378,9 @@ class DetailAdapter(BaseAdapter):
376 if occupant: 378 if occupant:
377 return self._details_dict_to_tuple(occupant) 379 return self._details_dict_to_tuple(occupant)
378 380
381 make_ = namedtuple("Detail", "label plot_id occupant_id")
382 return make_(None, None, None)
383
379 def _validate(self, plot_id, occupant_id, start_date=None): 384 def _validate(self, plot_id, occupant_id, start_date=None):
380 """Validates that the given plot_id and occupant_id 385 """Validates that the given plot_id and occupant_id
381 are valid. Also checks forge 386 are valid. Also checks forge
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
diff --git a/lib/d2/app/adapters/plot.py b/lib/d2/app/adapters/plot.py
index 451f215..ec6075d 100644
--- a/lib/d2/app/adapters/plot.py
+++ b/lib/d2/app/adapters/plot.py
@@ -1,7 +1,7 @@
1from d2.app.model.static import StaticData 1from d2.app.model.static import StaticData
2from d2.app.adapters import BaseAdapter 2from d2.app.adapters import BaseAdapter
3from d2.config import Config 3from d2.config import Config
4from d2.db import Plot 4from d2.db import Plot
5 5
6class PlotAdapter(BaseAdapter): 6class PlotAdapter(BaseAdapter):
7 7
@@ -9,7 +9,7 @@ class PlotAdapter(BaseAdapter):
9 self._db = db 9 self._db = db
10 self._log = log 10 self._log = log
11 self._static = static 11 self._static = static
12 self._plot = plot 12 self._plot = plot
13 13
14 @classmethod 14 @classmethod
15 def load(cls, config=None, static=None): 15 def load(cls, config=None, static=None):
@@ -20,3 +20,8 @@ class PlotAdapter(BaseAdapter):
20 def get_all(self, plot_ids): 20 def get_all(self, plot_ids):
21 return self._db.session.query(self._plot).filter( 21 return self._db.session.query(self._plot).filter(
22 self._plot.id.in_(plot_ids)).all() 22 self._plot.id.in_(plot_ids)).all()
23
24
25 def get_all_from_forges(self, forges):
26 hold = [forge.plot_id for forge in forges]
27 return self.get_all(hold)
diff --git a/lib/d2/app/controllers/index.py b/lib/d2/app/controllers/index.py
index 1c6ae66..f8756c2 100644
--- a/lib/d2/app/controllers/index.py
+++ b/lib/d2/app/controllers/index.py
@@ -1,4 +1,4 @@
1from d2.app.controllers import BaseController 1from d2.app.controllers import BaseController
2from d2.app.adapters.search import SearchAdapter 2from d2.app.adapters.search import SearchAdapter
3from d2.app.adapters.forge import ForgeAdapter 3from d2.app.adapters.forge import ForgeAdapter
4from d2.app.adapters.detail import DetailAdapter 4from d2.app.adapters.detail import DetailAdapter
@@ -31,24 +31,19 @@ class IndexController(BaseController):
31 return self._plot_ 31 return self._plot_
32 32
33 def _show_map(self, occupant_id, plot_id): 33 def _show_map(self, occupant_id, plot_id):
34 if plot_id: 34 details = self._detail.details(plot_id, occupant_id)
35 forges = self._forge.get_forge_by_plot_id(plot_id) 35 forges = self._forge.get_forge_by_occupant_id(details.occupant_id)
36 details = self._detail.details(plot_id, occupant_id) 36 plots = self._plot.get_all_from_forges(forges)
37 plots = self._plot.get_all([plot_id]) 37 center_plot = None
38 else: 38 for plot in plots:
39 forges = self._forge.get_forge_by_occupant_id(occupant_id) 39 if plot.id == details.plot_id:
40 details = self._detail.details(plot_id, occupant_id) 40 center_plot=plot
41 plots = []
42 if len(forges) > 0:
43 plot_ids = [forge.plot_id for forge in forges]
44 plots = self._plot.get_all(plot_ids)
45 41
46 self.render('index.html', 42 self.render('index.html',
47 mode="map", 43 mode="map",
48 details=details, 44 details=details,
49 plots=plots, 45 plots=plots,
50 forges=forges) 46 center_plot=center_plot)
51
52 47
53 def get(self, type_1=None, id_1=None, type_2=None, id_2=None): 48 def get(self, type_1=None, id_1=None, type_2=None, id_2=None):
54 if type_1 and id_1: 49 if type_1 and id_1:
@@ -66,7 +61,6 @@ class IndexController(BaseController):
66 self._show_map(occupant_id, plot_id) 61 self._show_map(occupant_id, plot_id)
67 else: 62 else:
68 self.render('index.html', mode="get") 63 self.render('index.html', mode="get")
69
70 64
71 def post(self): 65 def post(self):
72 name = self.get_argument('name') 66 name = self.get_argument('name')
diff --git a/templates/index.html b/templates/index.html
index 9a504a5..5cfefb2 100644
--- a/templates/index.html
+++ b/templates/index.html
@@ -24,8 +24,8 @@
24 var map_width = {{plots[0].map.width}}; 24 var map_width = {{plots[0].map.width}};
25 var map_height = {{plots[0].map.height}}; 25 var map_height = {{plots[0].map.height}};
26 //These are the coordinates from bottom left 26 //These are the coordinates from bottom left
27 var center_point_x = {{plots[0].x}}; 27 var center_point_x = {{center_plot.x}};
28 var center_point_y = {{plots[0].y}}; 28 var center_point_y = {{center_plot.y}};
29 29
30 //Initialise the 'map' object 30 //Initialise the 'map' object
31 function init() 31 function init()
@@ -77,8 +77,8 @@
77 77
78 function emphasize() 78 function emphasize()
79 { 79 {
80 {% if (len(forges) > 0) %} 80 {% if details %}
81 var e = document.getElementById("{{forges[0].occupant_id}}_{{forges[0].plot_id}}"); 81 var e = document.getElementById("{{details.occupant_id}}_{{details.plot_id}}");
82 if (e) 82 if (e)
83 { 83 {
84 e.setAttributeNS(null, "fill", "red"); 84 e.setAttributeNS(null, "fill", "red");
@@ -147,7 +147,7 @@
147 </div> 147 </div>
148 {% else %} 148 {% else %}
149 <div id="result"> 149 <div id="result">
150 Sorry, no match found. Please try to broaden your search by entering less in t he search field above. 150 Sorry, no match found. Please try to broaden your search by entering more in the search field above.
151 </div> 151 </div>
152 {% end %} 152 {% end %}
153{% else %} 153{% else %}