1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 """
24 Source 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.mediabase import MediaBase
41 from gen.lib.notebase import NoteBase
42 from gen.lib.reporef import RepoRef
43 from gen.lib.markertype import MarkerType
44
45
46
47
48
49
50 -class Source(MediaBase, NoteBase, PrimaryObject):
51 """A record of a source of information."""
52
65
67 """
68 Convert the object to a serialized tuple of data.
69 """
70 return (self.handle, self.gramps_id, unicode(self.title),
71 unicode(self.author), unicode(self.pubinfo),
72 NoteBase.serialize(self),
73 MediaBase.serialize(self), unicode(self.abbrev),
74 self.change, self.datamap,
75 [rr.serialize() for rr in self.reporef_list],
76 self.marker.serialize(), self.private)
77
79 """
80 Convert the data held in a tuple created by the serialize method
81 back into the data in an Event structure.
82 """
83 (self.handle, self.gramps_id, self.title, self.author,
84 self.pubinfo, note_list, media_list,
85 self.abbrev, self.change, self.datamap, reporef_list,
86 marker, self.private) = data
87
88 self.marker = InstanceType(MarkerType)
89 self.marker.unserialize(marker)
90 NoteBase.unserialize(self, note_list)
91 MediaBase.unserialize(self, media_list)
92 self.reporef_list = [InstanceType(RepoRef).unserialize(rr)
93 for rr in reporef_list]
94
96 """
97 Return True if the object has reference to a given handle of given
98 primary object type.
99
100 @param classname: The name of the primary object class.
101 @type classname: str
102 @param handle: The handle to be checked.
103 @type handle: str
104 @return: Returns whether the object has reference to this handle of
105 this object type.
106 @rtype: bool
107 """
108 if classname == 'Repository':
109 return handle in [ref.ref for ref in self.reporef_list]
110 return False
111
113 """
114 Remove all references in this object to object handles in the list.
115
116 @param classname: The name of the primary object class.
117 @type classname: str
118 @param handle_list: The list of handles to be removed.
119 @type handle_list: str
120 """
121 if classname == 'Repository':
122 new_list = [ ref for ref in self.reporef_list \
123 if ref.ref not in handle_list ]
124 self.reporef_list = new_list
125
127 """
128 Replace all references to old handle with those to the new handle.
129
130 @param classname: The name of the primary object class.
131 @type classname: str
132 @param old_handle: The handle to be replaced.
133 @type old_handle: str
134 @param new_handle: The handle to replace the old one with.
135 @type new_handle: str
136 """
137 if classname == 'Repository':
138 handle_list = [ref.ref for ref in self.reporef_list]
139 while old_handle in handle_list:
140 ix = handle_list.index(old_handle)
141 self.reporef_list[ix].ref = new_handle
142 handle_list[ix] = ''
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.title, self.author, self.pubinfo, self.abbrev,
152 self.gramps_id] + self.datamap.keys() + self.datamap.values()
153
155 """
156 Return the list of child objects that may carry textual data.
157
158 @return: Returns the list of child objects that may carry textual data.
159 @rtype: list
160 """
161 return self.media_list + self.reporef_list
162
164 """
165 Return the list of child secondary objects that may refer sources.
166
167 @return: Returns the list of child secondary child objects that may
168 refer sources.
169 @rtype: list
170 """
171 return self.media_list
172
174 """
175 Return the list of child secondary objects that may refer notes.
176
177 @return: Returns the list of child secondary child objects that may
178 refer notes.
179 @rtype: list
180 """
181 return self.media_list + self.reporef_list
182
184 """
185 Return the list of child objects which may, directly or through
186 their children, reference primary objects.
187
188 @return: Returns the list of objects refereincing primary objects.
189 @rtype: list
190 """
191 return self.media_list + self.reporef_list
192
194 """
195 Return the list of (classname, handle) tuples for all directly
196 referenced primary objects.
197
198 @return: List of (classname, handle) tuples for referenced objects.
199 @rtype: list
200 """
201 return self.get_referenced_note_handles()
202
204 """
205 Return True if any of the child objects has reference to this source
206 handle.
207
208 @param src_handle: The source handle to be checked.
209 @type src_handle: str
210 @return: Returns whether any of it's child objects has reference to
211 this source handle.
212 @rtype: bool
213 """
214 for item in self.get_sourcref_child_list():
215 if item.has_source_reference(src_handle):
216 return True
217
218 return False
219
221 """
222 Remove references to all source handles in the list in all child
223 objects.
224
225 @param src_handle_list: The list of source handles to be removed.
226 @type src_handle_list: list
227 """
228 for item in self.get_sourcref_child_list():
229 item.remove_source_references(src_handle_list)
230
232 """
233 Replace references to source handles in the list in this object and
234 all child objects.
235
236 @param old_handle: The source handle to be replaced.
237 @type old_handle: str
238 @param new_handle: The source handle to replace the old one with.
239 @type new_handle: str
240 """
241 for item in self.get_sourcref_child_list():
242 item.replace_source_references(old_handle, new_handle)
243
245 """Return the data map of attributes for the source."""
246 return self.datamap
247
249 """Set the data map of attributes for the source."""
250 self.datamap = datamap
251
253 """Set the particular data item in the attribute data map."""
254 self.datamap[key] = value
255
257 """
258 Set the descriptive title of the Source object.
259
260 @param title: descriptive title to assign to the Source
261 @type title: str
262 """
263 self.title = title
264
266 """
267 Return the descriptive title of the Place object.
268
269 @returns: Returns the descriptive title of the Place
270 @rtype: str
271 """
272 return self.title
273
275 """Set the author of the Source."""
276 self.author = author
277
279 """Return the author of the Source."""
280 return self.author
281
283 """Set the publication information of the Source."""
284 self.pubinfo = text
285
287 """Return the publication information of the Source."""
288 return self.pubinfo
289
291 """Set the title abbreviation of the Source."""
292 self.abbrev = abbrev
293
295 """Return the title abbreviation of the Source."""
296 return self.abbrev
297
299 """
300 Add a L{RepoRef} instance to the Source's reporef list.
301
302 @param repo_ref: L{RepoRef} instance to be added to the object's
303 reporef list.
304 @type repo_ref: L{RepoRef}
305 """
306 self.reporef_list.append(repo_ref)
307
309 """
310 Return the list of L{RepoRef} instances associated with the Source.
311
312 @Return: list of L{RepoRef} instances associated with the Source
313 @rtype: list
314 """
315 return self.reporef_list
316
318 """
319 Set the list of L{RepoRef} instances associated with the Source.
320 It replaces the previous list.
321
322 @param reporef_list: list of L{RepoRef} instances to be assigned to
323 the Source.
324 @type reporef_list: list
325 """
326 self.reporef_list = reporef_list
327
329 """
330 Return True if the Source has reference to this Repository handle.
331
332 @param repo_handle: The Repository handle to be checked.
333 @type repo_handle: str
334 @return: Returns whether the Source has reference to this Repository
335 handle.
336 @rtype: bool
337 """
338 return repo_handle in [repo_ref.ref for repo_ref in self.reporef_list]
339
341 """
342 Remove references to all Repository handles in the list.
343
344 @param repo_handle_list: The list of Repository handles to be removed.
345 @type repo_handle_list: list
346 """
347 new_reporef_list = [ repo_ref for repo_ref in self.reporef_list \
348 if repo_ref.ref not in repo_handle_list ]
349 self.reporef_list = new_reporef_list
350
352 """
353 Replace all references to old Repository handle with the new handle.
354
355 @param old_handle: The Repository handle to be replaced.
356 @type old_handle: str
357 @param new_handle: The Repository handle to replace the old one with.
358 @type new_handle: str
359 """
360 refs_list = [ repo_ref.ref for repo_ref in self.reporef_list ]
361 n_replace = refs_list.count(old_handle)
362 for ix_replace in xrange(n_replace):
363 ix = refs_list.index(old_handle)
364 self.reporef_list[ix].ref = new_handle
365 refs_list.pop(ix)
366