1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 """
24 Name class for GRAMPS.
25 """
26
27
28
29
30
31
32 from gen.lib.secondaryobj import SecondaryObject
33 from gen.lib.privacybase import PrivacyBase
34 from gen.lib.srcbase import SourceBase
35 from gen.lib.notebase import NoteBase
36 from gen.lib.datebase import DateBase
37 from gen.lib.nametype import NameType
38
39
40
41
42
43
44 -class Name(SecondaryObject, PrivacyBase, SourceBase, NoteBase, DateBase):
45 """
46 Provide name information about a person.
47
48 A person may have more that one name throughout his or her life.
49 """
50
51 DEF = 0
52 LNFN = 1
53 FNLN = 2
54 PTFN = 3
55 FN = 4
56
57 - def __init__(self, source=None, data=None):
58 """Create a new Name instance, copying from the source if provided."""
59 PrivacyBase.__init__(self, source)
60 SourceBase.__init__(self, source)
61 NoteBase.__init__(self, source)
62 DateBase.__init__(self, source)
63 if data:
64 (privacy, source_list, note, date,
65 self.first_name, self.surname, self.suffix, self.title,
66 name_type, self.prefix, self.patronymic,
67 self.group_as, self.sort_as, self.display_as, self.call) = data
68 self.type = NameType(name_type)
69 PrivacyBase.unserialize(self, privacy)
70 SourceBase.unserialize(self, source_list)
71 NoteBase.unserialize(self, note)
72 DateBase.unserialize(self, date)
73 elif source:
74 self.first_name = source.first_name
75 self.surname = source.surname
76 self.suffix = source.suffix
77 self.title = source.title
78 self.type = source.type
79 self.prefix = source.prefix
80 self.patronymic = source.patronymic
81 self.group_as = source.group_as
82 self.sort_as = source.sort_as
83 self.display_as = source.display_as
84 self.call = source.call
85 else:
86 self.first_name = ""
87 self.surname = ""
88 self.suffix = ""
89 self.title = ""
90 self.type = NameType()
91 self.prefix = ""
92 self.patronymic = ""
93 self.group_as = ""
94 self.sort_as = self.DEF
95 self.display_as = self.DEF
96 self.call = u''
97
99 """
100 Convert the object to a serialized tuple of data.
101 """
102 return (PrivacyBase.serialize(self),
103 SourceBase.serialize(self),
104 NoteBase.serialize(self),
105 DateBase.serialize(self),
106 self.first_name, self.surname, self.suffix, self.title,
107 self.type.serialize(), self.prefix, self.patronymic,
108 self.group_as, self.sort_as, self.display_as, self.call)
109
111 """
112 Indicate if the name is empty.
113 """
114 return (self.first_name == u"" and self.surname == u"" and
115 self.suffix == u"" and self.title == u"" and
116 self.prefix == u"" and self.patronymic == u"")
117
119 """
120 Convert a serialized tuple of data to an object.
121 """
122 (privacy, source_list, note_list, date,
123 self.first_name, self.surname, self.suffix, self.title,
124 name_type, self.prefix, self.patronymic,
125 self.group_as, self.sort_as, self.display_as, self.call) = data
126 self.type = NameType(name_type)
127 PrivacyBase.unserialize(self, privacy)
128 SourceBase.unserialize(self, source_list)
129 NoteBase.unserialize(self, note_list)
130 DateBase.unserialize(self, date)
131 return self
132
134 """
135 Return the list of all textual attributes of the object.
136
137 @return: Returns the list of all textual attributes of the object.
138 @rtype: list
139 """
140 return [self.first_name, self.surname, self.suffix, self.title,
141 str(self.type), self.prefix, self.patronymic, self.call]
142
144 """
145 Return the list of child objects that may carry textual data.
146
147 @return: Returns the list of child objects that may carry textual data.
148 @rtype: list
149 """
150 return self.source_list
151
153 """
154 Return the list of child secondary objects that may refer notes.
155
156 @return: Returns the list of child secondary child objects that may
157 refer notes.
158 @rtype: list
159 """
160 return self.source_list
161
163 """
164 Return the list of child objects which may, directly or through
165 their children, reference primary objects.
166
167 @return: Returns the list of objects refereincing primary objects.
168 @rtype: list
169 """
170 return self.source_list
171
173 """
174 Return the list of (classname, handle) tuples for all directly
175 referenced primary objects.
176
177 @return: List of (classname, handle) tuples for referenced objects.
178 @rtype: list
179 """
180 return self.get_referenced_note_handles()
181
183 """
184 Set the grouping name for a person.
185
186 Normally, this is the person's surname. However, some locales group
187 equivalent names (e.g. Ivanova and Ivanov in Russian are usually
188 considered equivalent.
189
190 Note that there is also a database wide grouping set_name_group_mapping
191 So one might map a name Smith to SmithNew, and have one person still
192 grouped with name Smith. Hence, group_as can be equal to surname!
193 """
194 self.group_as = name
195
197 """
198 Return the grouping name, which is used to group equivalent surnames.
199 """
200 return self.group_as
201
203 """
204 Return the grouping name, which is used to group equivalent surnames.
205 """
206 if self.group_as:
207 return self.group_as
208 else:
209 return self.surname
210
212 """
213 Specifies the sorting method for the specified name.
214
215 Typically the locale's default should be used. However, there may be
216 names where a specific sorting structure is desired for a name.
217 """
218 self.sort_as = value
219
221 """
222 Return the selected sorting method for the name.
223
224 The options are LNFN (last name, first name), FNLN (first name, last
225 name), etc.
226 """
227 return self.sort_as
228
230 """
231 Specifies the display format for the specified name.
232
233 Typically the locale's default should be used. However, there may be
234 names where a specific display format is desired for a name.
235 """
236 self.display_as = value
237
239 """
240 Return the selected display format for the name.
241
242 The options are LNFN (last name, first name), FNLN (first name, last
243 name), etc.
244 """
245 return self.display_as
246
248 """
249 Return the call name.
250
251 The call name's exact definition is not predetermined, and may be
252 locale specific.
253 """
254 return self.call
255
257 """
258 Set the call name.
259
260 The call name's exact definition is not predetermined, and may be
261 locale specific.
262 """
263 self.call = val
264
266 """
267 Return the prefix (or article) of a surname.
268
269 The prefix is not used for sorting or grouping.
270 """
271 return self.prefix
272
274 """
275 Set the prefix (or article) of a surname.
276
277 Examples of articles would be 'de' or 'van'.
278 """
279 self.prefix = val
280
282 """Set the type of the Name instance."""
283 self.type.set(the_type)
284
286 """Return the type of the Name instance."""
287 return self.type
288
290 """Set the given name for the Name instance."""
291 self.first_name = name
292
294 """Set the patronymic name for the Name instance."""
295 self.patronymic = name
296
298 """Set the surname (or last name) for the Name instance."""
299 self.surname = name
300
302 """Set the suffix (such as Jr., III, etc.) for the Name instance."""
303 self.suffix = name
304
306 """Return the given name for the Name instance."""
307 return self.first_name
308
310 """Return the patronymic name for the Name instance."""
311 return self.patronymic
312
314 """Return the surname (or last name) for the Name instance."""
315 return self.surname
316
318 """Return the surname (or last name) for the Name instance."""
319 return self.surname.upper()
320
322 """Return the suffix for the Name instance."""
323 return self.suffix
324
326 """Set the title (Dr., Reverand, Captain) for the Name instance."""
327 self.title = title
328
330 """Return the title for the Name instance."""
331 return self.title
332
334 """
335 Return a name string built from the components of the Name instance,
336 in the form of surname, Firstname.
337 """
338
339 if self.patronymic:
340 first = "%s %s" % (self.first_name, self.patronymic)
341 else:
342 first = self.first_name
343 if self.suffix:
344 if self.prefix:
345 return "%s %s, %s %s" % (self.prefix, self.surname,
346 first, self.suffix)
347 else:
348 return "%s, %s %s" % (self.surname, first, self.suffix)
349 else:
350 if self.prefix:
351 return "%s %s, %s" % (self.prefix, self.surname, first)
352 else:
353 return "%s, %s" % (self.surname, first)
354
356 """
357 Return a name string built from the components of the Name instance,
358 in the form of surname, Firstname.
359 """
360
361 if self.patronymic:
362 first = "%s %s" % (self.first_name, self.patronymic)
363 else:
364 first = self.first_name
365 if self.suffix:
366 if self.prefix:
367 return "%s %s, %s %s" % (self.prefix.upper(),
368 self.surname.upper(), first,
369 self.suffix)
370 else:
371 return "%s, %s %s" % (self.surname.upper(), first, self.suffix)
372 else:
373 if self.prefix:
374 return "%s %s, %s" % (self.prefix.upper(),
375 self.surname.upper(),
376 first)
377 else:
378 return "%s, %s" % (self.surname.upper(), first)
379
381 """
382 Return a name string built from the components of the Name instance,
383 in the form of Firstname surname.
384 """
385 if self.patronymic:
386 first = "%s %s" % (self.first_name, self.patronymic)
387 else:
388 first = self.first_name
389 if (self.suffix == ""):
390 if self.prefix:
391 return "%s %s %s" % (first, self.prefix, self.surname)
392 else:
393 return "%s %s" % (first, self.surname)
394 else:
395 if self.prefix:
396 return "%s %s %s, %s" % (first, self.prefix, self.surname,
397 self.suffix)
398 else:
399 return "%s %s, %s" % (first, self.surname, self.suffix)
400