Code guideline: move to relative import within gen module

svn: r20478
This commit is contained in:
Benny Malengier 2012-10-01 20:53:08 +00:00
parent adac46441d
commit 47a612c36a
13 changed files with 589 additions and 569 deletions

View File

@ -29,7 +29,6 @@
import cPickle import cPickle
import base64 import base64
import time import time
import gen
import re import re
from . import DbReadBase, DbWriteBase, DbTxn from . import DbReadBase, DbWriteBase, DbTxn
from . import (PERSON_KEY, from . import (PERSON_KEY,
@ -42,6 +41,7 @@ from . import (PERSON_KEY,
REPOSITORY_KEY, REPOSITORY_KEY,
NOTE_KEY) NOTE_KEY)
from ..utils.id import create_id from ..utils.id import create_id
from ..lib.researcher import Researcher
from ..lib.mediaobj import MediaObject from ..lib.mediaobj import MediaObject
from ..lib.person import Person from ..lib.person import Person
from ..lib.family import Family from ..lib.family import Family
@ -509,7 +509,7 @@ class DictionaryDb(DbWriteBase, DbReadBase):
return None return None
def get_researcher(self): def get_researcher(self):
obj = gen.lib.Researcher() obj = Researcher()
return obj return obj
def get_person_handles(self, sort_handles=False): def get_person_handles(self, sort_handles=False):

View File

@ -45,11 +45,11 @@ except ValueError:
from test import test_util from test import test_util
test_util.path_append_parent() test_util.path_append_parent()
from gen.config import config from ...config import config
import gen.datehandler from ...datehandler import get_date_formats, set_format
from gen.datehandler import parser as _dp from ...datehandler import parser as _dp
from gen.datehandler import displayer as _dd from ...datehandler import displayer as _dd
from gen.lib.date import Date, Span from ...lib.date import Date, Span
gettext.textdomain("gramps") gettext.textdomain("gramps")
gettext.install("gramps",loc,unicode=1) gettext.install("gramps",loc,unicode=1)
@ -221,7 +221,7 @@ cal_str = [ "CAL_GREGORIAN", "CAL_JULIAN", "CAL_HEBREW", "CAL_FRENCH",
mod_str = ["MOD_NONE", "MOD_BEFORE", "MOD_AFTER", "MOD_ABOUT", "MOD_RANGE", mod_str = ["MOD_NONE", "MOD_BEFORE", "MOD_AFTER", "MOD_ABOUT", "MOD_RANGE",
"MOD_SPAN", "MOD_TEXTONLY"] "MOD_SPAN", "MOD_TEXTONLY"]
qua_str = ["QUAL_NONE", "QUAL_ESTIMATED", "QUAL_CALCULATED"] qua_str = ["QUAL_NONE", "QUAL_ESTIMATED", "QUAL_CALCULATED"]
formats = gen.datehandler.get_date_formats() formats = get_date_formats()
class Eval(unittest.TestCase): class Eval(unittest.TestCase):
def __init__(self, method_name, dateval, e1, e2, e3, format): def __init__(self, method_name, dateval, e1, e2, e3, format):
@ -247,12 +247,12 @@ def suite3():
suite = unittest.TestSuite() suite = unittest.TestSuite()
count = 1 count = 1
for testset in date_tests: for testset in date_tests:
for format in range( len( gen.datehandler.get_date_formats())): for format in range( len( get_date_formats())):
gen.datehandler.set_format(format) set_format(format)
for dateval in date_tests[testset]: for dateval in date_tests[testset]:
if dateval.modifier != Date.MOD_TEXTONLY: if dateval.modifier != Date.MOD_TEXTONLY:
dateval.text = ("Comment. Format: %s" % dateval.text = ("Comment. Format: %s" %
gen.datehandler.get_date_formats()[format]) get_date_formats()[format])
suite.addTest( suite.addTest(
Eval("testset '%s' test_eval%04d" % (testset, count), Eval("testset '%s' test_eval%04d" % (testset, count),
dateval, dateval,

File diff suppressed because it is too large Load Diff

View File

@ -37,8 +37,8 @@ import libxslt
from libgrampsxml import GRAMPS_XML_VERSION from libgrampsxml import GRAMPS_XML_VERSION
from gen.const import ROOT_DIR, VERSION, USER_PLUGINS from gen.const import ROOT_DIR, VERSION, USER_PLUGINS
import gen.lib from ...lib import Name, Surname
from gen.ggettext import sgettext as _ from ...ggettext import sgettext as _
class CopiedDoc(object): class CopiedDoc(object):
"""Context manager that creates a deep copy of an libxml-xml document.""" """Context manager that creates a deep copy of an libxml-xml document."""
@ -1029,9 +1029,9 @@ class BirthCheck(BaseMergeCheck):
</database>""" </database>"""
self.basedoc = libxml2.readDoc(self.base_str + base_str, '', None, self.basedoc = libxml2.readDoc(self.base_str + base_str, '', None,
libxml2.XML_PARSE_NONET) libxml2.XML_PARSE_NONET)
surname = gen.lib.Surname() surname = Surname()
surname.set_surname(u"Person 0") surname.set_surname(u"Person 0")
name = gen.lib.Name() name = Name()
name.add_surname(surname) name.add_surname(surname)
self.expect_str = "person: i0000 ('i0000', 'I0000', 1, %s, [], " % str( self.expect_str = "person: i0000 ('i0000', 'I0000', 1, %s, [], " % str(
name.serialize()) name.serialize())

View File

@ -26,7 +26,7 @@ Contain and organize bibliographic information.
""" """
import string import string
import math import math
import gen.lib from ...lib.citation import Citation as lib_Citation
class Citation(object): class Citation(object):
""" """
@ -213,7 +213,7 @@ class Bibliography(object):
if ( self.mode & self.MODE_CONF ) == self.MODE_CONF: if ( self.mode & self.MODE_CONF ) == self.MODE_CONF:
confidence = source_ref.get_confidence_level() confidence = source_ref.get_confidence_level()
if confidence is not None and confidence != \ if confidence is not None and confidence != \
gen.lib.Citation.CONF_NORMAL: lib_Citation.CONF_NORMAL:
return True return True
if ( self.mode & self.MODE_NOTE ) == self.MODE_NOTE: if ( self.mode & self.MODE_NOTE ) == self.MODE_NOTE:
if len(source_ref.get_note_list()) != 0: if len(source_ref.get_note_list()) != 0:

View File

@ -41,9 +41,9 @@ from gen.ggettext import gettext as _
# GRAMPS modules # GRAMPS modules
# #
#------------------------------------------------------------------------ #------------------------------------------------------------------------
import gen.datehandler from ...datehandler import get_date
from gen.utils.file import media_path_full from ...utils.file import media_path_full
from gen.plug.docgen import IndexMark, INDEX_TYPE_ALP from ..docgen import IndexMark, INDEX_TYPE_ALP
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -190,12 +190,12 @@ def get_person_mark(db, person):
birth_ref = person.get_birth_ref() birth_ref = person.get_birth_ref()
if birth_ref: if birth_ref:
birthEvt = db.get_event_from_handle(birth_ref.ref) birthEvt = db.get_event_from_handle(birth_ref.ref)
birth = gen.datehandler.get_date(birthEvt) birth = get_date(birthEvt)
death_ref = person.get_death_ref() death_ref = person.get_death_ref()
if death_ref: if death_ref:
deathEvt = db.get_event_from_handle(death_ref.ref) deathEvt = db.get_event_from_handle(death_ref.ref)
death = gen.datehandler.get_date(deathEvt) death = get_date(deathEvt)
if birth == death == " ": if birth == death == " ":
key = name key = name
@ -247,8 +247,8 @@ def get_person_filters(person, include_single=True):
@param include_single: include a filter to include the single person @param include_single: include a filter to include the single person
@type person: boolean @type person: boolean
""" """
from gen.filters import GenericFilter, rules, CustomFilters from ...filters import GenericFilter, rules, CustomFilters
from gen.display.name import displayer as name_displayer from ...display.name import displayer as name_displayer
if person: if person:
name = name_displayer.display(person) name = name_displayer.display(person)

View File

@ -35,12 +35,12 @@ import os
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import gen.lib from lib import Person, ChildRefType, EventType, FamilyRelType
MALE = gen.lib.Person.MALE MALE = Person.MALE
FEMALE = gen.lib.Person.FEMALE FEMALE = Person.FEMALE
UNKNOWN = gen.lib.Person.UNKNOWN UNKNOWN = Person.UNKNOWN
from gen.ggettext import sgettext as _ from ggettext import sgettext as _
from gen.plug import PluginRegister, BasePluginManager from plug import PluginRegister, BasePluginManager
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -610,9 +610,9 @@ class RelationshipCalculator(object):
ref.get_father_relation()) for ref in ref.get_father_relation()) for ref in
family.get_child_ref_list() family.get_child_ref_list()
if ref.ref == person.handle] if ref.ref == person.handle]
if not birthmother and childrel[0][0] == gen.lib.ChildRefType.BIRTH: if not birthmother and childrel[0][0] == ChildRefType.BIRTH:
birthmother = family.get_mother_handle() birthmother = family.get_mother_handle()
if not birthfather and childrel[0][1] == gen.lib.ChildRefType.BIRTH: if not birthfather and childrel[0][1] == ChildRefType.BIRTH:
birthfather = family.get_father_handle() birthfather = family.get_father_handle()
if birthmother and birthfather: if birthmother and birthfather:
break break
@ -631,11 +631,11 @@ class RelationshipCalculator(object):
ref.get_father_relation()) for ref in ref.get_father_relation()) for ref in
family.get_child_ref_list() family.get_child_ref_list()
if ref.ref == person.handle] if ref.ref == person.handle]
if not childrel[0][0] == gen.lib.ChildRefType.BIRTH \ if not childrel[0][0] == ChildRefType.BIRTH \
and not childrel[0][0] == gen.lib.ChildRefType.UNKNOWN : and not childrel[0][0] == ChildRefType.UNKNOWN :
nb_parents.append(family.get_mother_handle()) nb_parents.append(family.get_mother_handle())
if not childrel[0][1] == gen.lib.ChildRefType.BIRTH \ if not childrel[0][1] == ChildRefType.BIRTH \
and not childrel[0][1] == gen.lib.ChildRefType.UNKNOWN : and not childrel[0][1] == ChildRefType.UNKNOWN :
nb_parents.append(family.get_father_handle()) nb_parents.append(family.get_father_handle())
#make every person appear only once: #make every person appear only once:
return list(set(nb_parents)) return list(set(nb_parents))
@ -658,21 +658,21 @@ class RelationshipCalculator(object):
ex = False ex = False
for eventref in family.get_event_ref_list(): for eventref in family.get_event_ref_list():
event = db.get_event_from_handle(eventref.ref) event = db.get_event_from_handle(eventref.ref)
if event and (event.get_type() == gen.lib.EventType.DIVORCE if event and (event.get_type() == EventType.DIVORCE
or event.get_type() == gen.lib.EventType.ANNULMENT): or event.get_type() == EventType.ANNULMENT):
ex = True ex = True
break break
if family_rel == gen.lib.FamilyRelType.MARRIED: if family_rel == FamilyRelType.MARRIED:
if ex: if ex:
val.append(self.PARTNER_EX_MARRIED) val.append(self.PARTNER_EX_MARRIED)
else: else:
val.append(self.PARTNER_MARRIED) val.append(self.PARTNER_MARRIED)
elif family_rel == gen.lib.FamilyRelType.UNMARRIED: elif family_rel == FamilyRelType.UNMARRIED:
if ex: if ex:
val.append(self.PARTNER_EX_UNMARRIED) val.append(self.PARTNER_EX_UNMARRIED)
else: else:
val.append(self.PARTNER_UNMARRIED) val.append(self.PARTNER_UNMARRIED)
elif family_rel == gen.lib.FamilyRelType.CIVIL_UNION: elif family_rel == FamilyRelType.CIVIL_UNION:
if ex: if ex:
val.append(self.PARTNER_EX_CIVIL_UNION) val.append(self.PARTNER_EX_CIVIL_UNION)
else: else:
@ -967,7 +967,7 @@ class RelationshipCalculator(object):
self.REL_MOTHER_NOTBIRTH, childrel[0][0])]: self.REL_MOTHER_NOTBIRTH, childrel[0][0])]:
if data[0] and data[0] not in parentstodo : if data[0] and data[0] not in parentstodo :
persontodo = db.get_person_from_handle(data[0]) persontodo = db.get_person_from_handle(data[0])
if data[3] == gen.lib.ChildRefType.BIRTH : if data[3] == ChildRefType.BIRTH :
addstr = data[1] addstr = data[1]
elif not self.__only_birth : elif not self.__only_birth :
addstr = data[2] addstr = data[2]

View File

@ -28,16 +28,17 @@ Provide a simplified database access interface to the GRAMPS database.
from __future__ import with_statement from __future__ import with_statement
from types import NoneType from types import NoneType
import gen.lib from ..lib import (Person, Family, Event, Source, Place, Citation,
import gen.datehandler MediaObject, Repository, Note, Date)
from gen.utils.string import gender as gender_map from ..datehandler import displayer
from gen.utils.db import get_birth_or_fallback, get_death_or_fallback from ..utils.string import gender as gender_map
from gen.plug.report.utils import place_name from ..utils.db import get_birth_or_fallback, get_death_or_fallback
from ..plug.report.utils import place_name
from gen.display.name import displayer as name_displayer from ..display.name import displayer as name_displayer
from gen.lib import EventType from ..lib import EventType
from gen.config import config from ..config import config
from gen.ggettext import gettext as _ from ..ggettext import gettext as _
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -127,7 +128,7 @@ class SimpleAccess(object):
""" """
if type(person) in [str, unicode]: if type(person) in [str, unicode]:
person = self.dbase.get_person_from_handle(person) person = self.dbase.get_person_from_handle(person)
assert(isinstance(person, (gen.lib.Person, NoneType))) assert(isinstance(person, (Person, NoneType)))
if person: if person:
return name_displayer.display(person) return name_displayer.display(person)
else: else:
@ -144,7 +145,7 @@ class SimpleAccess(object):
""" """
if type(person) in [str, unicode]: if type(person) in [str, unicode]:
person = self.dbase.get_person_from_handle(person) person = self.dbase.get_person_from_handle(person)
assert(isinstance(person, (gen.lib.Person, NoneType))) assert(isinstance(person, (Person, NoneType)))
if person: if person:
surname = person.get_primary_name().get_surname() surname = person.get_primary_name().get_surname()
return surname or config.get('preferences.no-surname-text') return surname or config.get('preferences.no-surname-text')
@ -162,7 +163,7 @@ class SimpleAccess(object):
""" """
if type(person) in [str, unicode]: if type(person) in [str, unicode]:
person = self.dbase.get_person_from_handle(person) person = self.dbase.get_person_from_handle(person)
assert(isinstance(person, (gen.lib.Person, NoneType))) assert(isinstance(person, (Person, NoneType)))
if person: if person:
return person.get_primary_name().get_first_name() return person.get_primary_name().get_first_name()
else: else:
@ -193,7 +194,7 @@ class SimpleAccess(object):
""" """
if type(person) in [str, unicode]: if type(person) in [str, unicode]:
person = self.dbase.get_person_from_handle(person) person = self.dbase.get_person_from_handle(person)
assert(isinstance(person, (gen.lib.Person, NoneType))) assert(isinstance(person, (Person, NoneType)))
if person: if person:
return gender_map[person.get_gender()] return gender_map[person.get_gender()]
return u'' return u''
@ -209,7 +210,7 @@ class SimpleAccess(object):
@return: mother or father of the associated person @return: mother or father of the associated person
@rtype: L{gen.lib.Person} @rtype: L{gen.lib.Person}
""" """
assert(isinstance(person, (gen.lib.Person, NoneType))) assert(isinstance(person, (Person, NoneType)))
if person: if person:
parent_handle_list = person.get_parent_family_handle_list() parent_handle_list = person.get_parent_family_handle_list()
@ -230,7 +231,7 @@ class SimpleAccess(object):
@return: mother or father of the associated family @return: mother or father of the associated family
@rtype: L{gen.lib.Family} @rtype: L{gen.lib.Family}
""" """
assert(isinstance(family, (gen.lib.Family, NoneType))) assert(isinstance(family, (Family, NoneType)))
if family: if family:
handle = func(family) handle = func(family)
@ -249,7 +250,7 @@ class SimpleAccess(object):
@return: Returns a string describing the date @return: Returns a string describing the date
@rtype: unicode @rtype: unicode
""" """
assert(isinstance(person, (gen.lib.Person, NoneType))) assert(isinstance(person, (Person, NoneType)))
if person: if person:
ref = func(person) ref = func(person)
@ -259,7 +260,7 @@ class SimpleAccess(object):
event = self.dbase.get_event_from_handle(event_handle) event = self.dbase.get_event_from_handle(event_handle)
date_obj = event.get_date_object() date_obj = event.get_date_object()
if date_obj: if date_obj:
return gen.datehandler.displayer.display(date_obj) return displayer.display(date_obj)
return u'' return u''
def __event_date_obj(self, person, func): def __event_date_obj(self, person, func):
@ -273,7 +274,7 @@ class SimpleAccess(object):
@return: Returns the date @return: Returns the date
@rtype: l{gen.lib.Date} @rtype: l{gen.lib.Date}
""" """
assert(isinstance(person, (gen.lib.Person, NoneType))) assert(isinstance(person, (Person, NoneType)))
if person: if person:
ref = func(person) ref = func(person)
@ -285,8 +286,8 @@ class SimpleAccess(object):
if date_obj: if date_obj:
return date_obj return date_obj
else: else:
return gen.lib.Date() return Date()
return gen.lib.Date() return Date()
def __event_place(self, person, func): def __event_place(self, person, func):
""" """
@ -299,7 +300,7 @@ class SimpleAccess(object):
@return: Returns a string describing the place @return: Returns a string describing the place
@rtype: unicode @rtype: unicode
""" """
assert(isinstance(person, (gen.lib.Person, NoneType))) assert(isinstance(person, (Person, NoneType)))
if person: if person:
ref = func(person) ref = func(person)
@ -322,7 +323,7 @@ class SimpleAccess(object):
""" """
if type(person) in [str, unicode]: if type(person) in [str, unicode]:
person = self.dbase.get_person_from_handle(person) person = self.dbase.get_person_from_handle(person)
assert(isinstance(person, (gen.lib.Person, NoneType))) assert(isinstance(person, (Person, NoneType)))
if person: if person:
family_handle_list = person.get_family_handle_list() family_handle_list = person.get_family_handle_list()
@ -350,7 +351,7 @@ class SimpleAccess(object):
""" """
if type(person) in [str, unicode]: if type(person) in [str, unicode]:
person = self.dbase.get_person_from_handle(person) person = self.dbase.get_person_from_handle(person)
assert(isinstance(person, (gen.lib.Person, NoneType))) assert(isinstance(person, (Person, NoneType)))
if person: if person:
family_handle_list = person.get_family_handle_list() family_handle_list = person.get_family_handle_list()
@ -374,7 +375,7 @@ class SimpleAccess(object):
""" """
if type(person) in [str, unicode]: if type(person) in [str, unicode]:
person = self.dbase.get_person_from_handle(person) person = self.dbase.get_person_from_handle(person)
assert(isinstance(person, (gen.lib.Person, NoneType))) assert(isinstance(person, (Person, NoneType)))
if person: if person:
family_handle_list = person.get_family_handle_list() family_handle_list = person.get_family_handle_list()
@ -406,7 +407,7 @@ class SimpleAccess(object):
""" """
if type(person) in [str, unicode]: if type(person) in [str, unicode]:
person = self.dbase.get_person_from_handle(person) person = self.dbase.get_person_from_handle(person)
assert(isinstance(person, (gen.lib.Person, NoneType))) assert(isinstance(person, (Person, NoneType)))
if person: if person:
family_handle_list = person.get_family_handle_list() family_handle_list = person.get_family_handle_list()
@ -423,7 +424,7 @@ class SimpleAccess(object):
if events: if events:
date_obj = events[0].get_date_object() date_obj = events[0].get_date_object()
if date_obj: if date_obj:
return gen.datehandler.displayer.display(date_obj) return displayer.display(date_obj)
return u'' return u''
def children(self, obj): def children(self, obj):
@ -435,9 +436,9 @@ class SimpleAccess(object):
@return: Returns a list of L{gen.lib.Person} objects representing the children @return: Returns a list of L{gen.lib.Person} objects representing the children
@rtype: list @rtype: list
""" """
assert(isinstance(obj, (gen.lib.Person, gen.lib.Family, NoneType))) assert(isinstance(obj, (Person, Family, NoneType)))
if isinstance(obj, gen.lib.Person): if isinstance(obj, Person):
family_handle_list = obj.get_family_handle_list() family_handle_list = obj.get_family_handle_list()
if family_handle_list: if family_handle_list:
family_id = family_handle_list[0] family_id = family_handle_list[0]
@ -445,7 +446,7 @@ class SimpleAccess(object):
return [ self.dbase.get_person_from_handle(hndl.ref) return [ self.dbase.get_person_from_handle(hndl.ref)
for hndl in family.get_child_ref_list() ] for hndl in family.get_child_ref_list() ]
elif isinstance(obj, gen.lib.Family): elif isinstance(obj, Family):
return [ self.dbase.get_person_from_handle(hndl.ref) return [ self.dbase.get_person_from_handle(hndl.ref)
for hndl in obj.get_child_ref_list() ] for hndl in obj.get_child_ref_list() ]
return [] return []
@ -461,10 +462,10 @@ class SimpleAccess(object):
family family
@rtype: L{gen.lib.Person} @rtype: L{gen.lib.Person}
""" """
if isinstance(obj, gen.lib.Person): if isinstance(obj, Person):
return self.__parent(obj, gen.lib.Family.get_father_handle) return self.__parent(obj, Family.get_father_handle)
elif isinstance(obj, gen.lib.Family): elif isinstance(obj, Family):
return self.__family_parent(obj, gen.lib.Family.get_father_handle) return self.__family_parent(obj, Family.get_father_handle)
else: else:
return None return None
@ -479,10 +480,10 @@ class SimpleAccess(object):
family family
@rtype: L{gen.lib.Person} @rtype: L{gen.lib.Person}
""" """
if isinstance(obj, gen.lib.Person): if isinstance(obj, Person):
return self.__parent(obj, gen.lib.Family.get_mother_handle) return self.__parent(obj, Family.get_mother_handle)
elif isinstance(obj, gen.lib.Family): elif isinstance(obj, Family):
return self.__family_parent(obj, gen.lib.Family.get_mother_handle) return self.__family_parent(obj, Family.get_mother_handle)
else: else:
return None return None
@ -497,7 +498,7 @@ class SimpleAccess(object):
""" """
if type(person) in [str, unicode]: if type(person) in [str, unicode]:
person = self.dbase.get_person_from_handle(person) person = self.dbase.get_person_from_handle(person)
return self.__event_date(person, gen.lib.Person.get_birth_ref) return self.__event_date(person, Person.get_birth_ref)
def birth_date_obj(self, person): def birth_date_obj(self, person):
""" """
@ -510,7 +511,7 @@ class SimpleAccess(object):
""" """
if type(person) in [str, unicode]: if type(person) in [str, unicode]:
person = self.dbase.get_person_from_handle(person) person = self.dbase.get_person_from_handle(person)
return self.__event_date_obj(person, gen.lib.Person.get_birth_ref) return self.__event_date_obj(person, Person.get_birth_ref)
def birth_or_fallback(self, person, get_event=False): def birth_or_fallback(self, person, get_event=False):
@ -530,7 +531,7 @@ class SimpleAccess(object):
elif event: elif event:
return event.date return event.date
else: else:
return gen.lib.Date() return Date()
def birth_place(self, person): def birth_place(self, person):
""" """
@ -543,7 +544,7 @@ class SimpleAccess(object):
""" """
if type(person) in [str, unicode]: if type(person) in [str, unicode]:
person = self.dbase.get_person_from_handle(person) person = self.dbase.get_person_from_handle(person)
return self.__event_place(person, gen.lib.Person.get_birth_ref) return self.__event_place(person, Person.get_birth_ref)
def death_date(self, person): def death_date(self, person):
""" """
@ -556,7 +557,7 @@ class SimpleAccess(object):
""" """
if type(person) in [str, unicode]: if type(person) in [str, unicode]:
person = self.dbase.get_person_from_handle(person) person = self.dbase.get_person_from_handle(person)
return self.__event_date(person, gen.lib.Person.get_death_ref) return self.__event_date(person, Person.get_death_ref)
def death_date_obj(self, person): def death_date_obj(self, person):
""" """
@ -569,7 +570,7 @@ class SimpleAccess(object):
""" """
if type(person) in [str, unicode]: if type(person) in [str, unicode]:
person = self.dbase.get_person_from_handle(person) person = self.dbase.get_person_from_handle(person)
return self.__event_date_obj(person, gen.lib.Person.get_death_ref) return self.__event_date_obj(person, Person.get_death_ref)
def death_or_fallback(self, person, get_event=False): def death_or_fallback(self, person, get_event=False):
""" """
@ -588,7 +589,7 @@ class SimpleAccess(object):
elif event: elif event:
return event.date return event.date
else: else:
return gen.lib.Date() return Date()
def death_place(self, person): def death_place(self, person):
""" """
@ -601,7 +602,7 @@ class SimpleAccess(object):
""" """
if type(person) in [str, unicode]: if type(person) in [str, unicode]:
person = self.dbase.get_person_from_handle(person) person = self.dbase.get_person_from_handle(person)
return self.__event_place(person, gen.lib.Person.get_death_ref) return self.__event_place(person, Person.get_death_ref)
def event_place(self, event): def event_place(self, event):
""" """
@ -612,7 +613,7 @@ class SimpleAccess(object):
@return: Returns a string indicating the place of the event @return: Returns a string indicating the place of the event
@rtype: unicode @rtype: unicode
""" """
assert(isinstance(event, (gen.lib.Event, NoneType))) assert(isinstance(event, (Event, NoneType)))
if event: if event:
place_handle = event.get_place_handle() place_handle = event.get_place_handle()
@ -630,7 +631,7 @@ class SimpleAccess(object):
@rtype: unicode @rtype: unicode
""" """
if date_obj: if date_obj:
return gen.datehandler.displayer.display(date_obj) return displayer.display(date_obj)
else: else:
return u'' return u''
@ -643,10 +644,10 @@ class SimpleAccess(object):
@return: Returns a string indicating the date of the event @return: Returns a string indicating the date of the event
@rtype: unicode @rtype: unicode
""" """
assert(isinstance(event, (gen.lib.Event, NoneType))) assert(isinstance(event, (Event, NoneType)))
date_obj = event.get_date_object() date_obj = event.get_date_object()
if date_obj: if date_obj:
return gen.datehandler.displayer.display(date_obj) return displayer.display(date_obj)
else: else:
return u'' return u''
@ -659,7 +660,7 @@ class SimpleAccess(object):
@return: Returns a string indicating the date of the event @return: Returns a string indicating the date of the event
@rtype: unicode @rtype: unicode
""" """
assert(isinstance(event, (gen.lib.Event, NoneType))) assert(isinstance(event, (Event, NoneType)))
if event: if event:
return event.get_date_object() return event.get_date_object()
@ -672,7 +673,7 @@ class SimpleAccess(object):
@return: Returns a string indicating the type of the event @return: Returns a string indicating the type of the event
@rtype: unicode @rtype: unicode
""" """
assert(isinstance(event, (gen.lib.Event, NoneType))) assert(isinstance(event, (Event, NoneType)))
if event: if event:
return str(event.get_type()) return str(event.get_type())
else: else:
@ -691,7 +692,7 @@ class SimpleAccess(object):
@return: list of events associated with the object @return: list of events associated with the object
@rtype: list @rtype: list
""" """
assert(isinstance(obj, (gen.lib.Person, gen.lib.Family, NoneType))) assert(isinstance(obj, (Person, Family, NoneType)))
assert(isinstance(restrict, list) or restrict is None) assert(isinstance(restrict, list) or restrict is None)
if obj: if obj:
@ -716,7 +717,7 @@ class SimpleAccess(object):
@return: list of events associated with the object @return: list of events associated with the object
@rtype: list @rtype: list
""" """
assert(isinstance(obj, (gen.lib.Person, gen.lib.Family, gen.lib.Event, NoneType))) assert(isinstance(obj, (Person, Family, Event, NoneType)))
if obj: if obj:
handles = [ ref.ref for ref in obj.get_source_references() ] handles = [ ref.ref for ref in obj.get_source_references() ]
@ -736,7 +737,7 @@ class SimpleAccess(object):
""" """
if type(person) in [str, unicode]: if type(person) in [str, unicode]:
person = self.dbase.get_person_from_handle(person) person = self.dbase.get_person_from_handle(person)
assert(isinstance(person, (gen.lib.Person, NoneType))) assert(isinstance(person, (Person, NoneType)))
if person: if person:
return [ self.dbase.get_family_from_handle(handle) return [ self.dbase.get_family_from_handle(handle)
@ -755,7 +756,7 @@ class SimpleAccess(object):
""" """
if type(person) in [str, unicode]: if type(person) in [str, unicode]:
person = self.dbase.get_person_from_handle(person) person = self.dbase.get_person_from_handle(person)
assert(isinstance(person, (gen.lib.Person, NoneType))) assert(isinstance(person, (Person, NoneType)))
if person: if person:
return [ self.dbase.get_family_from_handle(handle) return [ self.dbase.get_family_from_handle(handle)
@ -842,7 +843,7 @@ class SimpleAccess(object):
@return: title of the source @return: title of the source
@rtype: unicode @rtype: unicode
""" """
assert(isinstance(source, (gen.lib.Source, NoneType))) assert(isinstance(source, (Source, NoneType)))
if source: if source:
return source.get_title() return source.get_title()
return u'' return u''
@ -856,7 +857,7 @@ class SimpleAccess(object):
@return: title of the citation @return: title of the citation
@rtype: unicode @rtype: unicode
""" """
assert(isinstance(citation, (gen.lib.Citation, NoneType))) assert(isinstance(citation, (Citation, NoneType)))
if citation: if citation:
return citation.get_page() return citation.get_page()
return u'' return u''
@ -870,7 +871,7 @@ class SimpleAccess(object):
@return: author of the source @return: author of the source
@rtype: unicode @rtype: unicode
""" """
assert(isinstance(source, (gen.lib.Source, NoneType))) assert(isinstance(source, (Source, NoneType)))
if source: if source:
return source.get_author() return source.get_author()
return u'' return u''
@ -899,40 +900,40 @@ class SimpleAccess(object):
obj = self.dbase.get_table_metadata(object_class)\ obj = self.dbase.get_table_metadata(object_class)\
[prop + "_func"](value) [prop + "_func"](value)
if obj: if obj:
if isinstance(obj, gen.lib.Person): if isinstance(obj, Person):
return "%s: %s [%s]" % (_(object_class), return "%s: %s [%s]" % (_(object_class),
self.name(obj), self.name(obj),
self.gid(obj)) self.gid(obj))
elif isinstance(obj, gen.lib.Event): elif isinstance(obj, Event):
return "%s: %s [%s]" % (_(object_class), return "%s: %s [%s]" % (_(object_class),
self.event_type(obj), self.event_type(obj),
self.gid(obj)) self.gid(obj))
elif isinstance(obj, gen.lib.Family): elif isinstance(obj, Family):
return "%s: %s/%s [%s]" % (_(object_class), return "%s: %s/%s [%s]" % (_(object_class),
self.name(self.mother(obj)), self.name(self.mother(obj)),
self.name(self.father(obj)), self.name(self.father(obj)),
self.gid(obj)) self.gid(obj))
elif isinstance(obj, gen.lib.MediaObject): elif isinstance(obj, MediaObject):
return "%s: %s [%s]" % (_(object_class), return "%s: %s [%s]" % (_(object_class),
obj.desc, obj.desc,
self.gid(obj)) self.gid(obj))
elif isinstance(obj, gen.lib.Source): elif isinstance(obj, Source):
return "%s: %s [%s]" % (_(object_class), return "%s: %s [%s]" % (_(object_class),
self.title(obj), self.title(obj),
self.gid(obj)) self.gid(obj))
elif isinstance(obj, gen.lib.Citation): elif isinstance(obj, Citation):
return "%s: [%s]" % (_(object_class), return "%s: [%s]" % (_(object_class),
self.gid(obj)) self.gid(obj))
elif isinstance(obj, gen.lib.Place): elif isinstance(obj, Place):
return "%s: %s [%s]" % (_(object_class), return "%s: %s [%s]" % (_(object_class),
place_name(self.dbase, place_name(self.dbase,
obj.handle), obj.handle),
self.gid(obj)) self.gid(obj))
elif isinstance(obj, gen.lib.Repository): elif isinstance(obj, Repository):
return "%s: %s [%s]" % (_(object_class), return "%s: %s [%s]" % (_(object_class),
obj.type, obj.type,
self.gid(obj)) self.gid(obj))
elif isinstance(obj, gen.lib.Note): elif isinstance(obj, Note):
return "%s: %s [%s]" % (_(object_class), return "%s: %s [%s]" % (_(object_class),
obj.type, obj.type,
self.gid(obj)) self.gid(obj))
@ -947,11 +948,11 @@ class SimpleAccess(object):
""" """
Given a object, return a string describing the object. Given a object, return a string describing the object.
""" """
if isinstance(obj, gen.lib.Person): if isinstance(obj, Person):
return self.name(obj) return self.name(obj)
elif isinstance(obj, gen.lib.Event): elif isinstance(obj, Event):
return self.event_type(obj) return self.event_type(obj)
elif isinstance(obj, gen.lib.Family): elif isinstance(obj, Family):
father = self.father(obj) father = self.father(obj)
mother = self.mother(obj) mother = self.mother(obj)
if father: if father:
@ -963,17 +964,17 @@ class SimpleAccess(object):
else: else:
mother_text = _("Unknown mother") mother_text = _("Unknown mother")
return "%s and %s" % (mother_text, father_text) return "%s and %s" % (mother_text, father_text)
elif isinstance(obj, gen.lib.MediaObject): elif isinstance(obj, MediaObject):
return obj.desc return obj.desc
elif isinstance(obj, gen.lib.Citation): elif isinstance(obj, Citation):
return obj.gramps_id return obj.gramps_id
elif isinstance(obj, gen.lib.Source): elif isinstance(obj, Source):
return self.title(obj) return self.title(obj)
elif isinstance(obj, gen.lib.Place): elif isinstance(obj, Place):
return place_name(self.dbase, obj.handle) return place_name(self.dbase, obj.handle)
elif isinstance(obj, gen.lib.Repository): elif isinstance(obj, Repository):
return obj.gramps_id return obj.gramps_id
elif isinstance(obj, gen.lib.Note): elif isinstance(obj, Note):
return obj.gramps_id return obj.gramps_id
elif obj is None: elif obj is None:
return "" return ""

View File

@ -28,9 +28,10 @@ Provide a simplified table creation interface
import cgi import cgi
from gen.ggettext import sgettext as _ from gen.ggettext import sgettext as _
import gen.lib from ..lib import (Person, Family, Event, Source, Place, Citation,
from gen.config import config Repository, MediaObject, Note, Date, Span)
import gen.datehandler from ..config import config
from ..datehandler import displayer
class SimpleTable(object): class SimpleTable(object):
""" """
@ -108,44 +109,44 @@ class SimpleTable(object):
elif isinstance(item, (int, float, long)): elif isinstance(item, (int, float, long)):
retval.append(item) retval.append(item)
self.row_sort_val(col, item) self.row_sort_val(col, item)
elif isinstance(item, gen.lib.Person): elif isinstance(item, Person):
retval.append(self.access.describe(item)) retval.append(self.access.describe(item))
if (self._link_col == col or link is None): if (self._link_col == col or link is None):
link = ('Person', item.handle) link = ('Person', item.handle)
elif isinstance(item, gen.lib.Family): elif isinstance(item, Family):
retval.append(self.access.describe(item)) retval.append(self.access.describe(item))
if (self._link_col == col or link is None): if (self._link_col == col or link is None):
link = ('Family', item.handle) link = ('Family', item.handle)
elif isinstance(item, gen.lib.Citation): elif isinstance(item, Citation):
retval.append(self.access.describe(item)) retval.append(self.access.describe(item))
if (self._link_col == col or link is None): if (self._link_col == col or link is None):
link = ('Citation', item.handle) link = ('Citation', item.handle)
elif isinstance(item, gen.lib.Source): elif isinstance(item, Source):
retval.append(self.access.describe(item)) retval.append(self.access.describe(item))
if (self._link_col == col or link is None): if (self._link_col == col or link is None):
link = ('Source', item.handle) link = ('Source', item.handle)
elif isinstance(item, gen.lib.Event): elif isinstance(item, Event):
retval.append(self.access.describe(item)) retval.append(self.access.describe(item))
if (self._link_col == col or link is None): if (self._link_col == col or link is None):
link = ('Event', item.handle) link = ('Event', item.handle)
elif isinstance(item, gen.lib.MediaObject): elif isinstance(item, MediaObject):
retval.append(self.access.describe(item)) retval.append(self.access.describe(item))
if (self._link_col == col or link is None): if (self._link_col == col or link is None):
link = ('Media', item.handle) link = ('Media', item.handle)
elif isinstance(item, gen.lib.Place): elif isinstance(item, Place):
retval.append(self.access.describe(item)) retval.append(self.access.describe(item))
if (self._link_col == col or link is None): if (self._link_col == col or link is None):
link = ('Place', item.handle) link = ('Place', item.handle)
elif isinstance(item, gen.lib.Repository): elif isinstance(item, Repository):
retval.append(self.access.describe(item)) retval.append(self.access.describe(item))
if (self._link_col == col or link is None): if (self._link_col == col or link is None):
link = ('Repository', item.handle) link = ('Repository', item.handle)
elif isinstance(item, gen.lib.Note): elif isinstance(item, Note):
retval.append(self.access.describe(item)) retval.append(self.access.describe(item))
if (self._link_col == col or link is None): if (self._link_col == col or link is None):
link = ('Note', item.handle) link = ('Note', item.handle)
elif isinstance(item, gen.lib.Date): elif isinstance(item, Date):
text = gen.datehandler.displayer.display(item) text = displayer.display(item)
retval.append(text) retval.append(text)
if item.get_valid(): if item.get_valid():
if item.format: if item.format:
@ -161,7 +162,7 @@ class SimpleTable(object):
invalid_date_format % cgi.escape(text)) invalid_date_format % cgi.escape(text))
if (self._link_col == col or link is None): if (self._link_col == col or link is None):
link = ('Date', item) link = ('Date', item)
elif isinstance(item, gen.lib.Span): elif isinstance(item, Span):
text = str(item) text = str(item)
retval.append(text) retval.append(text)
self.row_sort_val(col, item) self.row_sort_val(col, item)

View File

@ -31,8 +31,8 @@ Configuration based utilities
# Gramps modules # Gramps modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import gen.lib from ..lib import Researcher
from gen.config import config from ..config import config
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -53,7 +53,7 @@ def get_researcher():
phone = config.get('researcher.researcher-phone') phone = config.get('researcher.researcher-phone')
email = config.get('researcher.researcher-email') email = config.get('researcher.researcher-email')
owner = gen.lib.Researcher() owner = Researcher()
owner.set_name(name) owner.set_name(name)
owner.set_address(address) owner.set_address(address)
owner.set_locality(locality) owner.set_locality(locality)

View File

@ -37,11 +37,11 @@ from cgi import escape
# Gramps modules # Gramps modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import gen.lib from ..lib import EventType
import gen.datehandler from ..datehandler import get_date
from gen.display.name import displayer as name_displayer from ..display.name import displayer as name_displayer
from gen.utils.db import (get_birth_or_fallback, get_death_or_fallback, from .db import (get_birth_or_fallback, get_death_or_fallback,
get_marriage_or_fallback) get_marriage_or_fallback)
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -73,19 +73,19 @@ class FormattingHelper(object):
text = "" text = ""
marriage = get_marriage_or_fallback(self.dbstate.db, family) marriage = get_marriage_or_fallback(self.dbstate.db, family)
if marriage and use_markup and marriage.get_type() != gen.lib.EventType.MARRIAGE: if marriage and use_markup and marriage.get_type() != EventType.MARRIAGE:
mdate = "<i>%s %s</i>" % (marriage.get_type().get_abbreviation(), mdate = "<i>%s %s</i>" % (marriage.get_type().get_abbreviation(),
escape(gen.datehandler.get_date(marriage))) escape(get_date(marriage)))
mplace = "<i>%s</i>" % escape(self.get_place_name(marriage.get_place_handle())) mplace = "<i>%s</i>" % escape(self.get_place_name(marriage.get_place_handle()))
name = "<i>%s</i>" % str(marriage.get_type()) name = "<i>%s</i>" % str(marriage.get_type())
elif marriage and use_markup: elif marriage and use_markup:
mdate = "%s %s" % (marriage.get_type().get_abbreviation(), mdate = "%s %s" % (marriage.get_type().get_abbreviation(),
escape(gen.datehandler.get_date(marriage))) escape(get_date(marriage)))
mplace = escape(self.get_place_name(marriage.get_place_handle())) mplace = escape(self.get_place_name(marriage.get_place_handle()))
name = str(marriage.get_type()) name = str(marriage.get_type())
elif marriage: elif marriage:
mdate = "%s %s" % (marriage.get_type().get_abbreviation(), mdate = "%s %s" % (marriage.get_type().get_abbreviation(),
gen.datehandler.get_date(marriage)) get_date(marriage))
mplace = self.get_place_name(marriage.get_place_handle()) mplace = self.get_place_name(marriage.get_place_handle())
name = str(marriage.get_type()) name = str(marriage.get_type())
else: else:
@ -149,31 +149,29 @@ class FormattingHelper(object):
text = name text = name
if line_count >= 3: if line_count >= 3:
birth = get_birth_or_fallback(self.dbstate.db, person) birth = get_birth_or_fallback(self.dbstate.db, person)
if birth and use_markup and birth.get_type() != \ if birth and use_markup and birth.get_type() != EventType.BIRTH:
gen.lib.EventType.BIRTH: bdate = "<i>%s</i>" % escape(get_date(birth))
bdate = "<i>%s</i>" % escape(gen.datehandler.get_date(birth))
bplace = "<i>%s</i>" % escape(self.get_place_name( bplace = "<i>%s</i>" % escape(self.get_place_name(
birth.get_place_handle())) birth.get_place_handle()))
elif birth and use_markup: elif birth and use_markup:
bdate = escape(gen.datehandler.get_date(birth)) bdate = escape(get_date(birth))
bplace = escape(self.get_place_name(birth.get_place_handle())) bplace = escape(self.get_place_name(birth.get_place_handle()))
elif birth: elif birth:
bdate = gen.datehandler.get_date(birth) bdate = get_date(birth)
bplace = self.get_place_name(birth.get_place_handle()) bplace = self.get_place_name(birth.get_place_handle())
else: else:
bdate = "" bdate = ""
bplace = "" bplace = ""
death = get_death_or_fallback(self.dbstate.db, person) death = get_death_or_fallback(self.dbstate.db, person)
if death and use_markup and death.get_type() != \ if death and use_markup and death.get_type() != EventType.DEATH:
gen.lib.EventType.DEATH: ddate = "<i>%s</i>" % escape(get_date(death))
ddate = "<i>%s</i>" % escape(gen.datehandler.get_date(death))
dplace = "<i>%s</i>" % escape(self.get_place_name( dplace = "<i>%s</i>" % escape(self.get_place_name(
death.get_place_handle())) death.get_place_handle()))
elif death and use_markup: elif death and use_markup:
ddate = escape(gen.datehandler.get_date(death)) ddate = escape(get_date(death))
dplace = escape(self.get_place_name(death.get_place_handle())) dplace = escape(self.get_place_name(death.get_place_handle()))
elif death: elif death:
ddate = gen.datehandler.get_date(death) ddate = get_date(death)
dplace = self.get_place_name(death.get_place_handle()) dplace = self.get_place_name(death.get_place_handle())
else: else:
ddate = "" ddate = ""

View File

@ -31,8 +31,8 @@ String mappings for constants
# Gramps modules # Gramps modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import gen.lib from ..lib import Person, Citation, FamilyRelType
from gen.ggettext import sgettext as _ from ..ggettext import sgettext as _
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -40,32 +40,32 @@ from gen.ggettext import sgettext as _
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
gender = { gender = {
gen.lib.Person.MALE : _("male"), Person.MALE : _("male"),
gen.lib.Person.FEMALE : _("female"), Person.FEMALE : _("female"),
gen.lib.Person.UNKNOWN : _("gender|unknown"), Person.UNKNOWN : _("gender|unknown"),
} }
def format_gender( type): def format_gender( type):
return gender.get(type[0], _("Invalid")) return gender.get(type[0], _("Invalid"))
confidence = { confidence = {
gen.lib.Citation.CONF_VERY_HIGH : _("Very High"), Citation.CONF_VERY_HIGH : _("Very High"),
gen.lib.Citation.CONF_HIGH : _("High"), Citation.CONF_HIGH : _("High"),
gen.lib.Citation.CONF_NORMAL : _("Normal"), Citation.CONF_NORMAL : _("Normal"),
gen.lib.Citation.CONF_LOW : _("Low"), Citation.CONF_LOW : _("Low"),
gen.lib.Citation.CONF_VERY_LOW : _("Very Low"), Citation.CONF_VERY_LOW : _("Very Low"),
} }
family_rel_descriptions = { family_rel_descriptions = {
gen.lib.FamilyRelType.MARRIED : _("A legal or common-law relationship " FamilyRelType.MARRIED : _("A legal or common-law relationship "
"between a husband and wife"), "between a husband and wife"),
gen.lib.FamilyRelType.UNMARRIED : _("No legal or common-law relationship " FamilyRelType.UNMARRIED : _("No legal or common-law relationship "
"between man and woman"), "between man and woman"),
gen.lib.FamilyRelType.CIVIL_UNION : _("An established relationship between " FamilyRelType.CIVIL_UNION : _("An established relationship between "
"members of the same sex"), "members of the same sex"),
gen.lib.FamilyRelType.UNKNOWN : _("Unknown relationship between a man " FamilyRelType.UNKNOWN : _("Unknown relationship between a man "
"and woman"), "and woman"),
gen.lib.FamilyRelType.CUSTOM : _("An unspecified relationship between " FamilyRelType.CUSTOM : _("An unspecified relationship between "
"a man and woman"), "a man and woman"),
} }

View File

@ -38,10 +38,14 @@ import time
# Gramps modules # Gramps modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import gen.lib from ..lib import (Person, Surname, Name, NameType, Family, FamilyRelType,
from gen.utils.id import create_id Event, EventType, Source, Place, Citation,
from gen.const import IMAGE_DIR Repository, RepositoryType, MediaObject, Note, NoteType,
from gen.ggettext import sgettext as _ StyledText, StyledTextTag, StyledTextTagType, Tag,
ChildRef, ChildRefType)
from id import create_id
from ..const import IMAGE_DIR
from ..ggettext import sgettext as _
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -86,19 +90,19 @@ def make_unknown(class_arg, explanation, class_func, commit_func, transaction,
""" """
retval = [] retval = []
obj = class_func(class_arg) obj = class_func(class_arg)
if isinstance(obj, gen.lib.Person): if isinstance(obj, Person):
surname = gen.lib.Surname() surname = Surname()
surname.set_surname('Unknown') surname.set_surname('Unknown')
name = gen.lib.Name() name = Name()
name.add_surname(surname) name.add_surname(surname)
name.set_type(gen.lib.NameType.UNKNOWN) name.set_type(NameType.UNKNOWN)
obj.set_primary_name(name) obj.set_primary_name(name)
elif isinstance(obj, gen.lib.Family): elif isinstance(obj, Family):
obj.set_relationship(gen.lib.FamilyRelType.UNKNOWN) obj.set_relationship(FamilyRelType.UNKNOWN)
handle = obj.handle handle = obj.handle
if getattr(argv['db'].transaction, 'no_magic', False): if getattr(argv['db'].transaction, 'no_magic', False):
backlinks = argv['db'].find_backlink_handles( backlinks = argv['db'].find_backlink_handles(
handle, [gen.lib.Person.__name__]) handle, [Person.__name__])
for dummy, person_handle in backlinks: for dummy, person_handle in backlinks:
person = argv['db'].get_person_from_handle(person_handle) person = argv['db'].get_person_from_handle(person_handle)
add_personref_to_family(obj, person) add_personref_to_family(obj, person)
@ -106,16 +110,16 @@ def make_unknown(class_arg, explanation, class_func, commit_func, transaction,
for person in argv['db'].iter_people(): for person in argv['db'].iter_people():
if person._has_handle_reference('Family', handle): if person._has_handle_reference('Family', handle):
add_personref_to_family(obj, person) add_personref_to_family(obj, person)
elif isinstance(obj, gen.lib.Event): elif isinstance(obj, Event):
if 'type' in argv: if 'type' in argv:
obj.set_type(argv['type']) obj.set_type(argv['type'])
else: else:
obj.set_type(gen.lib.EventType.UNKNOWN) obj.set_type(EventType.UNKNOWN)
elif isinstance(obj, gen.lib.Place): elif isinstance(obj, Place):
obj.set_title(_('Unknown')) obj.set_title(_('Unknown'))
elif isinstance(obj, gen.lib.Source): elif isinstance(obj, Source):
obj.set_title(_('Unknown')) obj.set_title(_('Unknown'))
elif isinstance(obj, gen.lib.Citation): elif isinstance(obj, Citation):
#TODO create a new source for every citation? #TODO create a new source for every citation?
obj2 = argv['source_class_func'](argv['source_class_arg']) obj2 = argv['source_class_func'](argv['source_class_arg'])
obj2.set_title(_('Unknown')) obj2.set_title(_('Unknown'))
@ -123,23 +127,23 @@ def make_unknown(class_arg, explanation, class_func, commit_func, transaction,
argv['source_commit_func'](obj2, transaction, time.time()) argv['source_commit_func'](obj2, transaction, time.time())
retval.append(obj2) retval.append(obj2)
obj.set_reference_handle(obj2.handle) obj.set_reference_handle(obj2.handle)
elif isinstance(obj, gen.lib.Repository): elif isinstance(obj, Repository):
obj.set_name(_('Unknown')) obj.set_name(_('Unknown'))
obj.set_type(gen.lib.RepositoryType.UNKNOWN) obj.set_type(RepositoryType.UNKNOWN)
elif isinstance(obj, gen.lib.MediaObject): elif isinstance(obj, MediaObject):
obj.set_path(os.path.join(IMAGE_DIR, "image-missing.png")) obj.set_path(os.path.join(IMAGE_DIR, "image-missing.png"))
obj.set_mime_type('image/png') obj.set_mime_type('image/png')
obj.set_description(_('Unknown')) obj.set_description(_('Unknown'))
elif isinstance(obj, gen.lib.Note): elif isinstance(obj, Note):
obj.set_type(gen.lib.NoteType.UNKNOWN); obj.set_type(NoteType.UNKNOWN);
text = _('Unknown, created to replace a missing note object.') text = _('Unknown, created to replace a missing note object.')
link_start = text.index(',') + 2 link_start = text.index(',') + 2
link_end = len(text) - 1 link_end = len(text) - 1
tag = gen.lib.StyledTextTag(gen.lib.StyledTextTagType.LINK, tag = StyledTextTag(StyledTextTagType.LINK,
'gramps://Note/handle/%s' % explanation, 'gramps://Note/handle/%s' % explanation,
[(link_start, link_end)]) [(link_start, link_end)])
obj.set_styledtext(gen.lib.StyledText(text, [tag])) obj.set_styledtext(StyledText(text, [tag]))
elif isinstance(obj, gen.lib.Tag): elif isinstance(obj, Tag):
if not hasattr(make_unknown, 'count'): if not hasattr(make_unknown, 'count'):
make_unknown.count = 1 #primitive static variable make_unknown.count = 1 #primitive static variable
obj.set_name(_("Unknown, was missing %(time)s (%(count)d)") % { obj.set_name(_("Unknown, was missing %(time)s (%(count)d)") % {
@ -161,7 +165,7 @@ def create_explanation_note(dbase):
those objects of type "Unknown" need a explanatory note. This funcion those objects of type "Unknown" need a explanatory note. This funcion
provides such a note for import methods. provides such a note for import methods.
""" """
note = gen.lib.Note( _('Objects referenced by this note ' note = Note( _('Objects referenced by this note '
'were missing in a file imported on %s.') % 'were missing in a file imported on %s.') %
time.strftime('%x %X', time.localtime())) time.strftime('%x %X', time.localtime()))
note.set_handle(create_id()) note.set_handle(create_id())
@ -177,18 +181,18 @@ def add_personref_to_family(family, person):
handle = family.handle handle = family.handle
person_handle = person.handle person_handle = person.handle
if handle in person.get_family_handle_list(): if handle in person.get_family_handle_list():
if ((person.get_gender() == gen.lib.Person.FEMALE) and if ((person.get_gender() == Person.FEMALE) and
(family.get_mother_handle() is None)): (family.get_mother_handle() is None)):
family.set_mother_handle(person_handle) family.set_mother_handle(person_handle)
else: else:
# This includes cases of gen.lib.Person.UNKNOWN # This includes cases of Person.UNKNOWN
if family.get_father_handle() is None: if family.get_father_handle() is None:
family.set_father_handle(person_handle) family.set_father_handle(person_handle)
else: else:
family.set_mother_handle(person_handle) family.set_mother_handle(person_handle)
if handle in person.get_parent_family_handle_list(): if handle in person.get_parent_family_handle_list():
childref = gen.lib.ChildRef() childref = ChildRef()
childref.set_reference_handle(person_handle) childref.set_reference_handle(person_handle)
childref.set_mother_relation(gen.lib.ChildRefType.UNKNOWN) childref.set_mother_relation(ChildRefType.UNKNOWN)
childref.set_father_relation(gen.lib.ChildRefType.UNKNOWN) childref.set_father_relation(ChildRefType.UNKNOWN)
family.add_child_ref(childref) family.add_child_ref(childref)