1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 """
24 Basic Primary Object class for GRAMPS.
25 """
26
27
28
29
30
31
32 import time
33 import locale
34
35
36
37
38
39
40 from gen.lib.baseobj import BaseObject
41 from gen.lib.privacybase import PrivacyBase
42 from gen.lib.markertype import MarkerType
43 from gen.lib.srcbase import SourceBase
44 from gen.lib.mediabase import MediaBase
45
46
47
48
49
50
51 try:
52 CODESET = locale.nl_langinfo(locale.CODESET)
53 except:
54 CODESET = locale.getpreferredencoding()
55
56
57
58
59
60
62 """
63 The BasicPrimaryObject is the base class for Note objects.
64
65 It is also the base class for the PrimaryObject class.
66
67 The PrimaryObject is the base class for all other primary objects in the
68 database. Primary objects are the core objects in the database.
69 Each object has a database handle and a GRAMPS ID value. The database
70 handle is used as the record number for the database, and the GRAMPS
71 ID is the user visible version.
72 """
73
75 """
76 Initialize a PrimaryObject.
77
78 If source is None, both the ID and handle are assigned as empty
79 strings. If source is not None, then object is initialized from values
80 of the source object.
81
82 @param source: Object used to initialize the new object
83 @type source: PrimaryObject
84 """
85 PrivacyBase.__init__(self, source)
86 if source:
87 self.gramps_id = source.gramps_id
88 self.handle = source.handle
89 self.change = source.change
90 self.marker = source.marker
91 else:
92 self.gramps_id = None
93 self.handle = None
94 self.change = 0
95 self.marker = MarkerType()
96
98 """
99 Return the time that the data was last changed.
100
101 The value in the format returned by the time.time() command.
102
103 @returns: Time that the data was last changed. The value in the format
104 returned by the time.time() command.
105 @rtype: int
106 """
107 return self.change
108
110 """
111 Return the string representation of the last change time.
112
113 @returns: string representation of the last change time.
114 @rtype: str
115
116 """
117 if self.change:
118 return unicode(time.strftime('%x %X', time.localtime(self.change)),
119 CODESET)
120 else:
121 return u''
122
124 """
125 Set the database handle for the primary object.
126
127 @param handle: object database handle
128 @type handle: str
129 """
130 self.handle = handle
131
133 """
134 Return the database handle for the primary object.
135
136 @returns: database handle associated with the object
137 @rtype: str
138 """
139 return self.handle
140
142 """
143 Set the GRAMPS ID for the primary object.
144
145 @param gramps_id: GRAMPS ID
146 @type gramps_id: str
147 """
148 self.gramps_id = gramps_id
149
151 """
152 Return the GRAMPS ID for the primary object.
153
154 @returns: GRAMPS ID associated with the object
155 @rtype: str
156 """
157 return self.gramps_id
158
160 """
161 Return True if the object has reference to a given handle of given
162 primary object type.
163
164 @param classname: The name of the primary object class.
165 @type classname: str
166 @param handle: The handle to be checked.
167 @type handle: str
168 @return: Returns whether the object has reference to this handle of
169 this object type.
170 @rtype: bool
171 """
172 return False
173
175 """
176 Remove all references in this object to object handles in the list.
177
178 @param classname: The name of the primary object class.
179 @type classname: str
180 @param handle_list: The list of handles to be removed.
181 @type handle_list: str
182 """
183 pass
184
186 """
187 Replace all references to old handle with those to the new handle.
188
189 @param classname: The name of the primary object class.
190 @type classname: str
191 @param old_handle: The handle to be replaced.
192 @type old_handle: str
193 @param new_handle: The handle to replace the old one with.
194 @type new_handle: str
195 """
196 pass
197
199 """
200 Set the marker for the object.
201
202 @param marker: marker assigned to the object
203 @type marker: MarkerType
204 """
205 self.marker.set(marker)
206
208 """
209 Return the marker for the object.
210
211 The exact type depends on the derived class type.
212
213 @return: Returns the marker for the object.
214 @rtype: MarkerType
215 """
216 return self.marker
217
219 """
220 Indicate if the object has a source references.
221
222 In the base class, no such references exist. Derived classes should
223 override this if they provide source references.
224 """
225 return False
226
235
237 """
238 Remove the specified source references from the object.
239
240 In the base class no such references exist. Derived classes should
241 override this if they provide source references.
242 """
243 pass
244
253
256
259
260
261
262
263
264
266 """
267 The PrimaryObject is the base class for all primary objects in the
268 database.
269
270 Primary objects are the core objects in the database.
271 Each object has a database handle and a GRAMPS ID value. The database
272 handle is used as the record number for the database, and the GRAMPS
273 ID is the user visible version.
274 """
275
277 """
278 Initialize a PrimaryObject.
279
280 If source is None, both the ID and handle are assigned as empty
281 strings. If source is not None, then object is initialized from values
282 of the source object.
283
284 @param source: Object used to initialize the new object
285 @type source: PrimaryObject
286 """
287 BasicPrimaryObject.__init__(self, source)
288
290 """
291 Return True if the object has reference to a given handle of given
292 primary object type.
293
294 @param classname: The name of the primary object class.
295 @type classname: str
296 @param handle: The handle to be checked.
297 @type handle: str
298 @return: Returns whether the object has reference to this handle
299 of this object type.
300 @rtype: bool
301 """
302 if classname == 'Source' and isinstance(self, SourceBase):
303 return self.has_source_reference(handle)
304 elif classname == 'MediaObject' and isinstance(self, MediaBase):
305 return self.has_media_reference(handle)
306 else:
307 return self._has_handle_reference(classname, handle)
308
310 """
311 Remove all references in this object to object handles in the list.
312
313 @param classname: The name of the primary object class.
314 @type classname: str
315 @param handle_list: The list of handles to be removed.
316 @type handle_list: str
317 """
318 if classname == 'Source' and isinstance(self, SourceBase):
319 self.remove_source_references(handle_list)
320 elif classname == 'MediaObject' and isinstance(self, MediaBase):
321 self.remove_media_references(handle_list)
322 else:
323 self._remove_handle_references(classname, handle_list)
324
326 """
327 Replace all references to old handle with those to the new handle.
328
329 @param classname: The name of the primary object class.
330 @type classname: str
331 @param old_handle: The handle to be replaced.
332 @type old_handle: str
333 @param new_handle: The handle to replace the old one with.
334 @type new_handle: str
335 """
336 if classname == 'Source' and isinstance(self, SourceBase):
337 self.replace_source_references(old_handle, new_handle)
338 elif classname == 'MediaObject' and isinstance(self, MediaBase):
339 self.replace_media_references(old_handle, new_handle)
340 else:
341 self._replace_handle_reference(classname, old_handle, new_handle)
342
344 """
345 Return True if the handle is referenced by the object.
346 """
347 return False
348
350 """
351 Remove the handle references from the object.
352 """
353 pass
354
356 """
357 Replace the handle reference with the new reference.
358 """
359 pass
360
362 self.marker.set(marker)
363
366