diff --git a/src/web/dbdjango.py b/src/web/dbdjango.py index f94ff4685..9a9c8c258 100644 --- a/src/web/dbdjango.py +++ b/src/web/dbdjango.py @@ -26,6 +26,7 @@ # Gramps Modules # #------------------------------------------------------------------------ +import cPickle import web import gen from gen.db import DbReadBase, DbWriteBase @@ -161,27 +162,45 @@ class DbDjango(DbWriteBase, DbReadBase): obj.unserialize(self.dji.get_event(self.dji.Event.get(handle=handle))) return obj - def get_family_from_handle(self, handle): - obj = gen.lib.Family() - obj.unserialize(self.dji.get_family(self.dji.Family.get(handle=handle))) + def get_family_from_handle(self, handle): + #print "get_family_from_handle", handle + family = self.dji.Family.get(handle=handle) + obj = self.make_family(family) return obj def get_family_from_gramps_id(self, gramps_id): - obj = gen.lib.Family() + #print "get_family_from_id", gramps_id try: family = self.dji.Family.get(gramps_id=gramps_id) except: return None - obj.unserialize(self.dji.get_family(family)) + obj = self.make_family(family) return obj def get_person_from_handle(self, handle): + #print "get_person_from_handle", handle try: person = self.dji.Person.select_related().get(handle=handle) except: return None - data = self.dji.get_person(person) - obj = gen.lib.Person().unserialize(data) + return self.make_person(person) + + def make_family(self, family): + if family.cache: + data = cPickle.loads(str(family.cache)) + obj = gen.lib.Family.create(data) + else: + data = self.dji.get_family(family) + obj = gen.lib.Family.create(data) + return obj + + def make_person(self, person): + if person.cache: + data = cPickle.loads(str(person.cache)) + obj = gen.lib.Person.create(data) + else: + data = self.dji.get_person(person) + obj = gen.lib.Person.create(data) return obj def get_place_from_handle(self, handle): @@ -239,14 +258,10 @@ class DbDjango(DbWriteBase, DbReadBase): return (family.handle for family in self.dji.Family.all()) def get_person_from_gramps_id(self, gramps_id): - obj = gen.lib.Person() + #print "get_person_from_gramps_id", gramps_id match_list = self.dji.Person.filter(gramps_id=gramps_id) if match_list.count() > 0: - data = self.dji.get_person( - match_list[0] - ) - obj.unserialize(data) - return obj + return self.make_person(match_list[0]) else: return None diff --git a/src/web/grampsdb/models.py b/src/web/grampsdb/models.py index 38c7a3ff8..bcbe7967a 100644 --- a/src/web/grampsdb/models.py +++ b/src/web/grampsdb/models.py @@ -412,6 +412,7 @@ class PrimaryObject(models.Model): blank=True) # user edits private = models.BooleanField('private') #attributes = models.ManyToManyField("Attribute", blank=True, null=True) + cache = models.TextField(blank=True, null=True) def __unicode__(self): return "%s: %s" % (self.__class__.__name__, self.gramps_id) @@ -433,6 +434,9 @@ class Person(PrimaryObject): birth = models.ForeignKey("Event", related_name="birth", blank=True, null=True) death = models.ForeignKey("Event", related_name="death", blank=True, null=True) + birth_ref_index = models.IntegerField("Birth Reference Index", default=-1) + death_ref_index = models.IntegerField("Death Reference Index", default=-1) + tags = models.ManyToManyField('Tag', blank=True, null=True) # Others keys here: @@ -454,7 +458,7 @@ class Person(PrimaryObject): return str(self.get_primary_name()) def make_tag_list(self): - return [] + return tuple() class Family(PrimaryObject): father = models.ForeignKey('Person', related_name="father_ref", @@ -465,7 +469,7 @@ class Family(PrimaryObject): tags = models.ManyToManyField('Tag', blank=True, null=True) def make_tag_list(self): - return [] + return tuple() #lds_list = models.ManyToManyField('Lds', null=True, blank=True) @@ -526,7 +530,7 @@ class Media(DateObject, PrimaryObject): tags = models.ManyToManyField('Tag', blank=True, null=True) def make_tag_list(self): - return [] + return tuple() class Note(PrimaryObject): note_type = models.ForeignKey('NoteType') @@ -538,7 +542,7 @@ class Note(PrimaryObject): tags = models.ManyToManyField('Tag', blank=True, null=True) def make_tag_list(self): - return [] + return tuple() #--------------------------------------------------------------------------- # diff --git a/src/web/libdjango.py b/src/web/libdjango.py index 569536b82..b5dc21530 100644 --- a/src/web/libdjango.py +++ b/src/web/libdjango.py @@ -162,6 +162,17 @@ class DjangoInterface(object): object_type=obj_type) return map(self.pack_attribute, attribute_list) + def get_primary_name(self, person): + names = person.name_set.filter(preferred=True).order_by("order") + if len(names) > 0: + return gen.lib.Name.create(self.pack_name(names[0])) + else: + return gen.lib.Name() + + def get_alternate_names(self, person): + names = person.name_set.filter(preferred=False).order_by("order") + return [gen.lib.Name.create(self.pack_name(n)) for n in names] + def get_names(self, person, preferred): names = person.name_set.filter(preferred=preferred).order_by("order") if preferred: @@ -374,10 +385,9 @@ class DjangoInterface(object): pnote_list = self.get_note_list(person) person_ref_list = self.get_person_ref_list(person) # This looks up the events for the first EventType given: - death_ref_index = lookup_role_index(models.EventType.DEATH, - event_ref_list) - birth_ref_index = lookup_role_index(models.EventType.BIRTH, - event_ref_list) + death_ref_index = person.death_ref_index + birth_ref_index = person.birth_ref_index + return (str(person.handle), person.gramps_id, tuple(person.gender_type)[0], @@ -1093,14 +1103,19 @@ class DjangoInterface(object): object_id=person.id, object_type=obj_type, ref_object__event_type__val=models.EventType.BIRTH) + + all_events = self.get_event_ref_list(person) if events: person.birth = events[0].ref_object + person.birth_ref_index = lookup_role_index(models.EventType.BIRTH, all_events) + events = models.EventRef.objects.filter( object_id=person.id, object_type=obj_type, ref_object__event_type__val=models.EventType.DEATH) if events: person.death = events[0].ref_object + person.death_ref_index = lookup_role_index(models.EventType.DEATH, all_events) person.save() return person