Moved functions from my_tags to web.utils; added some support for tables; uses docgen code; minor changes to css

svn: r13579
This commit is contained in:
Doug Blank 2009-11-14 22:48:30 +00:00
parent d3fd2f150d
commit 02d095ca8c
6 changed files with 227 additions and 77 deletions

View File

@ -305,13 +305,30 @@ table tr th {
padding:.1em 10px;
border-bottom:double 4px #7D5925;
}
table.infolist tr th a {
text-decoration:none;
}
table tr td {
vertical-align:middle;
padding:.1em 10px;
}
table tr td.TableHeaderCell {
color: #7D5925;
background-color: #f8eec9;
font-weight: bold;
text-align: left;
margin:0;
border-bottom:double 4px #7D5925;
border-left:solid 2px #7D5925;
border-right:solid 2px #7D5925;
border-top:solid 2px #7D5925;
}
table tr td.TableDataCell {
color: #f8eec9;
border:solid 2px #7D5925;
}
table.infolist tr th a {
text-decoration:none;
}
table.infolist tr td a {
display:block;
text-decoration:none;

View File

@ -48,7 +48,7 @@
/* Component containers
----------------------------------*/
.ui-widget { }
.ui-widget { font-family:Georgia, serif; color:#7D5925; font-size: 0.7em; }
.ui-widget input, .ui-widget select, .ui-widget textarea, .ui-widget button { }
.ui-widget-content { border: 1px solid #efec9f; background: #443113 url(images/ui-bg_diamond_8_443113_10x8.png) 50% 50% repeat; color: #efec9f; }
.ui-widget-content a { color: #efec9f; background: none;}

View File

@ -10,33 +10,52 @@
});
</script>
<table>
<div class="content" id="IndividualDetail">
<h3>{{person.name_set|make_name:user}}</h3>
<div id="summaryarea">
<table class="infolist">
<tbody>
<tr>
<td>Family:</td><td> {{person.name_set|preferred:"surname"}}</td><td>Prefix:</td><td>{{person.name_set|preferred:"prefix"}}</td>
<td class="ColumnAttribute">Family</td>
<td class="ColumnValue">{{person.name_set|preferred:"surname"}}</td>
<td class="ColumnAttribute">Prefix</td>
<td class="ColumnValue">{{person.name_set|preferred:"prefix"}}</td>
</tr>
<tr>
<td>Given:</td><td> {{person.name_set|preferred:"first_name"}}</td><td>Callname:</td><td>{{person.name_set|preferred:"call"}}</td>
<td class="ColumnAttribute">Given</td>
<td class="ColumnValue">{{person.name_set|preferred:"first_name"}}</td>
<td class="ColumnAttribute">Callname</td>
<td class="ColumnValue">{{person.name_set|preferred:"call"}}</td>
</tr>
<tr>
<td>Type:</td><td> {{person.name_set|preferred:"name_type"}}</td><td>Patronymic:</td><td>{{person.name_set|preferred:"patronymic"}}</td>
<td class="ColumnAttribute">Type</td>
<td class="ColumnValue">{{person.name_set|preferred:"name_type"}}</td>
<td class="ColumnAttribute">Patronymic</td>
<td class="ColumnValue">{{person.name_set|preferred:"patronymic"}}</td>
</tr>
<tr>
<td>Description:</td><td spancols="2"></td>
<td class="ColumnAttribute">Description</td>
<td class="ColumnValue" spancols="3"></td>
</tr>
<tr>
<td>ID:</td><td spancols="2">{{person.gramps_id|escape}}</td>
<td class="ColumnAttribute">ID</td>
<td class="ColumnValue" spancols="3">{{person.gramps_id|escape}}</td>
</tr>
<tr>
<td>Place:</td><td spancols="2"></td>
<td class="ColumnAttribute">Place</td>
<td class="ColumnValue" spancols="3"></td>
</tr>
</tbody>
</table>
</div>
</div>
<!-- Tabs -->
<h2 class="demoHeaders">Tabs</h2>
<div class="ui-tabs ui-widget ui-widget-content ui-corner-all" id="tabs">
<ul class="ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all">
<li class="ui-state-default ui-corner-top ui-tabs-selected ui-state-active"><a href="#tabs-1" style=":hover {color: black;}">Events</a></li>
<li class="ui-state-default ui-corner-top ui-tabs-selected ui-state-active"><a href="#tabs-1">Events</a></li>
<li class="ui-corner-top ui-state-default"><a href="#tabs-2">Names</a></li>
<li class="ui-corner-top ui-state-default"><a href="#tabs-3">Sources</a></li>
<li class="ui-corner-top ui-state-default"><a href="#tabs-4">Attributes</a></li>
@ -47,8 +66,21 @@
<li class="ui-corner-top ui-state-default"><a href="#tabs-9">LDS</a></li>
<li class="ui-corner-top ui-state-default"><a href="#tabs-10">References</a></li>
</ul>
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom" id="tabs-1"> table 1 </div>
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tabs-2"> table 2 </div>
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom" id="tabs-1">
<!-- Events -->
{{ person|events_table|safe }}
</div>
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tabs-2">
<!-- Names -->
<table border="1">
{% for name in person.name_set.all %}
<tr>
<td>{{forloop.counter}}</td>
<td><a href="/name/{{name.id}}">{{name|make_name:user}}</a></td>
</tr>
{% endfor %}
</table>
</div>
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tabs-3"> table 3 </div>
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tabs-4"> table 4 </div>
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tabs-5"> table 5 </div>

View File

@ -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

View File

@ -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)

149
src/web/utils.py Normal file
View File

@ -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