1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 """
24 Event object for GRAMPS.
25 """
26
27
28
29
30
31
32 from gen.lib.primaryobj import PrimaryObject
33 from gen.lib.srcbase import SourceBase
34 from gen.lib.notebase import NoteBase
35 from gen.lib.mediabase import MediaBase
36 from gen.lib.attrbase import AttributeBase
37 from gen.lib.datebase import DateBase
38 from gen.lib.placebase import PlaceBase
39 from gen.lib.eventtype import EventType
40 from gen.lib.markertype import MarkerType
41
42 from types import InstanceType
43
44
45
46
47
48
49 -class Event(SourceBase, NoteBase, MediaBase, AttributeBase,
50 DateBase, PlaceBase, PrimaryObject):
51 """
52 Introduction
53 ============
54 The Event record is used to store information about some type of
55 action that occurred at a particular place at a particular time,
56 such as a birth, death, or marriage.
57 """
58
81
83 """
84 Convert the data held in the event to a Python tuple that
85 represents all the data elements.
86
87 This method is used to convert the object into a form that can easily
88 be saved to a database.
89
90 These elements may be primative Python types (string, integers),
91 complex Python types (lists or tuples, or Python objects. If the
92 target database cannot handle complex types (such as objectes or
93 lists), the database is responsible for converting the data into
94 a form that it can use.
95
96 @returns: Returns a python tuple containing the data that should
97 be considered persistent.
98 @rtype: tuple
99 """
100 return (self.handle, self.gramps_id, self.type.serialize(),
101 DateBase.serialize(self, no_text_date),
102 self.description, self.place,
103 SourceBase.serialize(self),
104 NoteBase.serialize(self),
105 MediaBase.serialize(self),
106 AttributeBase.serialize(self),
107 self.change, self.marker.serialize(), self.private)
108
110 """
111 Convert the data held in a tuple created by the serialize method
112 back into the data in an Event structure.
113
114 @param data: tuple containing the persistent data associated the
115 Person object
116 @type data: tuple
117 """
118 (self.handle, self.gramps_id, the_type, date,
119 self.description, self.place,
120 source_list, note_list, media_list, attribute_list,
121 self.change, marker, self.private) = data
122
123 self.marker = InstanceType(MarkerType)
124 self.marker.unserialize(marker)
125 self.type = InstanceType(EventType)
126 self.type.unserialize(the_type)
127 DateBase.unserialize(self, date)
128 MediaBase.unserialize(self, media_list)
129 AttributeBase.unserialize(self, attribute_list)
130 SourceBase.unserialize(self, source_list)
131 NoteBase.unserialize(self, note_list)
132
134 """
135 Return True if the object has reference to a given handle of given
136 primary object type.
137
138 @param classname: The name of the primary object class.
139 @type classname: str
140 @param handle: The handle to be checked.
141 @type handle: str
142 @return: Returns whether the object has reference to this handle of
143 this object type.
144 @rtype: bool
145 """
146 if classname == 'Place':
147 return self.place == handle
148 return False
149
151 """
152 Remove all references in this object to object handles in the list.
153
154 @param classname: The name of the primary object class.
155 @type classname: str
156 @param handle_list: The list of handles to be removed.
157 @type handle_list: str
158 """
159 if classname == 'Place' and self.place in handle_list:
160 self.place = ""
161
163 """
164 Replace all references to old handle with those to the new handle.
165
166 @param classname: The name of the primary object class.
167 @type classname: str
168 @param old_handle: The handle to be replaced.
169 @type old_handle: str
170 @param new_handle: The handle to replace the old one with.
171 @type new_handle: str
172 """
173 if classname == 'Place' and self.place == old_handle:
174 self.place = new_handle
175
177 """
178 Return the list of all textual attributes of the object.
179
180 @return: Returns the list of all textual attributes of the object.
181 @rtype: list
182 """
183 return [self.description, str(self.type), self.gramps_id]
184
186 """
187 Return the list of child objects that may carry textual data.
188
189 @return: Returns the list of child objects that may carry textual data.
190 @rtype: list
191 """
192 return self.media_list + self.source_list + self.attribute_list
193
195 """
196 Return the list of child secondary objects that may refer sources.
197
198 @return: Returns the list of child secondary child objects that may
199 refer sources.
200 @rtype: list
201 """
202 return self.media_list + self.attribute_list
203
205 """
206 Return the list of child secondary objects that may refer notes.
207
208 @return: Returns the list of child secondary child objects that may
209 refer notes.
210 @rtype: list
211 """
212 return self.media_list + self.attribute_list + self.source_list
213
215 """
216 Return the list of (classname, handle) tuples for all directly
217 referenced primary objects.
218
219 @return: List of (classname, handle) tuples for referenced objects.
220 @rtype: list
221 """
222 ret = self.get_referenced_note_handles()
223 if self.place:
224 ret.append(('Place', self.place))
225 return ret
226
228 """
229 Return the list of child objects which may, directly or through
230 their children, reference primary objects.
231
232 @return: Returns the list of objects refereincing primary objects.
233 @rtype: list
234 """
235 return self.get_sourcref_child_list() + self.source_list
236
238 """
239 Return True if the Event is an empty object (no values set).
240
241 @returns: True if the Event is empty
242 @rtype: bool
243 """
244 date = self.get_date_object()
245 place = self.get_place_handle()
246 description = self.description
247 the_type = self.type
248 return (the_type == EventType.CUSTOM and date.is_empty()
249 and not place and not description)
250
279
281 """
282 Set the type of the Event to the passed (int,str) tuple.
283
284 @param the_type: Type to assign to the Event
285 @type the_type: tuple
286 """
287 self.type.set(the_type)
288
290 """
291 Return the type of the Event.
292
293 @return: Type of the Event
294 @rtype: tuple
295 """
296 return self.type
297
299 """
300 Set the description of the Event to the passed string.
301
302 The string may contain any information.
303
304 @param description: Description to assign to the Event
305 @type description: str
306 """
307 self.description = description
308
310 """
311 Return the description of the Event.
312
313 @return: Returns the description of the Event
314 @rtype: str
315 """
316 return self.description
317