diff --git a/src/data/templates/view_people.html b/src/data/templates/view_people.html
index 5da19a178..bb609c10b 100644
--- a/src/data/templates/view_people.html
+++ b/src/data/templates/view_people.html
@@ -11,25 +11,21 @@
ID |
Gender |
Birth Date |
-
-
Death Date |
-
{% for name in page.object_list %}
- {% get_person_from_handle db name.person.handle as person %}
- {% if person %}
- {{ forloop.counter|row_count:page }}
+ {% if name.person %}
+ | {{ forloop.counter|row_count:page }}
|
- {{person|make_name:user}}
+ | {{name|make_name:user}}
|
- [{{person.gramps_id}}] |
- {{person.gender_type}} |
- {{person|person_get_birth_date|nbsp}} |
- {{person|person_get_death_date|nbsp}} |
+ [{{name.person.gramps_id}}] |
+ {{name.person.gender_type}} |
+ {{name.person.birth}} |
+ {{name.person.death}} |
{% endif %}
{% endfor %}
diff --git a/src/plugins/export/ExportDjango.py b/src/plugins/export/ExportDjango.py
index 452b0dd84..e4a67bf85 100644
--- a/src/plugins/export/ExportDjango.py
+++ b/src/plugins/export/ExportDjango.py
@@ -49,7 +49,7 @@ log = logging.getLogger(".ExportDjango")
#
#------------------------------------------------------------------------
import ExportOptions
-from Utils import create_id
+from Utils import create_id, probably_alive
import const
import gen.lib
@@ -95,7 +95,10 @@ def export_all(database, filename, option_box=None, callback=None):
if step == 0:
dji.add_person(data)
elif step == 1:
- dji.add_person_detail(data)
+ djperson = dji.add_person_detail(data)
+ person = database.get_person_from_handle(person_handle)
+ djperson.probably_alive = probably_alive(person, database)
+ djperson.save()
count += 1
callback(100 * count/total)
diff --git a/src/web/djangodb.py b/src/web/djangodb.py
index 9171f8e7e..c1f9d6e97 100644
--- a/src/web/djangodb.py
+++ b/src/web/djangodb.py
@@ -86,9 +86,8 @@ class DjangoDb(DbReadBase, DbWriteBase):
return obj
def get_person_from_handle(self, handle):
- obj = gen.lib.Person()
- data = self.dji.get_person(self.dji.Person.get(handle=handle))
- obj.unserialize(data)
+ data = self.dji.get_person(self.dji.Person.select_related().get(handle=handle))
+ obj = gen.lib.Person.create(data)
return obj
def get_place_from_handle(self, handle):
@@ -114,6 +113,11 @@ class DjangoDb(DbReadBase, DbWriteBase):
obj.unserialize(self.dji.get_note(self.dji.Note.get(handle=handle)))
return obj
+ def get_object_from_handle(self, handle):
+ obj = gen.lib.MediaObject()
+ obj.unserialize(self.dji.get_media(self.dji.Media.get(handle=handle)))
+ return obj
+
def get_person_handles(self):
return [person.handle for person in self.dji.Person.all()]
diff --git a/src/web/grampsdb/fixtures/initial_data.json b/src/web/grampsdb/fixtures/initial_data.json
index ced879d91..f0d8cef08 100644
--- a/src/web/grampsdb/fixtures/initial_data.json
+++ b/src/web/grampsdb/fixtures/initial_data.json
@@ -18,7 +18,7 @@
"setting" : "db_created" ,
"description" : "database creation date/time" ,
"value_type" : "str" ,
- "value" : "2009-12-26 08:01"
+ "value" : "2009-12-28 22:19"
}
},
{
diff --git a/src/web/grampsdb/models.py b/src/web/grampsdb/models.py
index 6bb5a2576..d4eb52db5 100644
--- a/src/web/grampsdb/models.py
+++ b/src/web/grampsdb/models.py
@@ -392,6 +392,7 @@ class Person(PrimaryObject):
The model for the person object
"""
gender_type = models.ForeignKey('GenderType')
+ probably_alive = models.BooleanField("Probably alive")
families = models.ManyToManyField('Family', blank=True, null=True)
parent_families = models.ManyToManyField('Family',
related_name="parent_families",
@@ -400,8 +401,8 @@ class Person(PrimaryObject):
references = generic.GenericRelation('PersonRef', related_name="refs",
content_type_field="object_type",
object_id_field="object_id")
- #lds_list = models.ManyToManyField('Lds', null=True, blank=True)
- #url_list = models.ManyToManyField('Url', null=True, blank=True)
+ birth = models.ForeignKey("Event", related_name="birth", null=True)
+ death = models.ForeignKey("Event", related_name="death", null=True)
# Others keys here:
# .name_set
@@ -806,177 +807,3 @@ def get_tables(*categories):
return [pair for pair in TABLES if (pair[0] in categories) or
("all" in categories) and pair[0] != "abstract"]
-#---------------------------------------------------------------------------
-#
-# Testing Functions
-#
-#---------------------------------------------------------------------------
-
-## Primary:
-
-def test_Person():
- m = get_default_type(MarkerType)
- p = Person(handle=create_id(), marker_type=m)
- p.gender_type = GenderType.objects.get(id=1)
- p.gramps_id = "P%05d" % (Person.objects.count() + 1)
- p.save()
- return p
-
-def test_Family():
- m = get_default_type(MarkerType)
- frt = FamilyRelType.objects.get(id=1)
- f = Family(handle=create_id(), marker_type=m, family_rel_type=frt)
- f.gramps_id = "F%05d" % (Family.objects.count() + 1)
- f.save()
- return f
-
-def test_Source():
- m = get_default_type(MarkerType)
- s = Source(handle=create_id(), marker_type=m)
- s.save()
- s.gramps_id = "S%05d" % (Source.objects.count() + 1)
- s.save()
- return s
-
-def test_Event():
- m = get_default_type(MarkerType)
- et = get_default_type(EventType)
- e = Event(handle=create_id(), marker_type=m, event_type=et)
- e.set_date_from_gdate( GDate() )
- e.gramps_id = "E%05d" % (Event.objects.count() + 1)
- e.save()
- return e
-
-def test_Repository():
- m = get_default_type(MarkerType)
- rt = get_default_type(RepositoryType)
- r = Repository(handle=create_id(), marker_type=m, repository_type=rt)
- r.gramps_id = "R%05d" % (Repository.objects.count() + 1)
- r.save()
- return r
-
-def test_Place():
- m = get_default_type(MarkerType)
- p = Place(handle=create_id(), marker_type=m)
- p.gramps_id = "L%05d" % (Place.objects.count() + 1)
- p.save()
- return p
-
-def test_Media():
- m = get_default_type(MarkerType)
- media = Media(handle=create_id(), marker_type=m)
- media.set_date_from_gdate( GDate() )
- media.save()
- media.gramps_id = "M%05d" % (Media.objects.count() + 1)
- return media
-
-def test_Note():
- m = get_default_type(MarkerType)
- note_type = get_default_type(NoteType)
- note = Note(handle=create_id(), marker_type=m, note_type=note_type,
- preformatted=False)
- note.gramps_id = "N%05d" % (Note.objects.count() + 1)
- note.save()
- return note
-
-def test_Family_with_children():
- father = test_Person()
- fname = test_Name(father, "Blank", "Lowell")
- mother = test_Person()
- mname = test_Name(mother, "Bamford", "Norma")
- family_rel_type = get_default_type(FamilyRelType)
- m = get_default_type(MarkerType)
- f = Family(handle=create_id(), father=father, mother=mother,
- family_rel_type=family_rel_type, marker_type=m)
- f.save()
- for names in [("Blank", "Doug"), ("Blank", "Laura"), ("Blank", "David")]:
- p = test_Person()
- n = test_Name(p, names[0], names[1])
- p.families.add(f)
- f.save()
- return f
-
-## Secondary:
-
-def test_Name(person=None, surname=None, first=None):
- if not person: # Testing
- person = test_Person()
- m = get_default_type(MarkerType)
- n = Name()
- if first:
- n.first_name = first
- if surname:
- n.surname = surname
- n.set_date_from_gdate(Today())
- n.name_type = get_default_type(NameType)
- n.order = 1
- n.sort_as = 1
- n.display_as = 1
- person.save()
- n.person = person
- n.save()
- return n
-
-def test_Markup(note=None):
- if not note:
- note = test_Note()
- markup = Markup(note=note,
- markup_type=get_type(MarkupType,
- (1, "Testing"),
- get_or_create=True))
- markup.order = 1
- markup.save()
- return markup
-
-def test_Lds(place=None, famc=None):
- if not place:
- place = test_Place()
- if not famc:
- famc = test_Family()
- lds = Lds(lds_type=get_default_type(LdsType), status=get_default_type(LdsStatus),
- place=place, famc=famc, order=1)
- lds.set_date_from_gdate(Today())
- lds.save()
- return lds
-
-def test_NoteRef():
- note = test_Note()
- person = test_Person()
- note_ref = NoteRef(referenced_by=person, ref_object=note)
- note_ref.order = 1
- note_ref.save()
- family = test_Family()
- note_ref = NoteRef(referenced_by=family, ref_object=note)
- note_ref.order = 1
- note_ref.save()
- return note_ref
-
-def test_SourceRef():
- note = test_Note()
- source = test_Source()
- source_ref = SourceRef(referenced_by=note, ref_object=source, confidence=4)
- source_ref.set_date_from_gdate(Today())
- source_ref.order = 1
- source_ref.save()
- return source_ref
-
-#---------------------------------------------------------------------------
-#
-# Testing
-#
-#---------------------------------------------------------------------------
-
-def main():
- for test_Item in [test_Person, test_Family, test_Family_with_children,
- test_Source, test_Event,
- test_Repository, test_Place, test_Media, test_Note,
- test_Name, test_Markup, test_Lds, test_NoteRef,
- test_SourceRef]:
- print "testing:", test_Item.__name__
- obj = test_Item()
-
- sourceref = test_SourceRef()
- print sourceref.ref_object.references.all()
-
-if __name__ == "__main__":
- main()
diff --git a/src/web/grampsdb/views.py b/src/web/grampsdb/views.py
index 71003354e..c7e60b1f4 100644
--- a/src/web/grampsdb/views.py
+++ b/src/web/grampsdb/views.py
@@ -269,12 +269,12 @@ def view_detail(request, view, handle, action="view"):
def get_gramps_db(request):
dbase = DjangoDb()
- if request.user.is_authenticated():
- private_filter=False
- living_filter=False
- else:
- private_filter=True
- living_filter=True
+ #if request.user.is_authenticated():
+ private_filter=False
+ living_filter=False
+ #else:
+ # private_filter=True
+ # living_filter=True
# If the private flag is set, apply the PrivateProxyDb
if private_filter:
dbase = gen.proxy.PrivateProxyDb(dbase)
@@ -453,6 +453,7 @@ def view(request, view):
if "," in search:
search, trash = [term.strip() for term in search.split(",", 1)]
object_list = Name.objects \
+ .select_related() \
.filter(Q(surname__istartswith=search) &
Q(private=False) &
Q(person__private=False)
@@ -460,6 +461,7 @@ def view(request, view):
.order_by("surname", "first_name")
else:
object_list = Name.objects \
+ .select_related() \
.filter(Q(private=False) &
Q(person__private=False)) \
.order_by("surname", "first_name")
@@ -526,9 +528,9 @@ def view(request, view):
raise Http404("Requested page type not known")
if request.user.is_authenticated():
- paginator = Paginator(object_list, 50)
+ paginator = Paginator(object_list, 20)
else:
- paginator = Paginator(object_list, 19)
+ paginator = Paginator(object_list, 20)
try:
page = int(request.GET.get('page', '1'))
diff --git a/src/web/libdjango.py b/src/web/libdjango.py
index dd013158a..03781a886 100644
--- a/src/web/libdjango.py
+++ b/src/web/libdjango.py
@@ -401,8 +401,10 @@ 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 = lookup_role_index(models.EventType.DEATH,
+ event_ref_list)
+ birth_ref_index = lookup_role_index(models.EventType.BIRTH,
+ event_ref_list)
return (str(person.handle),
person.gramps_id,
tuple(person.gender_type)[0],
@@ -1097,6 +1099,23 @@ class DjangoInterface(object):
self.add_source_ref_list(person, psource_list)
self.add_address_list("person", person, address_list)
self.add_lds_list("person", person, lds_ord_list)
+ # set person.birth and birth.death to correct events:
+
+ obj_type = ContentType.objects.get_for_model(person)
+ events = models.EventRef.objects.filter(
+ object_id=person.id,
+ object_type=obj_type,
+ ref_object__event_type__val=models.EventType.BIRTH)
+ if events:
+ person.birth = events[0].ref_object
+ 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.save()
+ return person
def add_note_detail(self, data):
"""
@@ -1122,7 +1141,9 @@ class DjangoInterface(object):
for markup in markup_list:
markup_code, value, start_stop_list = markup
m = models.Markup(note=n, order=count,
- markup_type=models.get_type(models.MarkupType, markup_code, get_or_create=True),
+ markup_type=models.get_type(models.MarkupType,
+ markup_code,
+ get_or_create=True),
string=value,
start_stop_list=str(start_stop_list))
m.save()
diff --git a/src/web/sqlite.db b/src/web/sqlite.db
index b7d627fe6..9d2c27b8f 100644
Binary files a/src/web/sqlite.db and b/src/web/sqlite.db differ
diff --git a/src/web/utils.py b/src/web/utils.py
index b42213d57..833775ddf 100644
--- a/src/web/utils.py
+++ b/src/web/utils.py
@@ -62,6 +62,8 @@ from gen.utils import get_birth_or_fallback, get_death_or_fallback
from gen.plug import BasePluginManager
from cli.grampscli import CLIManager
+_ = lambda msg: msg
+
util_filters = [
'nbsp',
'render',
@@ -106,9 +108,15 @@ def get_person_from_handle(db, handle):
try:
return db.get_person_from_handle(handle)
except:
+ print "error in get_person_from_handle:"
+ import sys, traceback
+ cla, exc, trbk = sys.exc_info()
+ print _("Error") + (" : %s %s" %(cla, exc))
+ traceback.print_exc()
return None
def probably_alive(handle):
+ return False
db = DjangoDb()
person = db.get_person_from_handle(handle)
return Utils.probably_alive(person, db)
@@ -365,13 +373,13 @@ def internet_table(obj, user, action, url=None, *args):
_("Description"))
if user.is_authenticated():
urls = dji.Url.filter(person=obj)
- for url in urls:
- table.row(str(url.url_type),
- url.path,
- url.desc)
+ for url_obj in urls:
+ table.row(str(url_obj.url_type),
+ url_obj.path,
+ url_obj.desc)
retval += table.get_html()
if user.is_authenticated() and url and action != "edit":
- retval += make_button(_("Add internet"), (url + "/add") % args)
+ retval += make_button(_("Add internet"), ((str(url) % args) + "/add"))
else:
retval += nbsp("") # to keep tabs same height
return retval
@@ -462,17 +470,17 @@ def get_title(place):
return ""
def person_get_birth_date(person):
- db = DjangoDb()
- event = get_birth_or_fallback(db, db.get_person_from_handle(person.handle))
- if event:
- return event.date
+ #db = DjangoDb()
+ #event = get_birth_or_fallback(db, db.get_person_from_handle(person.handle))
+ #if event:
+ # return event.date
return None
def person_get_death_date(person):
- db = DjangoDb()
- event = get_death_or_fallback(db, db.get_person_from_handle(person.handle))
- if event:
- return event.date
+ #db = DjangoDb()
+ #event = get_death_or_fallback(db, db.get_person_from_handle(person.handle))
+ #if event:
+ # return event.date
return None
def display_date(obj):
@@ -513,7 +521,7 @@ def make_name(name, user):
if user.is_authenticated():
return "%s, %s" % (surname, name.first_name)
else:
- if probably_alive(name.person.handle):
+ if name.person.probably_alive:
return "%s, %s" % (surname, "[Living]")
else:
return "%s, %s" % (surname, name.first_name)
@@ -524,7 +532,7 @@ def make_name(name, user):
if user.is_authenticated():
return "%s, %s" % (surname, name.model.first_name)
else:
- if probably_alive(name.model.person.handle):
+ if name.model.person.probably_alive:
return "%s, %s" % (surname, "[Living]")
else:
return "%s, %s" % (surname, name.model.first_name)
@@ -541,6 +549,64 @@ def make_name(name, user):
else: # no name
return ""
+class lazy(object):
+ EMPTY = []
+ used = 0
+ total = 0
+ def __init__(self, func, *args, **kwargs):
+ self.func = func
+ self.args = args
+ self.kwargs = kwargs
+ self.result = lazy.EMPTY
+ lazy.used = lazy.used + 1
+ lazy.total = lazy.total + 1
+ #print "freeze:", func, args
+
+ def thaw(self):
+ self.result = object.__getattribute__(self, "func")(*object.__getattribute__(self, "args"),
+ **object.__getattribute__(self, "kwargs"))
+ #print "thaw:", object.__getattribute__(self, "func"), object.__getattribute__(self, "result")
+ lazy.used = lazy.used - 1
+
+ def __getattribute__(self, attr):
+ if object.__getattribute__(self, "result") is lazy.EMPTY:
+ object.__getattribute__(self, "thaw")()
+ return getattr(object.__getattribute__(self, "result"), attr)
+
+ def __str__(self):
+ if object.__getattribute__(self, "result") is lazy.EMPTY:
+ object.__getattribute__(self, "thaw")()
+ return str(object.__getattribute__(self, "result"))
+
+ def __int__(self):
+ if object.__getattribute__(self, "result") is lazy.EMPTY:
+ object.__getattribute__(self, "thaw")()
+ return int(object.__getattribute__(self, "result"))
+
+ def __float__(self):
+ if object.__getattribute__(self, "result") is lazy.EMPTY:
+ object.__getattribute__(self, "thaw")()
+ return float(object.__getattribute__(self, "result"))
+
+ def __repr__(self):
+ if object.__getattribute__(self, "result") is lazy.EMPTY:
+ object.__getattribute__(self, "thaw")()
+ return repr(object.__getattribute__(self, "result"))
+
+ def __getitem__(self, pos):
+ if object.__getattribute__(self, "result") is lazy.EMPTY:
+ object.__getattribute__(self, "thaw")()
+ return object.__getattribute__(self, "result")[pos]
+
+ def __len__(self):
+ if object.__getattribute__(self, "result") is lazy.EMPTY:
+ object.__getattribute__(self, "thaw")()
+ return len(object.__getattribute__(self, "result"))
+
+def freeze(item):
+ return lazy(lambda i: i, item)
+
+
register_plugins()
# works after registering plugins: