Exploit new iter_<objects> methods

svn: r13209
This commit is contained in:
Gerald Britton
2009-09-15 19:37:23 +00:00
parent eb8ef2152b
commit 4b77831f0f
5 changed files with 72 additions and 79 deletions

View File

@@ -1178,9 +1178,8 @@ class GeoView(HtmlView):
latitude = "" latitude = ""
longitude = "" longitude = ""
self.center = True self.center = True
for place_handle in dbstate.db.iter_place_handles():
place = dbstate.db.get_place_from_handle( place_handle) for place in dbstate.db.iter_places():
if place:
descr = place.get_title() descr = place.get_title()
descr1 = _("Id : %s") % place.gramps_id descr1 = _("Id : %s") % place.gramps_id
longitude = place.get_longitude() longitude = place.get_longitude()
@@ -1221,66 +1220,64 @@ class GeoView(HtmlView):
latitude = "" latitude = ""
longitude = "" longitude = ""
self.center = True self.center = True
for event_handle in dbstate.db.get_event_handles():
event = dbstate.db.get_event_from_handle( event_handle) for event in dbstate.db.iter_events():
if event: place_handle = event.get_place_handle()
place_handle = event.get_place_handle() eventdate = event.get_date_object()
eventdate = event.get_date_object() eventyear = eventdate.get_year()
eventyear = eventdate.get_year() descr1 = _("Id : %(id)s (%(year)s)") % {
descr1 = _("Id : %(id)s (%(year)s)") % { 'id' : event.gramps_id,
'id' : event.gramps_id, 'year' : eventyear}
'year' : eventyear} if place_handle:
if place_handle: place = dbstate.db.get_place_from_handle(place_handle)
place = dbstate.db.get_place_from_handle(place_handle) if place:
if place: longitude = place.get_longitude()
longitude = place.get_longitude() latitude = place.get_latitude()
latitude = place.get_latitude() latitude, longitude = conv_lat_lon(latitude, longitude,
latitude, longitude = conv_lat_lon(latitude, longitude, "D.D8")
"D.D8") city = place.get_main_location().get_city()
city = place.get_main_location().get_city() country = place.get_main_location().get_country()
country = place.get_main_location().get_country() descr2 = "%s; %s" % (city, country)
descr2 = "%s; %s" % (city, country) # place.get_longitude and place.get_latitude return
# place.get_longitude and place.get_latitude return # one string. We have coordinates when the two values
# one string. We have coordinates when the two values # contains non null string.
# contains non null string. if ( longitude and latitude ):
if ( longitude and latitude ): person_list = [
person_list = [ dbstate.db.get_person_from_handle(ref_handle)
dbstate.db.get_person_from_handle(ref_handle) for (ref_type, ref_handle) in
for (ref_type, ref_handle) in \ dbstate.db.find_backlink_handles(event.handle)
dbstate.db.find_backlink_handles( if ref_type == 'Person'
event_handle) ]
if ref_type == 'Person' if person_list:
] descr = "<br>"
if person_list: for person in person_list:
descr = "<br>" descr = ("%(description)s%(name)s<br>") % {
for person in person_list: 'description' : descr,
descr = ("%(description)s%(name)s<br>") % { 'name' : _nd.display(person)}
'description' : descr, #) % { 'eventtype': gen.lib.EventType(
'name' : _nd.display(person)} descr = ("%(eventtype)s;"+
#) % { 'eventtype': gen.lib.EventType( " %(place)s%(description)s"
descr = ("%(eventtype)s;"+ ) % { 'eventtype': gen.lib.EventType(
" %(place)s%(description)s" event.get_type()
) % { 'eventtype': gen.lib.EventType( ),
event.get_type() 'place': place.get_title(),
), 'description': descr}
'place': place.get_title(),
'description': descr}
else:
descr = ("%(eventtype)s; %(place)s<br>") % {
'eventtype': gen.lib.EventType(
event.get_type()
),
'place': place.get_title()}
self._append_to_places_list(descr1, descr,
descr,
latitude, longitude,
descr2, self.center,
eventyear)
self.center = False
else: else:
descr = place.get_title() descr = ("%(eventtype)s; %(place)s<br>") % {
self._append_to_places_without_coord( 'eventtype': gen.lib.EventType(
place.gramps_id, descr) event.get_type()
),
'place': place.get_title()}
self._append_to_places_list(descr1, descr,
descr,
latitude, longitude,
descr2, self.center,
eventyear)
self.center = False
else:
descr = place.get_title()
self._append_to_places_without_coord(
place.gramps_id, descr)
if self.center: if self.center:
mess = _("Cannot center the map. No location with coordinates.") mess = _("Cannot center the map. No location with coordinates.")
else: else:

View File

@@ -160,15 +160,13 @@ class HasTextMatchingSubstringOf(Rule):
def cache_repos(self): def cache_repos(self):
# search all matching repositories # search all matching repositories
for repo_handle in self.db.get_repository_handles(): for repo in self.db.iter_repositories():
repo = self.db.get_repository_from_handle(repo_handle)
if( self.match_object(repo)): if( self.match_object(repo)):
self.repo_map[repo_handle] = 1 self.repo_map[repo.handle] = 1
def cache_sources(self): def cache_sources(self):
# search all sources and match all referents of a matching source # search all sources and match all referents of a matching source
for source_handle in self.db.get_source_handles(): for source in self.db.iter_sources():
source = self.db.get_source_from_handle(source_handle)
match = self.match_object(source) match = self.match_object(source)
if not match: if not match:
for reporef in source.get_reporef_list(): for reporef in source.get_reporef_list():
@@ -177,7 +175,7 @@ class HasTextMatchingSubstringOf(Rule):
if match: if match:
(person_list,family_list,event_list,place_list,source_list, (person_list,family_list,event_list,place_list,source_list,
media_list,repo_list media_list,repo_list
) = get_source_referents(source_handle,self.db) ) = get_source_referents(source.handle,self.db)
for handle in person_list: for handle in person_list:
self.person_map[handle] = 1 self.person_map[handle] = 1
for handle in family_list: for handle in family_list:

View File

@@ -196,8 +196,8 @@ class CommandLineTool(object):
person_id = self.options_dict['id'] person_id = self.options_dict['id']
self.person = self.database.get_person_from_gramps_id(person_id) self.person = self.database.get_person_from_gramps_id(person_id)
id_list = [] id_list = []
for person_handle in self.database.get_person_handles():
person = self.database.get_person_from_handle(person_handle) for person in self.database.iter_people():
id_list.append("%s\t%s" % ( id_list.append("%s\t%s" % (
person.get_gramps_id(), person.get_gramps_id(),
name_displayer.display(person))) name_displayer.display(person)))

View File

@@ -81,12 +81,11 @@ class StatsGramplet(Gramplet):
notfound = [] notfound = []
pobjects = database.get_number_of_media_objects() pobjects = database.get_number_of_media_objects()
for photo_id in database.get_media_object_handles(): for photo in database.iter_media_objects():
photo = database.get_object_from_handle(photo_id)
fullname = media_path_full(database, photo.get_path()) fullname = media_path_full(database, photo.get_path())
try: try:
bytes += posixpath.getsize(fullname) bytes += posixpath.getsize(fullname)
except: except OSError:
notfound.append(photo.get_path()) notfound.append(photo.get_path())
for cnt, person in enumerate(personList): for cnt, person in enumerate(personList):
@@ -97,7 +96,7 @@ class StatsGramplet(Gramplet):
names = [person.get_primary_name()] + person.get_alternate_names() names = [person.get_primary_name()] + person.get_alternate_names()
for name in names: for name in names:
if name.get_first_name() == "" or name.get_group_name() == "": if (name.get_first_name() or name.get_group_name()) == "":
incomp_names += 1 incomp_names += 1
if name.get_group_name() not in namelist: if name.get_group_name() not in namelist:
namelist.append(name.get_group_name()) namelist.append(name.get_group_name())

View File

@@ -81,15 +81,14 @@ def run(database, document, main_event):
yeartab.columns(_("Date"), _("Type"), _("Place"), _("Reference")) yeartab.columns(_("Date"), _("Type"), _("Place"), _("Reference"))
histab.columns(_("Date"), _("Type"), _("Place"), _("Reference")) histab.columns(_("Date"), _("Type"), _("Place"), _("Reference"))
for event_handle in database.get_event_handles(): for event in database.iter_events():
event = database.get_event_from_handle(event_handle)
date = event.get_date_object() date = event.get_date_object()
if date.get_year() == 0: if date.get_year() == 0:
continue continue
if (date.get_year() == main_date.get_year() and if (date.get_year() == main_date.get_year() and
date.get_month() == main_date.get_month() and date.get_month() == main_date.get_month() and
date.get_day() == main_date.get_day()): date.get_day() == main_date.get_day()):
for (objclass, handle) in database.find_backlink_handles(event_handle): for (objclass, handle) in database.find_backlink_handles(event.handle):
ref = get_ref(database, objclass, handle) ref = get_ref(database, objclass, handle)
stab.row(date, stab.row(date,
sdb.event_type(event), sdb.event_type(event),
@@ -97,13 +96,13 @@ def run(database, document, main_event):
elif (date.get_month() == main_date.get_month() and elif (date.get_month() == main_date.get_month() and
date.get_day() == main_date.get_day() and date.get_day() == main_date.get_day() and
date.get_month() != 0): date.get_month() != 0):
for (objclass, handle) in database.find_backlink_handles(event_handle): for (objclass, handle) in database.find_backlink_handles(event.handle):
ref = get_ref(database, objclass, handle) ref = get_ref(database, objclass, handle)
histab.row(date, histab.row(date,
sdb.event_type(event), sdb.event_type(event),
sdb.event_place(event), ref) sdb.event_place(event), ref)
elif (date.get_year() == main_date.get_year()): elif (date.get_year() == main_date.get_year()):
for (objclass, handle) in database.find_backlink_handles(event_handle): for (objclass, handle) in database.find_backlink_handles(event.handle):
ref = get_ref(database, objclass, handle) ref = get_ref(database, objclass, handle)
yeartab.row(date, yeartab.row(date,
sdb.event_type(event), sdb.event_type(event),