Using Gramps Proxy Databases from Gramps-Connect: first revisions

svn: r13863
This commit is contained in:
Doug Blank 2009-12-20 22:26:45 +00:00
parent c47b494b39
commit 0e14f53bcd
9 changed files with 126 additions and 42 deletions

View File

@ -22,7 +22,11 @@
</tr>
<tr>
<td class="ColumnAttribute">Description:</td>
{% if user.is_authenticated %}
<td class="ColumnValue" id="data" colspan="3">{{event.description|escape}}</td>
{% else %}
<td class="ColumnValue" id="data" colspan="3">[Private]</td>
{% endif %}
</tr>
<tr>
<td class="ColumnAttribute">ID:</td>

View File

@ -18,8 +18,8 @@
<tr class="{% cycle odd,even %}">
<td><a href="/{{view}}/{{family.handle|escape}}" class="noThumb">{{ forloop.counter|row_count:page }}</a></td>
<td><a href="/{{view}}/{{family.handle|escape}}" class="noThumb"><span class="grampsid">[{{family.gramps_id}}]</span></a>
<td><a href="/{{view}}/{{family.handle|escape}}">{{family.father.name_set|make_name:user|nbsp}}</a>
<td><a href="/{{view}}/{{family.handle|escape}}">{{family.mother.name_set|make_name:user|nbsp}}</a>
<td><a href="/{{view}}/{{family.handle|escape}}">{{family.father|make_name:user|nbsp}}</a>
<td><a href="/{{view}}/{{family.handle|escape}}">{{family.mother|make_name:user|nbsp}}</a>
{% if user.is_authenticated %}
<td><a href="/{{view}}/{{family.handle|escape}}">{{family.family_rel_type|escape}}</a>
{% else %}

View File

@ -12,7 +12,7 @@
<div class="content" id="IndividualDetail">
<h3>{{family.father.name_set|make_name:user}} and {{family.mother.name_set|make_name:user}}</h3>
<h3>{{family.father|make_name:user}} and {{family.mother|make_name:user}}</h3>
<div id="summaryarea">
<table class="infolist"> {% comment %} 4 cols {% endcomment %}
@ -23,9 +23,9 @@
</tr>
<tr>
<td class="ColumnAttribute">Name:</td>
<td class="ColumnValue" id="data"><a href="/person/{{family.father.handle}}">{{family.father.name_set|make_name:user}} [{{family.father.gramps_id|escape}}]</a></td>
<td class="ColumnValue" id="data"><a href="/person/{{family.father.handle}}">{{family.father|make_name:user}} [{{family.father.gramps_id|escape}}]</a></td>
<td class="ColumnAttribute">Name:</td>
<td class="ColumnValue" id="data"><a href="/person/{{family.mother.handle}}">{{family.mother.name_set|make_name:user}} [{{family.mother.gramps_id|escape}}]</a></td>
<td class="ColumnValue" id="data"><a href="/person/{{family.mother.handle}}">{{family.mother|make_name:user}} [{{family.mother.gramps_id|escape}}]</a></td>
</tr>
{% if user.is_authenticated or not family.father.handle|probably_alive %}
<tr>

View File

@ -20,18 +20,16 @@
<tbody>
{% for name in page.object_list %}
<tr class="{% cycle odd,even %}">
<td><a href="{{name.person.handle|escape}}/" class="noThumb">{{ forloop.counter|row_count:page }}</a>
{% get_person_from_handle db name.person.handle as person %}
{% if person %}
<td><a href="{{person.handle}}/" class="noThumb">{{ forloop.counter|row_count:page }}</a>
</td>
<td><a href="{{name.person.handle|escape}}/" class="noThumb">{{name|make_name:user}}</a>
<td><a href="{{person.handle}}/" class="noThumb">{{person|make_name}}</a>
</td>
<td><a href="{{name.person.handle|escape}}/" class="grampsid">[{{name.person.gramps_id|escape}}]</a></td>
<td><a href="{{name.person.handle|escape}}/" class="noThumb">{{name.person.gender_type|escape}}</a></td>
{% if user.is_authenticated %}
<td><a href="{{name.person.handle|escape}}/" class="noThumb">{{name.person|person_get_birth_date|nbsp}}</a></td>
<td><a href="{{name.person.handle|escape}}/" class="noThumb">{{name.person|person_get_death_date|nbsp}}</a></td>
{% else %}
<td><a href="{{name.person.handle|escape}}/" class="noThumb">[Private]</a>
<td><a href="{{name.person.handle|escape}}/" class="noThumb">[Private]</a>
<td><a href="{{person.handle}}/" class="grampsid">[{{person.gramps_id}}]</a></td>
<td><a href="{{person.handle}}/" class="noThumb">{{person.gender_type}}</a></td>
<td><a href="{{person.handle}}/" class="noThumb">{{person|person_get_birth_date|nbsp}}</a></td>
<td><a href="{{person.handle}}/" class="noThumb">{{person|person_get_death_date|nbsp}}</a></td>
{% endif %}
</tr>
{% endfor %}

View File

@ -60,6 +60,15 @@ class DjangoDb(GrampsDbBase):
self.dji = DjangoInterface()
self.readonly = False
self.db_is_open = True
self.name_formats = range(4)
self.bookmarks = []
self.family_bookmarks = []
self.event_bookmarks = []
self.place_bookmarks = []
self.source_bookmarks = []
self.repo_bookmarks = []
self.media_bookmarks = []
self.note_bookmarks = []
def get_researcher(self):
obj = gen.lib.Name()

View File

@ -18,7 +18,7 @@
"setting" : "db_created" ,
"description" : "database creation date/time" ,
"value_type" : "str" ,
"value" : "2009-11-22 17:24"
"value" : "2009-12-12 20:42"
}
},
{

View File

@ -1,3 +1,6 @@
import re
from django import template
from django.template import escape, Library
from django.utils.safestring import mark_safe
from web.utils import *
@ -21,6 +24,40 @@ for filter_name in util_filters:
func.is_safe = True
register.filter(filter_name, func)
def get_person_from_handle(db, handle):
# db is a Gramps Db interface
# handle is a Person Handle
return db.get_person_from_handle(handle)
class TemplateNode(template.Node):
def __init__(self, args, var_name):
self.db = template.Variable(args[0])
self.handle = template.Variable(args[1])
self.var_name = var_name
def render(self, context):
context[self.var_name] = \
get_person_from_handle(self.db.resolve(context),
self.handle.resolve(context))
return ''
def do_get_person_from_handle(parser, token):
try:
# Splitting by None == splitting by spaces.
tag_name, args = token.contents.split(None, 1)
except ValueError:
raise template.TemplateSyntaxError, \
("%r tag requires arguments" % token.contents.split()[0])
m = re.search(r'(.*?) as (\w+)', args)
if not m:
raise template.TemplateSyntaxError, \
("%r tag had invalid arguments" % tag_name)
args_string, var_name = m.groups()
args = args_string.split()
return TemplateNode(args, var_name)
register.tag("get_person_from_handle", do_get_person_from_handle)
probably_alive.is_safe = True
register.filter('probably_alive', probably_alive)

View File

@ -43,6 +43,9 @@ import web
from web.grampsdb.models import *
from web.grampsdb.forms import NameForm
from web.utils import probably_alive
from web.djangodb import DjangoDb
from gen.proxy import LivingProxyDb
_ = lambda text: text
@ -276,6 +279,15 @@ def view_detail(request, view, handle):
return render_to_response(view_template, context)
def view(request, view):
db_direct = DjangoDb()
if not request.user.is_authenticated():
#MODE_EXCLUDE_ALL = 0
#MODE_INCLUDE_LAST_NAME_ONLY = 1
#MODE_INCLUDE_FULL_NAME_ONLY = 2
db = LivingProxyDb(db_direct,
LivingProxyDb.MODE_INCLUDE_LAST_NAME_ONLY)
else:
db = db_direct
search = ""
if view == "event":
if request.user.is_authenticated():
@ -499,6 +511,7 @@ def view(request, view):
context["tview"] = _(view.title())
context["search"] = search
context["total"] = total
context["db"] = db
if search:
context["search_query"] = ("&search=%s" % escape(search))
else:

View File

@ -23,33 +23,50 @@
#------------------------------------------------------------------------
#
# Gramps/Django Modules
# Python Modules
#
#------------------------------------------------------------------------
import locale
#------------------------------------------------------------------------
#
# Django Modules
#
#------------------------------------------------------------------------
import web.grampsdb.models as models
import web.grampsdb.forms as forms
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
from django.utils.safestring import mark_safe
from django.contrib.contenttypes.models import ContentType
#------------------------------------------------------------------------
#
# Python Modules
# Gramps-Connect Modules
#
#------------------------------------------------------------------------
import locale
import web.grampsdb.models as models
import web.grampsdb.forms as forms
from web import libdjango
from web.djangodb import DjangoDb
#------------------------------------------------------------------------
#
# Gramps Modules
#
#------------------------------------------------------------------------
from Simple import SimpleTable, SimpleAccess, make_basic_stylesheet
import Utils
import DbState
import DateHandler
from gen.lib.date import Date as GDate, Today
import gen.lib
from gen.plug import BasePluginManager
from cli.grampscli import CLIManager
#------------------------------------------------------------------------
#
# Modeul Constants
#
#------------------------------------------------------------------------
dji = libdjango.DjangoInterface()
_dd = DateHandler.displayer.display
_dp = DateHandler.parser.parse
@ -458,10 +475,18 @@ def get_title(place):
return ""
def person_get_birth_date(person):
return person_get_event(person, models.EventType.BIRTH)
db = DjangoDb()
event = db.get_birth_or_fallback(person)
if event:
return event.date
return None
def person_get_death_date(person):
return person_get_event(person, models.EventType.DEATH)
db = DjangoDb()
event = db.get_death_or_fallback(person)
if event:
return event.date
return None
def display_date(obj):
date_tuple = dji.get_date(obj)
@ -493,7 +518,7 @@ def person_get_event(person, event_type=None):
for event_handle in event_ref_list]
return [j for i in retval for j in i]
def make_name(name, user):
def make_name(name, user=None):
if isinstance(name, models.Name):
surname = name.surname.strip()
if not surname:
@ -516,16 +541,14 @@ def make_name(name, user):
return "%s, %s" % (surname, "[Living]")
else:
return "%s, %s" % (surname, name.model.first_name)
elif name: # name_set
try:
name = name.get(preferred=True)
except:
elif isinstance(name, gen.lib.Person): # name is a gen.lib.Person
person = name
name = person.get_primary_name()
if name is None:
return "[No preferred name]"
if name:
return make_name(name, user)
else:
return ""
else:
return "%s, %s" % (name.get_surname(), name.get_first_name())
else: # no name
return ""
register_plugins()