Person.save() now also computes probably_alive (but only when computing cache, too)
This commit is contained in:
parent
e649e5514d
commit
4051984031
@ -612,6 +612,20 @@ class Person(PrimaryObject):
|
||||
def get_selection_string(self):
|
||||
return self.name_set.get(preferred=True).get_selection_string()
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
from gramps.webapp.utils import probably_alive
|
||||
if "save_cache" in kwargs:
|
||||
compute_probably_alive = kwargs["save_cache"]
|
||||
else:
|
||||
compute_probably_alive = True
|
||||
PrimaryObject.save(self, *args, **kwargs)
|
||||
# expensive! only do this if also saving cache
|
||||
if compute_probably_alive:
|
||||
pa = probably_alive(self.handle)
|
||||
if self.probably_alive != pa:
|
||||
self.probably_alive = pa
|
||||
PrimaryObject.save(self, *args, **kwargs)
|
||||
|
||||
class Family(PrimaryObject):
|
||||
father = models.ForeignKey('Person', related_name="father_ref",
|
||||
null=True, blank=True)
|
||||
|
@ -117,7 +117,6 @@ def recheck_birth_death_refs(person):
|
||||
role_type=get_type_from_name(EventRoleType, "Primary"),
|
||||
ref_object__event_type__val=EventType.DEATH).order_by("order")
|
||||
if events:
|
||||
person.probably_alive = False
|
||||
person.death = events[0].ref_object
|
||||
new_index = lookup_role_index(EventType.DEATH, all_events)
|
||||
if person.death_ref_index != new_index:
|
||||
@ -125,7 +124,6 @@ def recheck_birth_death_refs(person):
|
||||
else:
|
||||
person.death = None
|
||||
person.death_ref_index = -1
|
||||
person.probably_alive = True
|
||||
|
||||
def process_event(request, context, handle, act, add_to=None): # view, edit, save
|
||||
"""
|
||||
|
@ -417,9 +417,8 @@ def process_person(request, context, handle, act, add_to=None): # view, edit, sa
|
||||
# check if valid:
|
||||
if nf.is_valid() and pf.is_valid() and sf.is_valid() and logform.is_valid():
|
||||
# name.preferred and surname.primary get set False in the above is_valid()
|
||||
person.probably_alive = not bool(person.death)
|
||||
update_last_changed(person, request.user.username)
|
||||
person = pf.save()
|
||||
person = pf.save(save_cache=False)
|
||||
# Process data:
|
||||
name.person = person
|
||||
name = nf.save(commit=False)
|
||||
|
@ -1940,6 +1940,7 @@ class DjangoInterface(object):
|
||||
referenced events should be marked not public (public = False).
|
||||
|
||||
"""
|
||||
from gramps.webapp.utils import probably_alive
|
||||
if obj.__class__.__name__ == "Event":
|
||||
objref = self.EventRef
|
||||
elif obj.__class__.__name__ == "Person":
|
||||
@ -2040,3 +2041,21 @@ class DjangoInterface(object):
|
||||
count += 1
|
||||
callback(100 * (count/total if total else 0))
|
||||
|
||||
def update_probably_alive(self, callback=None):
|
||||
"""
|
||||
Call this to update primary_alive for people.
|
||||
"""
|
||||
from gramps.webapp.utils import probably_alive
|
||||
if not isinstance(callback, collections.Callable):
|
||||
callback = lambda percent: None # dummy
|
||||
callback(0)
|
||||
count = 0.0
|
||||
total = self.Person.all().count()
|
||||
for item in self.Person.all():
|
||||
pa = probably_alive(item.handle)
|
||||
if pa != item.probably_alive:
|
||||
print("Updating probably_alive")
|
||||
item.probably_alive = pa
|
||||
item.save()
|
||||
count += 1
|
||||
callback(100 * (count/total if total else 0))
|
||||
|
@ -152,7 +152,6 @@ def get_person_from_handle(db, handle):
|
||||
return None
|
||||
|
||||
def probably_alive(handle):
|
||||
return False
|
||||
person = db.get_person_from_handle(handle)
|
||||
return alive(person, db)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user