@@ -41,24 +41,31 @@ def get_place_by_handle(db_handle: DbReadBase, handle: Handle) -> Optional[Place
4141
4242
4343def get_family_by_handle (
44- db_handle : DbReadBase , handle : Handle , extended : bool = False
44+ db_handle : DbReadBase , handle : Handle , args : Optional [ Dict ] = None
4545) -> Optional [Family ]:
46- """Get a family and all extended attributes."""
46+ """Get a family and optional extended attributes."""
4747 try :
4848 obj = db_handle .get_family_from_handle (handle )
4949 except HandleError :
5050 return None
51- if extended :
52- obj .extended = get_extended_attributes (db_handle , obj )
53- obj .extended ["father" ] = get_person_by_handle (db_handle , obj .father_handle )
54- obj .extended ["mother" ] = get_person_by_handle (db_handle , obj .mother_handle )
51+ args = args or {}
52+ if "extend" in args :
53+ obj .extended = get_extended_attributes (db_handle , obj , args )
54+ if "all" in args ["extend" ] or "father" in args ["extend" ]:
55+ obj .extended ["father" ] = get_person_by_handle (db_handle , obj .father_handle )
56+ if "all" in args ["extend" ] or "mother" in args ["extend" ]:
57+ obj .extended ["mother" ] = get_person_by_handle (db_handle , obj .mother_handle )
5558 return obj
5659
5760
58- def get_source_by_handle (db_handle : DbReadBase , handle : Handle ) -> Source :
59- """Get a source and all extended attributes."""
61+ def get_source_by_handle (
62+ db_handle : DbReadBase , handle : Handle , args : Optional [Dict ] = None
63+ ) -> Source :
64+ """Get a source and optional extended attributes."""
65+ args = args or {}
6066 obj = db_handle .get_source_from_handle (handle )
61- obj .extended = get_extended_attributes (db_handle , obj )
67+ if "extend" in args :
68+ obj .extended = get_extended_attributes (db_handle , obj , args )
6269 return obj
6370
6471
@@ -216,43 +223,55 @@ def get_family_profile_for_handle(
216223 return get_family_profile_for_object (db_handle , obj , with_events )
217224
218225
219- def get_extended_attributes (db_handle : DbReadBase , obj : GrampsObject ) -> Dict :
226+ def get_extended_attributes (
227+ db_handle : DbReadBase , obj : GrampsObject , args : Optional [Dict ] = None
228+ ) -> Dict :
220229 """Get extended attributes for a GrampsObject."""
230+ args = args or {}
221231 result = {}
222- if hasattr (obj , "child_ref_list" ):
232+ do_all = False
233+ if "all" in args ["extend" ]:
234+ do_all = True
235+ if (do_all or "child_ref_list" in args ["extend" ]) and hasattr (
236+ obj , "child_ref_list"
237+ ):
223238 result ["children" ] = [
224239 db_handle .get_person_from_handle (child_ref .ref )
225240 for child_ref in obj .child_ref_list
226241 ]
227- if hasattr (obj , "citation_list" ):
242+ if ( do_all or "citation_list" in args [ "extend" ]) and hasattr (obj , "citation_list" ):
228243 result ["citations" ] = [
229244 db_handle .get_citation_from_handle (handle ) for handle in obj .citation_list
230245 ]
231- if hasattr (obj , "event_ref_list" ):
246+ if (do_all or "event_ref_list" in args ["extend" ]) and hasattr (
247+ obj , "event_ref_list"
248+ ):
232249 result ["events" ] = [
233250 db_handle .get_event_from_handle (event_ref .ref )
234251 for event_ref in obj .event_ref_list
235252 ]
236- if hasattr (obj , "media_list" ):
253+ if ( do_all or "media_list" in args [ "extend" ]) and hasattr (obj , "media_list" ):
237254 result ["media" ] = [
238255 db_handle .get_media_from_handle (media_ref .ref )
239256 for media_ref in obj .media_list
240257 ]
241- if hasattr (obj , "note_list" ):
258+ if ( do_all or "note_list" in args [ "extend" ]) and hasattr (obj , "note_list" ):
242259 result ["notes" ] = [
243260 db_handle .get_note_from_handle (handle ) for handle in obj .note_list
244261 ]
245- if hasattr (obj , "person_ref_list" ):
262+ if (do_all or "person_ref_list" in args ["extend" ]) and hasattr (
263+ obj , "person_ref_list"
264+ ):
246265 result ["people" ] = [
247266 db_handle .get_person_from_handle (person_ref .ref )
248267 for person_ref in obj .person_ref_list
249268 ]
250- if hasattr (obj , "reporef_list" ):
269+ if ( do_all or "reporef_list" in args [ "extend" ]) and hasattr (obj , "reporef_list" ):
251270 result ["repositories" ] = [
252271 db_handle .get_repository_from_handle (repo_ref .ref )
253272 for repo_ref in obj .reporef_list
254273 ]
255- if hasattr (obj , "tag_list" ):
274+ if ( do_all or "tag_list" in args [ "extend" ]) and hasattr (obj , "tag_list" ):
256275 result ["tags" ] = [
257276 db_handle .get_tag_from_handle (handle ) for handle in obj .tag_list
258277 ]
0 commit comments