本文整理汇总了Python中gramps.gen.lib.Family.set_gramps_id方法的典型用法代码示例。如果您正苦于以下问题:Python Family.set_gramps_id方法的具体用法?Python Family.set_gramps_id怎么用?Python Family.set_gramps_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gramps.gen.lib.Family
的用法示例。
在下文中一共展示了Family.set_gramps_id方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_or_create_family
# 需要导入模块: from gramps.gen.lib import Family [as 别名]
# 或者: from gramps.gen.lib.Family import set_gramps_id [as 别名]
def get_or_create_family(self, family_ref, husband, wife):
"Return the family object for the give family ID."
# if a gramps_id and exists:
LOG.debug("get_or_create_family")
if family_ref.startswith("[") and family_ref.endswith("]"):
id_ = self.db.fid2user_format(family_ref[1:-1])
family = self.db.get_family_from_gramps_id(id_)
if family:
# don't delete, only add
fam_husband_handle = family.get_father_handle()
fam_wife_handle = family.get_mother_handle()
if husband:
if husband.get_handle() != fam_husband_handle:
# this husband is not the same old one! Add him!
family.set_father_handle(husband.get_handle())
if wife:
if wife.get_handle() != fam_wife_handle:
# this wife is not the same old one! Add her!
family.set_mother_handle(wife.get_handle())
LOG.debug(" returning existing family")
return family
# if not, create one:
family = Family()
# was marked with a gramps_id, but didn't exist, so we'll use it:
if family_ref.startswith("[") and family_ref.endswith("]"):
id_ = self.db.fid2user_format(family_ref[1:-1])
family.set_gramps_id(id_)
# add it:
family.set_handle(create_id())
if self.default_tag:
family.add_tag(self.default_tag.handle)
if husband:
family.set_father_handle(husband.get_handle())
husband.add_family_handle(family.get_handle())
if wife:
family.set_mother_handle(wife.get_handle())
wife.add_family_handle(family.get_handle())
if husband and wife:
family.set_relationship(FamilyRelType.MARRIED)
self.db.add_family(family, self.trans)
if husband:
self.db.commit_person(husband, self.trans)
if wife:
self.db.commit_person(wife, self.trans)
self.fam_count += 1
return family