Latest advancement in privacy issues; reworked proxy + forms

svn: r13929
This commit is contained in:
Doug Blank 2009-12-27 18:23:59 +00:00
parent ef3a25815a
commit 7ca0d94563
11 changed files with 315 additions and 275 deletions

View File

@ -83,25 +83,25 @@
</ul>
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom" id="tab-children">
<!-- Events -->
{{ family|family_children_table:user|safe }}
{% children_table family user action "/family/%s/children" family.handle %}
</div>
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tab-events">
{{ family|family_event_table:user|safe }}
{% event_table family user action "/family/%s/children" family.handle %}
</div>
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tab-sources">
{{ family|source_table:user|safe }}
{% source_table family user action "/family/%s/children" family.handle %}
</div>
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tab-attributes">
{{ family|family_attribute_table:user|safe }}
{% attribute_table family user action "/family/%s/children" family.handle %}
</div>
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tab-notes">
{{ family|family_note_table:user|safe }}
{% note_table family user action "/family/%s/children" family.handle %}
</div>
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tab-gallery">
{{ family|family_gallery_table:user|safe }}
{% gallery_table family user action "/family/%s/children" family.handle %}
</div>
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tab-lds">
{{ family|family_lds_table:user|safe }}
{% lds_table family user action "/family/%s/children" family.handle %}
</div>
</div>
{% endblock %}

View File

@ -11,7 +11,7 @@
</script>
<div class="content" id="IndividualDetail">
<h3>Name for Person [{{person.gramps_id}}]</h3>
<h3>{{person|make_name:user}} [{{person.gramps_id}}]</h3>
<div id="summaryarea">
<table class="infolist"> {% comment %} 4 cols {% endcomment %}
<tbody>
@ -69,26 +69,32 @@
<li class="ui-corner-top ui-state-default"><a href="#tab-notes">Notes</a></li>
</ul>
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom" id="tab-general">
<table>
<tr><td>{{form.group_as.label}}: </td>
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom"
id="tab-general">
<div style="overflow: auto; height:150px; color: black; background-color: white;">
<table border="1">
<tr><td style="background-color: #FFF2C5;">{{form.group_as.label}}: </td>
<td>{{form.group_as|render:action}}</td>
</tr>
<tr><td>{{form.sort_as.label}}: </td>
<tr><td style="background-color: #FFF2C5;">{{form.sort_as.label}}: </td>
<td>{{form.sort_as|render:action}}</td>
</tr>
<tr><td>{{form.display_as.label}}: </td>
<tr><td style="background-color: #FFF2C5;">{{form.display_as.label}}: </td>
<td>{{form.display_as|render:action}}</td>
</tr>
<tr><td>{{form.text.label}}: </td>
<tr><td style="background-color: #FFF2C5;">{{form.text.label}}: </td>
<td>{{form.text|render:action}}</td>
</tr>
</table>
</div>
&nbsp;
</div>
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tab-sources">
{% source_table form.model user action "/person/%s/name/%s/source/add" person.handle form.model.order %}
{% source_table form.model user action "/person/%s/name/%s/source" person.handle form.model.order %}
</div>
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tab-notes">
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom
ui-tabs-hide" id="tab-notes">
{% note_table form.model user action "/person/%s/name/%s/note" person.handle form.model.order %}
</div>
</div>

View File

@ -24,7 +24,7 @@
{% if person %}
<td><a href="{{person.handle}}/" class="noThumb">{{ forloop.counter|row_count:page }}</a>
</td>
<td><a href="{{person.handle}}/" class="noThumb">{{person|make_name}}</a>
<td><a href="{{person.handle}}/" class="noThumb">{{person|make_name:user}}</a>
</td>
<td><a href="{{person.handle}}/" class="grampsid">[{{person.gramps_id}}]</a></td>
<td><a href="{{person.handle}}/" class="noThumb">{{person.gender_type}}</a></td>

View File

@ -11,49 +11,61 @@
</script>
<div class="content" id="IndividualDetail">
<h3></h3>
<h3>{{nameform|make_name:user}} [{{person.gramps_id}}]</h3>
<div id="summaryarea">
<table class="infolist"> {% comment %} 5 cols {% endcomment %}
<tbody>
{% if user.is_authenticated %}
{% ifequal action "edit" %}
{% for error in personform.errors %}
{{error}}<br>
{% endfor %}
{% for error in nameform.errors %}
{{error}}<br>
{% endfor %}
<form method="post">
{% endifequal %}
{% endif %}
<tr>
<td class="ColumnAttribute">Family:</td>
<td class="ColumnValue" id="data">{{name.surname}}</td>
<td class="ColumnAttribute">Prefix:</td>
<td class="ColumnValue" id="data">{{name.prefix}}</td>
<td class="ColumnAttribute">{{nameform.surname.label}}</td>
<td class="ColumnValue" id="data">{{nameform.surname|render:action}}</td>
<td class="ColumnAttribute">{{nameform.prefix.label}}</td>
<td class="ColumnValue" id="data">{{nameform.prefix|render:action}}</td>
<td rowspan="6" colspan="2" style="border:solid 2px #7D5925;">Image:</td>
</tr>
<tr>
<td class="ColumnAttribute" colspan="2"></td>
<td class="ColumnAttribute">Suffix:</td>
<td class="ColumnValue" id="data">{{name.suffix}}</td>
<td class="ColumnAttribute">{{nameform.suffix.label}}</td>
<td class="ColumnValue" id="data">{{nameform.suffix|render:action}}</td>
</tr>
<tr>
<td class="ColumnAttribute">Given:</td>
<td class="ColumnValue" id="data">{{name.first_name}}</td>
<td class="ColumnAttribute">Call Name:</td>
<td class="ColumnValue" id="data">{{name.call}}</td>
<td class="ColumnAttribute">{{nameform.first_name.label}}</td>
<td class="ColumnValue" id="data">{{nameform.first_name|render:action}}</td>
<td class="ColumnAttribute">{{nameform.call.label}}</td>
<td class="ColumnValue" id="data">{{nameform.call|render:action}}</td>
</tr>
<tr>
<td class="ColumnAttribute">Type:</td>
<td class="ColumnValue" id="data">{{name.name_type}}</td>
<td class="ColumnAttribute">Patronymic:</td>
<td class="ColumnValue" id="data">{{name.patronymic}}</td>
<td class="ColumnAttribute">{{nameform.name_type.label}}</td>
<td class="ColumnValue" id="data">{{nameform.name_type|render:action}}</td>
<td class="ColumnAttribute">{{nameform.patronymic.label}}</td>
<td class="ColumnValue" id="data">{{nameform.patronymic|render:action}}</td>
</tr>
<tr>
<td class="ColumnAttribute" colspan="2"></td>
<td class="ColumnAttribute">Title:</td>
<td class="ColumnValue" id="data">{{name.title}}</td>
<td class="ColumnAttribute">{{nameform.title.label}}</td>
<td class="ColumnValue" id="data">{{nameform.title|render:action}}</td>
</tr>
<tr>
<td class="ColumnAttribute">Gender:</td>
<td class="ColumnValue" id="data">{{person.gender_type}}</td>
<td class="ColumnAttribute">ID:</td>
<td class="ColumnValue" id="data">{{person.gramps_id}}</td>
<td class="ColumnAttribute">{{personform.gender_type.label}}</td>
<td class="ColumnValue" id="data">{{personform.gender_type|render:action}}</td>
<td class="ColumnAttribute">{{personform.gramps_id.label}}</td>
<td class="ColumnValue" id="data">{{personform.gramps_id|render:action}}</td>
</tr>
<tr>
<td class="ColumnAttribute">Marker:</td>
<td class="ColumnValue" id="data">{{person.marker_type}}</td>
<td class="ColumnAttribute">{{personform.marker_type.label}}</td>
<td class="ColumnValue" id="data">{{personform.marker_type|render:action}}</td>
<td class="ColumnAttribute" colspan="3"></td>
</tr>
</tbody>
@ -80,40 +92,54 @@
</ul>
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom" id="tab-events">
<!-- Events -->
{{ person|person_event_table:user|safe }}
{% event_table person user action "/person/%s/event" person.handle %}
</div>
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tab-names">
{{ person|person_name_table:user|safe }}
{% name_table person user action "/person/%s/name" person.handle %}
</div>
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tab-sources">
{% source_table person user action "/person/%s/source/add" person.handle %}
{% source_table person user action "/person/%s/source" person.handle %}
</div>
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tab-attributes">
{{ person|person_attribute_table:user|safe }}
{% attribute_table person user action "/person/%s/attribute" person.handle %}
</div>
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tab-addresses">
{{ person|person_address_table:user|safe }}
{% address_table person user action "/person/%s/address" person.handle %}
</div>
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tab-notes">
{{ person|person_note_table:user|safe }}
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom
ui-tabs-hide" id="tab-notes">
{% note_table person user action "/person/%s/note" person.handle %}
</div>
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tab-gallery">
{{ person|person_gallery_table:user|safe }}
{% gallery_table person user action "/person/%s/gallery" person.handle %}
</div>
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tab-internet">
{{ person|person_internet_table:user|safe }}
{% internet_table person user action "/person/%s/internet" person.handle %}
</div>
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tab-association">
{{ person|person_association_table:user|safe }}
{% association_table person user action "/person/%s/association" person.handle %}
</div>
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tab-lds">
{{ person|person_lds_table:user|safe }}
{% lds_table person user action "/person/%s/lds" person.handle %}
</div>
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tab-references">
{{ person|person_reference_table:user|safe }}
{% reference_table person user action "/person/%s/reference" person.handle %}
</div>
</div>
{% if user.is_authenticated %}
{% ifequal action "edit" %}
{% make_button "Back to Person" "/person/%s" person.handle %}
<input type="hidden" name="action" value="save"/>
<input type="submit" value="Submit"/>
</form>
{% else %}
{% make_button "Back to People" "/person/" %}
{% make_button "Edit Person" "/person/%s/edit" person.handle %}
{% make_button "Delete Person" "/person/%s/delete" person.handle %}
{% endifequal %}
{% else %}
{% endif %}
{% endblock %}

View File

@ -92,9 +92,17 @@ class DjangoDb(DbReadBase, DbWriteBase):
return obj
def get_place_from_handle(self, handle):
obj = gen.lib.Place()
obj.unserialize(self.dji.get_place(self.dji.Place.get(handle=handle)))
return obj
try:
dji_obj = self.dji.Place.get(handle=handle)
except:
dji_obj = None
if dji_obj:
tuple_obj = self.dji.get_place(dji_obj)
if tuple_obj:
obj = gen.lib.Place()
obj.unserialize(tuple_obj)
return obj
return None
def get_source_from_handle(self, handle):
obj = gen.lib.Source()

View File

@ -18,7 +18,7 @@
"setting" : "db_created" ,
"description" : "database creation date/time" ,
"value_type" : "str" ,
"value" : "2009-12-26 00:38"
"value" : "2009-12-26 08:01"
}
},
{

View File

@ -10,7 +10,6 @@ import datetime
class PersonForm(forms.ModelForm):
class Meta:
model = Person
exclude = ('handle',)
'''def clean(self):
cleaned_data['last_changed'] = datetime.datetime.now()

View File

@ -8,16 +8,6 @@ import web.utils
register = Library()
for filter_name in util_filters:
func = getattr(web.utils, filter_name)
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, func):
self.args = map(template.Variable, args)
@ -33,8 +23,7 @@ class TemplateNode(template.Node):
return value
def parse_tokens(tokens):
# Splitting by None splits by spaces
items = tokens.contents.split(None)
items = tokens.split_contents()
# {% tag_name arg1 arg2 arg3 as variable %}
# {% tag_name arg1 arg2 arg3 %}
tag_name = items[0]
@ -52,11 +41,14 @@ def make_tag(func):
return TemplateNode(args, var_name, func)
return do_func
register.tag("get_person_from_handle",
make_tag(get_person_from_handle))
for filter_name in util_filters:
func = getattr(web.utils, filter_name)
func.is_safe = True
register.filter(filter_name, func)
register.tag("source_table",
make_tag(source_table))
for tag_name in util_tags:
func = getattr(web.utils, tag_name)
register.tag(tag_name, make_tag(func))
probably_alive.is_safe = True
register.filter('probably_alive', probably_alive)

View File

@ -41,11 +41,11 @@ from django.db.models import Q
#------------------------------------------------------------------------
import web
from web.grampsdb.models import *
from web.grampsdb.forms import NameForm
from web.grampsdb.forms import NameForm, PersonForm
from web.utils import probably_alive
from web.djangodb import DjangoDb
from gen.proxy import LivingProxyDb
import gen.proxy
_ = lambda text: text
@ -207,8 +207,9 @@ class PrivateProxy(object):
def __getattr__(self, attr):
return getattr(self.obj, attr)
def view_detail(request, view, handle):
def view_detail(request, view, handle, action="view"):
context = RequestContext(request)
context["action"] = action
context["view"] = view
if view == "event":
try:
@ -239,24 +240,7 @@ def view_detail(request, view, handle):
view_template = 'view_note_detail.html'
context["tview"] = _("Note")
elif view == "person":
try:
obj = Person.objects.get(handle=handle)
except:
raise Http404(_("Requested %s does not exist.") % view)
view_template = 'view_person_detail.html'
person = obj
name = person.get_primary_name()
if request.user.is_authenticated():
pass # see everything, no limits
elif probably_alive(person.handle):
name.first_name = "[Living]"
elif person.private:
name = Name()
name.surname = "[Private]"
name.first_name = "[Private]"
# FIXME: protect everything else; what if name.private?
context["name"] = name
context["tview"] = _("Person")
return view_person_detail(request, view, handle, action)
elif view == "place":
try:
obj = Place.objects.get(handle=handle)
@ -281,19 +265,56 @@ def view_detail(request, view, handle):
else:
raise Http404(_("Requested page type not known"))
context[view] = obj
context["action"] = "view"
return render_to_response(view_template, context)
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 the private flag is set, apply the PrivateProxyDb
if private_filter:
dbase = gen.proxy.PrivateProxyDb(dbase)
# If the restrict flag is set, apply the LivingProxyDb
if living_filter:
dbase = gen.proxy.LivingProxyDb(
dbase,
gen.proxy.LivingProxyDb.MODE_INCLUDE_LAST_NAME_ONLY)
return dbase
def view_person_detail(request, view, handle, action="view"):
context = RequestContext(request)
context["action"] = action
context["view"] = view
context["tview"] = _("Person")
view_template = 'view_person_detail.html'
if request.user.is_authenticated():
person = Person.objects.get(handle=handle)
name = person.name_set.get(preferred=True)
else:
db = get_gramps_db(request)
gramps_person = db.get_person_from_handle(handle)
if not gramps_person:
raise Http404(_("Requested %s is not accessible.") % view)
person = Person.objects.get(handle=handle)
name = person.name_set.get(preferred=True)
# fill forms with data from db
name.surname = gramps_person.get_primary_name().get_surname()
name.first_name = gramps_person.get_primary_name().get_first_name()
pf = PersonForm(instance=person)
pf.model = person
nf = NameForm(instance=name)
nf.model = name
context["personform"] = pf
context["nameform"] = nf
context["person"] = person
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
db = get_gramps_db(request)
search = ""
if view == "event":
if request.user.is_authenticated():
@ -315,9 +336,9 @@ def view(request, view):
view_template = 'view_events.html'
total = Event.objects.all().count()
elif view == "family":
if request.GET.has_key("search"):
search = request.GET.get("search")
if request.user.is_authenticated():
if request.user.is_authenticated():
if request.GET.has_key("search"):
search = request.GET.get("search")
if "," in search:
surname, first = [term.strip() for term in
search.split(",", 1)]
@ -338,8 +359,12 @@ def view(request, view):
Q(mother__name__first_name__istartswith=search)
) \
.order_by("gramps_id")
else:
# NON-AUTHENTICATED users
else: # no search
object_list = Family.objects.all().order_by("gramps_id")
else:
# NON-AUTHENTICATED users
if request.GET.has_key("search"):
search = request.GET.get("search")
if "," in search:
search, trash = [term.strip() for term in search.split(",", 1)]
object_list = Family.objects \
@ -347,15 +372,18 @@ def view(request, view):
Q(family_rel_type__name__icontains=search) |
Q(father__name__surname__istartswith=search) |
Q(mother__name__surname__istartswith=search)) &
Q(private=False)
Q(private=False) &
Q(mother__private=False) &
Q(father__private=False)
) \
.order_by("gramps_id")
else: # no search
if request.user.is_authenticated():
object_list = Family.objects.all().order_by("gramps_id")
else:
# NON-AUTHENTICATED users
object_list = Family.objects.filter(private=False).order_by("gramps_id")
object_list = Family.objects \
.filter(Q(private=False) &
Q(mother__private=False) &
Q(father__private=False)
) \
.order_by("gramps_id")
view_template = 'view_families.html'
total = Family.objects.all().count()
elif view == "media":
@ -395,9 +423,9 @@ def view(request, view):
view_template = 'view_notes.html'
total = Note.objects.all().count()
elif view == "person":
if request.GET.has_key("search"):
search = request.GET.get("search")
if request.user.is_authenticated():
if request.user.is_authenticated():
if request.GET.has_key("search"):
search = request.GET.get("search")
if "," in search:
surname, first_name = [term.strip() for term in
search.split(",", 1)]
@ -417,7 +445,11 @@ def view(request, view):
) \
.order_by("surname", "first_name")
else:
# BEGIN NON-AUTHENTICATED users
object_list = Name.objects.all().order_by("surname", "first_name")
else:
# BEGIN NON-AUTHENTICATED users
if request.GET.has_key("search"):
search = request.GET.get("search")
if "," in search:
search, trash = [term.strip() for term in search.split(",", 1)]
object_list = Name.objects \
@ -426,15 +458,12 @@ def view(request, view):
Q(person__private=False)
) \
.order_by("surname", "first_name")
# END NON-AUTHENTICATED users
else:
if request.user.is_authenticated():
object_list = Name.objects.all().order_by("surname", "first_name")
else:
# BEGIN NON-AUTHENTICATED users
object_list = Name.objects.filter(Q(private=False) &
Q(person__private=False)).order_by("surname", "first_name")
# END NON-AUTHENTICATED users
object_list = Name.objects \
.filter(Q(private=False) &
Q(person__private=False)) \
.order_by("surname", "first_name")
# END NON-AUTHENTICATED users
view_template = 'view_people.html'
total = Name.objects.all().count()
elif view == "place":

View File

@ -67,6 +67,8 @@ urlpatterns += patterns('',
(r'^(?P<view>(\w+))/$', view),
url(r'^person/(?P<handle>(\w+))/$', view_detail,
{"view": "person"}, name="view-person-detail"),
url(r'^person/(?P<handle>(\w+))/(?P<action>(\w+))$', view_detail,
{"view": "person"}, name="view-person-detail"),
(r'^(?P<view>(\w+))/(?P<handle>(\w+))/$', view_detail),
(r'^person/(?P<handle>(\w+))/name/(?P<order>(\w+))$', view_name_detail),
(r'^person/(?P<handle>(\w+))/name/(?P<order>(\w+))/(?P<action>(\w+))$', view_name_detail),

View File

@ -62,17 +62,28 @@ from gen.utils import get_birth_or_fallback, get_death_or_fallback
from gen.plug import BasePluginManager
from cli.grampscli import CLIManager
util_filters = ['person_event_table', 'person_name_table',
'person_attribute_table',
'person_address_table', 'person_note_table',
'person_gallery_table', 'person_internet_table',
'person_association_table', 'person_lds_table',
'person_reference_table',
'family_children_table', 'family_event_table',
'family_attribute_table',
'family_note_table', 'family_gallery_table',
'family_lds_table',
'nbsp', 'render']
util_filters = [
'nbsp',
'render',
]
util_tags = [
"get_person_from_handle",
"event_table",
"name_table",
"source_table",
"note_table",
"attribute_table",
"address_table",
"gallery_table",
"internet_table",
"association_table",
"lds_table",
"reference_table",
"children_table",
"make_button",
]
#------------------------------------------------------------------------
#
# Module Constants
@ -89,6 +100,14 @@ def register_plugins():
pmgr = BasePluginManager.get_instance()
return pmgr
def get_person_from_handle(db, handle):
# db is a Gramps Db interface
# handle is a Person Handle
try:
return db.get_person_from_handle(handle)
except:
return None
def probably_alive(handle):
db = DjangoDb()
person = db.get_person_from_handle(handle)
@ -160,10 +179,11 @@ def render(formfield, action):
retval = formfield.as_widget()
return retval
def make_button(text, url):
return """[<a href="%s">%s</a>]""" % (url, text)
def make_button(text, url, *args):
url = url % args
return """[ <a href="%s">%s</a> ] """ % (url, text)
def person_event_table(djperson, user):
def event_table(obj, user, action, url=None, *args):
retval = ""
table = Table()
table.columns(_("Description"),
@ -173,9 +193,9 @@ def person_event_table(djperson, user):
_("Place"),
_("Role"))
if user.is_authenticated():
obj_type = ContentType.objects.get_for_model(djperson)
obj_type = ContentType.objects.get_for_model(obj)
event_ref_list = models.EventRef.objects.filter(
object_id=djperson.id,
object_id=obj.id,
object_type=obj_type).order_by("order")
event_list = [(obj.ref_object, obj) for obj in event_ref_list]
for (djevent, event_ref) in event_list:
@ -187,12 +207,13 @@ def person_event_table(djperson, user):
get_title(djevent.place),
str(event_ref.role_type))
retval += table.get_html()
if user.is_authenticated():
retval += make_button(_("Add event"), "/person/%s/event/add" % djperson.handle)
if user.is_authenticated() and url and action != "edit":
retval += make_button(_("Add event"), (url + "/add") % args)
else:
retval += nbsp("") # to keep tabs same height
return retval
def person_name_table(djperson, user):
print "person_name_table", djperson, user
def name_table(obj, user, action, url=None, *args):
retval = ""
table = Table()
table.columns(_("Name"),
@ -202,7 +223,7 @@ def person_name_table(djperson, user):
_("Note Preview"))
if user.is_authenticated():
links = []
for name in djperson.name_set.all().order_by("order"):
for name in obj.name_set.all().order_by("order"):
obj_type = ContentType.objects.get_for_model(name)
sourceq = dji.SourceRef.filter(object_type=obj_type,
object_id=name.id).count() > 0
@ -219,12 +240,15 @@ def person_name_table(djperson, user):
name.group_as,
["No", "Yes"][sourceq],
note)
links.append(('URL', "/person/%s/name/%s" %
(name.person.handle, name.order)))
links.append(('URL',
# url is "/person/%s/name"
(url % name.person.handle) + ("/%s" % name.order)))
table.links(links)
retval += table.get_html()
if user.is_authenticated():
retval += make_button(_("Add name"), "/person/%s/name/add" % djperson.handle)
if user.is_authenticated() and url and action != "edit":
retval += make_button(_("Add name"), (url + "/add") % args)
else:
retval += nbsp("") # to keep tabs same height
return retval
def source_table(obj, user, action, url=None, *args):
@ -247,28 +271,56 @@ def source_table(obj, user, action, url=None, *args):
)
retval += table.get_html()
if user.is_authenticated() and url and action != "edit":
retval += make_button(_("Add source"), url % args)
retval += make_button(_("Add source"), (url + "/add") % args)
else:
retval += nbsp("") # to keep tabs same height
return retval
def person_attribute_table(djperson, user):
def note_table(obj, user, action, url=None, *args):
retval = ""
table = Table()
table.columns(
_("ID"),
_("Type"),
_("Note"))
if user.is_authenticated():
obj_type = ContentType.objects.get_for_model(obj)
note_refs = dji.NoteRef.filter(object_type=obj_type,
object_id=obj.id)
for note_ref in note_refs:
note = table.db.get_note_from_handle(
note_ref.ref_object.handle)
table.row(table.db.get_note_from_handle(note.handle),
str(note_ref.ref_object.note_type),
note_ref.ref_object.text[:50])
retval += table.get_html()
if user.is_authenticated() and url and action != "edit":
retval += make_button(_("Add note"), (url + "/add") % args)
else:
retval += nbsp("") # to keep tabs same height
return retval
def attribute_table(obj, user, action, url=None, *args):
retval = ""
table = Table()
table.columns(_("Type"),
_("Value"),
)
if user.is_authenticated():
obj_type = ContentType.objects.get_for_model(djperson)
obj_type = ContentType.objects.get_for_model(obj)
attributes = dji.Attribute.filter(object_type=obj_type,
object_id=djperson.id)
object_id=obj.id)
for attribute in attributes:
table.row(attribute.attribute_type.name,
attribute.value)
retval += table.get_html()
if user.is_authenticated():
retval += make_button(_("Add attribute"), "/person/%s/attribute/add" % djperson.handle)
if user.is_authenticated() and url and action != "edit":
retval += make_button(_("Add attribute"), (url + "/add") % args)
else:
retval += nbsp("") # to keep tabs same height
return retval
def person_address_table(djperson, user):
def address_table(obj, user, action, url=None, *args):
retval = ""
table = Table()
table.columns(_("Date"),
@ -277,7 +329,7 @@ def person_address_table(djperson, user):
_("State"),
_("Country"))
if user.is_authenticated():
for address in djperson.address_set.all().order_by("order"):
for address in obj.address_set.all().order_by("order"):
locations = address.location_set.all().order_by("order")
for location in locations:
table.row(display_date(address),
@ -286,77 +338,63 @@ def person_address_table(djperson, user):
location.state,
location.country)
retval += table.get_html()
if user.is_authenticated():
retval += make_button(_("Add address"), "/person/%s/address/add" % djperson.handle)
if user.is_authenticated() and url and action != "edit":
retval += make_button(_("Add address"), (url + "/add") % args)
else:
retval += nbsp("") # to keep tabs same height
return retval
def person_note_table(djperson, user):
retval = ""
table = Table()
table.columns(
_("ID"),
_("Type"),
_("Note"))
if user.is_authenticated():
obj_type = ContentType.objects.get_for_model(djperson)
note_refs = dji.NoteRef.filter(object_type=obj_type,
object_id=djperson.id)
for note_ref in note_refs:
note = table.db.get_note_from_handle(
note_ref.ref_object.handle)
table.row(table.db.get_note_from_handle(note.handle),
str(note_ref.ref_object.note_type),
note_ref.ref_object.text[:50])
retval += table.get_html()
if user.is_authenticated():
retval += make_button(_("Add note"), "/person/%s/note/add" % djperson.handle)
return retval
def person_gallery_table(djperson, user):
def gallery_table(obj, user, action, url=None, *args):
retval = ""
table = Table()
table.columns(_("Name"),
_("Type"),
)
retval += table.get_html()
if user.is_authenticated():
retval += make_button(_("Add gallery"), "/person/%s/gallery/add" % djperson.handle)
if user.is_authenticated() and url and action != "edit":
retval += make_button(_("Add gallery"), (url + "/add") % args)
else:
retval += nbsp("") # to keep tabs same height
return retval
def person_internet_table(djperson, user):
def internet_table(obj, user, action, url=None, *args):
retval = ""
table = Table()
table.columns(_("Type"),
_("Path"),
_("Description"))
if user.is_authenticated():
urls = dji.Url.filter(person=djperson)
urls = dji.Url.filter(person=obj)
for url in urls:
table.row(str(url.url_type),
url.path,
url.desc)
retval += table.get_html()
if user.is_authenticated():
retval += make_button(_("Add internet"), "/person/%s/internet/add" % djperson.handle)
if user.is_authenticated() and url and action != "edit":
retval += make_button(_("Add internet"), (url + "/add") % args)
else:
retval += nbsp("") # to keep tabs same height
return retval
def person_association_table(djperson, user):
def association_table(obj, user, action, url=None, *args):
retval = ""
table = Table()
table.columns(_("Name"),
_("ID"),
_("Association"))
if user.is_authenticated():
gperson = table.db.get_person_from_handle(djperson.handle)
gperson = table.db.get_person_from_handle(obj.handle)
associations = gperson.get_person_ref_list()
for association in associations:
table.row()
retval += table.get_html()
if user.is_authenticated():
retval += make_button(_("Add association"), "/person/%s/association/add" % djperson.handle)
if user.is_authenticated() and url and action != "edit":
retval += make_button(_("Add association"), (url + "/add") % args)
else:
retval += nbsp("") # to keep tabs same height
return retval
def person_lds_table(djperson, user):
def lds_table(obj, user, action, url=None, *args):
retval = ""
table = Table()
table.columns(_("Type"),
@ -365,8 +403,8 @@ def person_lds_table(djperson, user):
_("Temple"),
_("Place"))
if user.is_authenticated():
obj_type = ContentType.objects.get_for_model(djperson)
ldss = djperson.lds_set.all().order_by("order")
obj_type = ContentType.objects.get_for_model(obj)
ldss = obj.lds_set.all().order_by("order")
for lds in ldss:
table.row(str(lds.lds_type),
display_date(lds),
@ -374,25 +412,29 @@ def person_lds_table(djperson, user):
lds.temple,
get_title(lds.place))
retval += table.get_html()
if user.is_authenticated():
retval += make_button(_("Add LDS"), "/person/%s/lds/add" % djperson.handle)
if user.is_authenticated() and url and action != "edit":
retval += make_button(_("Add LDS"), (url + "/add") % args)
else:
retval += nbsp("") # to keep tabs same height
return retval
def person_reference_table(djperson, user):
def reference_table(obj, user, action, url=None, *args):
retval = ""
table = Table()
table.columns(_("Type"),
_("ID"),
_("Name"))
if user.is_authenticated():
references = dji.PersonRef.filter(ref_object=djperson)
references = dji.PersonRef.filter(ref_object=obj)
for reference in references:
table.row(str(reference.ref_object),
reference.ref_object.gramps_id,
make_name(reference.ref_object.name_set, user))
return table.get_html()
retval += table.get_html()
retval += nbsp("") # to keep tabs same height
return retval
def family_children_table(djfamily, user):
def children_table(obj, user, action, url=None, *args):
retval = ""
table = Table()
table.columns(
@ -407,74 +449,7 @@ def family_children_table(djfamily, user):
#if user.is_authenticated():
#for djfamily:
# table.row("test")
return table.get_html()
def family_event_table(djfamily, user):
retval = ""
table = Table()
table.columns(
_("Description"),
_("Type"),
_("ID"),
_("Date"),
_("Place"),
_("Role"),
)
table.row("test")
return table.get_html()
def family_source_table(djfamily, user):
retval = ""
table = Table()
table.columns(
_("ID"),
_("Type"),
_("Author"),
_("Page"),
)
table.row("test")
return table.get_html()
def family_attribute_table(djfamily, user):
retval = ""
table = Table()
table.columns(
_("Type"),
_("Value"),
)
table.row("test")
return table.get_html()
def family_note_table(djfamily, user):
retval = ""
table = Table()
table.columns(
_("Type"),
_("Preview"),
)
table.row("test")
return table.get_html()
def family_gallery_table(djfamily, user):
retval = ""
table = Table()
table.columns(
_("Column"),
)
table.row("test")
return table.get_html()
def family_lds_table(djfamily, user):
retval = ""
table = Table()
table.columns(
_("Type"),
_("Date"),
_("Status"),
_("Temple"),
_("Place"),
)
table.row("test")
retval += nbsp("") # to keep tabs same height
return table.get_html()
## FIXME: these dji function wrappers just use the functions
@ -488,14 +463,14 @@ def get_title(place):
def person_get_birth_date(person):
db = DjangoDb()
event = get_birth_or_fallback(db, person)
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, person)
event = get_death_or_fallback(db, db.get_person_from_handle(person.handle))
if event:
return event.date
return None
@ -530,7 +505,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=None):
def make_name(name, user):
if isinstance(name, models.Name):
surname = name.surname.strip()
if not surname:
@ -560,6 +535,9 @@ def make_name(name, user=None):
return "[No preferred name]"
else:
return "%s, %s" % (name.get_surname(), name.get_first_name())
elif isinstance(name, models.Person): # django person
person = name
return make_name(person.name_set.get(preferred=True), user)
else: # no name
return ""