1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 """
24 Place object for GRAMPS.
25 """
26
27
28
29
30
31
32 from types import InstanceType
33
34
35
36
37
38
39 from gen.lib.primaryobj import PrimaryObject
40 from gen.lib.srcbase import SourceBase
41 from gen.lib.notebase import NoteBase
42 from gen.lib.mediabase import MediaBase
43 from gen.lib.urlbase import UrlBase
44 from gen.lib.location import Location
45 from gen.lib.markertype import MarkerType
46
47 _EMPTY_LOC = Location().serialize()
48
49
50
51
52
53
54 -class Place(SourceBase, NoteBase, MediaBase, UrlBase, PrimaryObject):
55 """
56 Contains information related to a place, including multiple address
57 information (since place names can change with time), longitude, latitude,
58 a collection of images and URLs, a note and a source.
59 """
60
62 """
63 Create a new Place object, copying from the source if present.
64
65 @param source: A Place object used to initialize the new Place
66 @type source: Place
67 """
68 PrimaryObject.__init__(self, source)
69 SourceBase.__init__(self, source)
70 NoteBase.__init__(self, source)
71 MediaBase.__init__(self, source)
72 UrlBase.__init__(self, source)
73 if source:
74 self.long = source.long
75 self.lat = source.lat
76 self.title = source.title
77 self.main_loc = Location(source.main_loc)
78 self.alt_loc = [Location(loc) for loc in source.alt_loc]
79 else:
80 self.long = ""
81 self.lat = ""
82 self.title = ""
83 self.main_loc = None
84 self.alt_loc = []
85
87 """
88 Convert the data held in the Place to a Python tuple that
89 represents all the data elements.
90
91 This method is used to convert the object into a form that can easily
92 be saved to a database.
93
94 These elements may be primative Python types (string, integers),
95 complex Python types (lists or tuples, or Python objects. If the
96 target database cannot handle complex types (such as objectes or
97 lists), the database is responsible for converting the data into
98 a form that it can use.
99
100 @returns: Returns a python tuple containing the data that should
101 be considered persistent.
102 @rtype: tuple
103 """
104
105 if self.main_loc == None or self.main_loc.serialize() == _EMPTY_LOC:
106 main_loc = None
107 else:
108 main_loc = self.main_loc.serialize()
109
110 return (self.handle, self.gramps_id, self.title, self.long, self.lat,
111 main_loc, [al.serialize() for al in self.alt_loc],
112 UrlBase.serialize(self),
113 MediaBase.serialize(self),
114 SourceBase.serialize(self),
115 NoteBase.serialize(self),
116 self.change, self.marker.serialize() ,self.private)
117
119 """
120 Convert the data held in a tuple created by the serialize method
121 back into the data in a Place object.
122
123 @param data: tuple containing the persistent data associated the
124 Person object
125 @type data: tuple
126 """
127 (self.handle, self.gramps_id, self.title, self.long, self.lat,
128 main_loc, alt_loc, urls, media_list, source_list, note_list,
129 self.change, marker, self.private) = data
130
131 if main_loc == None:
132 self.main_loc = None
133 else:
134 self.main_loc = InstanceType(Location).unserialize(main_loc)
135 self.alt_loc = [InstanceType(Location).unserialize(al)
136 for al in alt_loc]
137 self.marker = InstanceType(MarkerType)
138 self.marker.unserialize(marker)
139 UrlBase.unserialize(self, urls)
140 MediaBase.unserialize(self, media_list)
141 SourceBase.unserialize(self, source_list)
142 NoteBase.unserialize(self, note_list)
143
145 """
146 Return the list of all textual attributes of the object.
147
148 @return: Returns the list of all textual attributes of the object.
149 @rtype: list
150 """
151 return [self.long, self.lat, self.title, self.gramps_id]
152
154 """
155 Return the list of child objects that may carry textual data.
156
157 @return: Returns the list of child objects that may carry textual data.
158 @rtype: list
159 """
160
161 ret = self.media_list + self.source_list + self.alt_loc + self.urls
162 if self.main_loc:
163 ret.append(self.main_loc)
164 return ret
165
167 """
168 Return the list of child secondary objects that may refer sources.
169
170 @return: List of child secondary child objects that may refer sources.
171 @rtype: list
172 """
173 return self.media_list
174
176 """
177 Return the list of child secondary objects that may refer notes.
178
179 @return: Returns the list of child secondary child objects that may
180 refer notes.
181 @rtype: list
182 """
183 return self.media_list + self.source_list
184
186 """
187 Return the list of child objects which may, directly or through
188 their children, reference primary objects.
189
190 @return: Returns the list of objects refereincing primary objects.
191 @rtype: list
192 """
193 return self.media_list + self.source_list
194
196 """
197 Return the list of (classname, handle) tuples for all directly
198 referenced primary objects.
199
200 @return: List of (classname, handle) tuples for referenced objects.
201 @rtype: list
202 """
203 return self.get_referenced_note_handles()
204
206 """
207 Set the descriptive title of the Place object.
208
209 @param title: descriptive title to assign to the Place
210 @type title: str
211 """
212 self.title = title
213
215 """
216 Return the descriptive title of the Place object.
217
218 @returns: Returns the descriptive title of the Place
219 @rtype: str
220 """
221 return self.title
222
224 """
225 Set the longitude of the Place object.
226
227 @param longitude: longitude to assign to the Place
228 @type longitude: str
229 """
230 self.long = longitude
231
233 """
234 Return the longitude of the Place object.
235
236 @returns: Returns the longitude of the Place
237 @rtype: str
238 """
239 return self.long
240
242 """
243 Set the latitude of the Place object.
244
245 @param latitude: latitude to assign to the Place
246 @type latitude: str
247 """
248 self.lat = latitude
249
251 """
252 Return the latitude of the Place object.
253
254 @returns: Returns the latitude of the Place
255 @rtype: str
256 """
257 return self.lat
258
260 """
261 Return the L{Location} object representing the primary information for
262 the Place instance.
263
264 If a L{Location} hasn't been assigned yet, an empty one is created.
265
266 @returns: Returns the L{Location} instance representing the primary
267 location information about the Place.
268 @rtype: L{Location}
269 """
270 if not self.main_loc:
271 self.main_loc = Location()
272 return self.main_loc
273
274 - def set_main_location(self, location):
275 """
276 Assign the main location information about the Place to the L{Location}
277 object passed.
278
279 @param location: L{Location} instance to assign to as the main
280 information for the Place.
281 @type location: L{Location}
282 """
283 self.main_loc = location
284
286 """
287 Return a list of alternate L{Location} objects the present alternate
288 information about the current Place.
289
290 A Place can have more than one L{Location}, since names and
291 jurisdictions can change over time for the same place.
292
293 @returns: Returns the alternate L{Location}s for the Place
294 @rtype: list of L{Location} objects
295 """
296 return self.alt_loc
297
299 """
300 Replace the current alternate L{Location} object list with the new one.
301
302 @param location_list: The list of L{Location} objects to assign to the
303 Place's internal list.
304 @type location_list: list of L{Location} objects
305 """
306 self.alt_loc = location_list
307
309 """
310 Add a L{Location} object to the alternate location list.
311
312 @param location: L{Location} instance to add
313 @type location: L{Location}
314 """
315 if location not in self.alt_loc:
316 self.alt_loc.append(location)
317
319 """
320 Get the display information associated with the object.
321
322 This includes the information that is used for display and for sorting.
323 Returns a list consisting of 13 strings. These are:
324
325 Place Title, Place ID, Main Location Parish, Main Location County,
326 Main Location City, Main Location State/Province,
327 Main Location Country, upper case Place Title, upper case Parish,
328 upper case city, upper case county, upper case state,
329 upper case country.
330 """
331
332 if self.main_loc:
333 return [self.title, self.gramps_id, self.main_loc.parish,
334 self.main_loc.city, self.main_loc.county,
335 self.main_loc.state, self.main_loc.country,
336 self.title.upper(), self.main_loc.parish.upper(),
337 self.main_loc.city.upper(), self.main_loc.county.upper(),
338 self.main_loc.state.upper(), self.main_loc.country.upper()]
339 else:
340 return [self.title, self.gramps_id, u'', u'', u'', u'', u'',
341 self.title.upper(), u'', u'', u'', u'', u'']
342