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

View File

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

View File

@ -196,8 +196,8 @@ class CommandLineTool(object):
person_id = self.options_dict['id']
self.person = self.database.get_person_from_gramps_id(person_id)
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" % (
person.get_gramps_id(),
name_displayer.display(person)))

View File

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

View File

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