-
table 1
-
table 2
+
+
+ {{ person|events_table|safe }}
+
+
table 3
table 4
table 5
diff --git a/src/web/djangodb.py b/src/web/djangodb.py
index a4f0edfd3..906e6270f 100644
--- a/src/web/djangodb.py
+++ b/src/web/djangodb.py
@@ -2,17 +2,12 @@ import web
import gen
from gen.db import GrampsDbBase
from web.libdjango import DjangoInterface
-import Utils
# from ReportBase._CommandLineReport import run_report
# import djangodb
# db = djangodb.DjangoDb()
# run_report(db, "ancestor_report", off="txt", of="ar.txt", pid="I37")
-def probably_alive(handle):
- db = DjangoDb()
- return Utils.probably_alive(db.get_person_from_handle(handle), db)
-
class Cursor(object):
def __init__(self, model, func):
self.model = model
@@ -114,6 +109,15 @@ class DjangoDb(GrampsDbBase):
def get_person_cursor(self):
return Cursor(self.dji.Person, self.dji.get_person)
+ def get_family_cursor(self):
+ return Cursor(self.dji.Family, self.dji.get_family)
+
+ def get_events_cursor(self):
+ return Cursor(self.dji.Event, self.dji.get_event)
+
+ def get_source_cursor(self):
+ return Cursor(self.dji.Source, self.dji.get_source)
+
def has_person_handle(self, handle):
return self.dji.Person.filter(handle=handle).count() == 1
diff --git a/src/web/grampsdb/templatetags/my_tags.py b/src/web/grampsdb/templatetags/my_tags.py
index c74ae98ca..19eebf7c8 100644
--- a/src/web/grampsdb/templatetags/my_tags.py
+++ b/src/web/grampsdb/templatetags/my_tags.py
@@ -1,54 +1,22 @@
from django.template import escape, Library
-from web import libdjango
-from web import djangodb
-import web.grampsdb.models as models
-from gen.lib.date import Date as GDate, Today
-import DateHandler
+from web.utils import *
-dji = libdjango.DjangoInterface()
register = Library()
-_dd = DateHandler.displayer.display
-_dp = DateHandler.parser.parse
-
-## FIXME: these dji function wrappers just use the functions
-## written for the import/export. Can be done much more directly.
-
-def person_get_birth_date(person):
- return person_get_event(person, models.EventType.BIRTH)
-def person_get_death_date(person):
- return person_get_event(person, models.EventType.DEATH)
+events_table.is_safe = True
+register.filter('events_table', events_table)
person_get_birth_date.is_safe = True
register.filter('person_get_birth_date', person_get_birth_date)
+
person_get_death_date.is_safe = True
register.filter('person_get_death_date', person_get_death_date)
-def display_date(obj):
- date_tuple = dji.get_date(obj)
- if date_tuple:
- gdate = GDate()
- gdate.unserialize(date_tuple)
- return escape(_dd(gdate))
- else:
- return ""
display_date.is_safe = True
register.filter('display_date', display_date)
-def person_get_event(person, event_type):
- event_ref_list = dji.get_event_ref_list(person)
- index = libdjango.lookup_role_index(event_type, event_ref_list)
- if index >= 0:
- event_handle = event_ref_list[index][3]
- # (False, [], [], u'b2cfa6cdec87392cf3b', (1, u'Primary'))
- # WARNING: the same object can be referred to more than once
- objs = models.EventRef.objects.filter(ref_object__handle=event_handle)
- if objs.count() > 0:
- return display_date(objs[0].ref_object)
- else:
- return ""
- else:
- return ""
+person_get_event.is_safe = True
+register.filter('person_get_events', person_get_event)
def preview(text, width=40):
text = text.replace("\n", " ")
@@ -56,26 +24,6 @@ def preview(text, width=40):
preview.is_safe = True
register.filter('preview', preview)
-def make_name(name, user):
- if isinstance(name, models.Name):
- surname = name.surname.strip()
- if not surname:
- surname = "[Missing]"
- if user.is_authenticated():
- return escape("%s, %s" % (surname, name.first_name))
- else:
- if djangodb.probably_alive(name.person.handle):
- return escape("%s, %s" % (surname, "[Living]"))
- else:
- return escape("%s, %s" % (surname, name.first_name))
- elif name:
- name = name.get(preferred=True)
- if name:
- return make_name(name, user)
- else:
- return ""
- else:
- return ""
make_name.is_safe = True
register.filter('make_name', make_name)
diff --git a/src/web/utils.py b/src/web/utils.py
new file mode 100644
index 000000000..d16a94e33
--- /dev/null
+++ b/src/web/utils.py
@@ -0,0 +1,149 @@
+import web.grampsdb.models as models
+from web import libdjango
+from web.djangodb import DjangoDb
+from Simple import SimpleTable, SimpleAccess, make_basic_stylesheet
+import Utils
+import DbState
+import DateHandler
+from gen.lib.date import Date as GDate, Today
+from gen.plug import BasePluginManager
+from cli.grampscli import CLIManager
+from django.template import escape
+
+dji = libdjango.DjangoInterface()
+
+_dd = DateHandler.displayer.display
+_dp = DateHandler.parser.parse
+
+def register_plugins():
+ dbstate = DbState.DbState()
+ climanager = CLIManager(dbstate, False) # don't load db
+ climanager.do_reg_plugins()
+ pmgr = BasePluginManager.get_instance()
+ return pmgr
+
+def probably_alive(handle):
+ db = DjangoDb()
+ return Utils.probably_alive(db.get_person_from_handle(handle), db)
+
+class Table(object):
+ """
+ >>> table = Table()
+ >>> table.columns("Col1", "Col2", "Col3")
+ >>> table.row("1", "2", "3")
+ >>> table.row("4", "5", "6")
+ >>> table.get_html()
+ """
+ def __init__(self):
+ self.db = DjangoDb()
+ self.access = SimpleAccess(self.db)
+ self.table = SimpleTable(self.access)
+ class Doc(object):
+ def __init__(self, doc):
+ self.doc = doc
+ # None is paperstyle, which is ignored:
+ self.doc = Doc(HtmlDoc.HtmlDoc(make_basic_stylesheet(), None))
+ self.doc.doc._backend = HtmlBackend()
+ # You can set elements id, class, etc:
+ # self.doc.doc.htmllist += [Html('div', id="grampstextdoc")]
+ self.doc.doc.htmllist += [Html('div')]
+
+ def columns(self, *args):
+ self.table.columns(*args)
+
+ def row(self, *args):
+ self.table.row(*args)
+
+ def get_html(self):
+ self.table.write(self.doc) # forces to htmllist
+ return str(self.doc.doc.htmllist[0])
+
+_ = lambda text: text
+
+def events_table(djperson):
+ table = Table()
+ table.columns(_("Description"),
+ _("Type"),
+ _("ID"),
+ _("Date"),
+ _("Place"),
+ _("Role"))
+ person = table.db.get_person_from_handle(djperson.handle)
+ event_list = table.access.events(person)
+ for event in event_list:
+ djevent = dji.Event.get(handle=event.handle)
+ table.row(
+ djevent.description,
+ djevent.event_type.name,
+ djevent.gramps_id,
+ table.access.event_date_obj(event),
+ table.access.event_place(event),
+ "FIXME")
+ return table.get_html()
+
+## FIXME: these dji function wrappers just use the functions
+## written for the import/export. Can be done much more directly.
+
+def person_get_birth_date(person):
+ return person_get_event(person, models.EventType.BIRTH)
+
+def person_get_death_date(person):
+ return person_get_event(person, models.EventType.DEATH)
+
+def display_date(obj):
+ date_tuple = dji.get_date(obj)
+ if date_tuple:
+ gdate = GDate()
+ gdate.unserialize(date_tuple)
+ return escape(_dd(gdate))
+ else:
+ return ""
+
+def person_get_event(person, event_type=None):
+ event_ref_list = dji.get_event_ref_list(person)
+ if event_type:
+ index = libdjango.lookup_role_index(event_type, event_ref_list)
+ if index >= 0:
+ event_handle = event_ref_list[index][3]
+ # (False, [], [], u'b2cfa6cdec87392cf3b', (1, u'Primary'))
+ # WARNING: the same object can be referred to more than once
+ objs = models.EventRef.objects.filter(ref_object__handle=event_handle)
+ if objs.count() > 0:
+ return display_date(objs[0].ref_object)
+ else:
+ return ""
+ else:
+ return ""
+ else:
+ retval = [[obj.ref_object for obj in
+ models.EventRef.objects.filter(ref_object__handle=event_handle[3])]
+ for event_handle in event_ref_list]
+ return [j for i in retval for j in i]
+
+def make_name(name, user):
+ if isinstance(name, models.Name):
+ surname = name.surname.strip()
+ if not surname:
+ surname = "[Missing]"
+ if user.is_authenticated():
+ return escape("%s, %s" % (surname, name.first_name))
+ else:
+ if probably_alive(name.person.handle):
+ return escape("%s, %s" % (surname, "[Living]"))
+ else:
+ return escape("%s, %s" % (surname, name.first_name))
+ elif name:
+ name = name.get(preferred=True)
+ if name:
+ return make_name(name, user)
+ else:
+ return ""
+ else:
+ return ""
+
+register_plugins()
+
+# works after registering plugins:
+import HtmlDoc
+from libhtmlbackend import HtmlBackend
+from libhtml import Html