Added functionality to add person to existing/new family as spouse/child

svn: r20040
This commit is contained in:
Doug Blank 2012-07-21 17:43:20 +00:00
parent d944dc918f
commit 685641ec27
5 changed files with 95 additions and 18 deletions

View File

@ -41,7 +41,7 @@
<td class="ColumnValue" id="data">{{family.father|render_name:user}}</td>
{% endif %}
<td class="ColumnAttribute">Name:</td>
{% if user.is_authenticated or mother.probably_alive %}
{% if user.is_authenticated or family.mother.probably_alive %}
<td class="ColumnValue" id="data">{% render familyform.mother user action %}</td>
{% else %}
<td class="ColumnValue" id="data">{{family.mother|render_name:user}}</td>

View File

@ -22,7 +22,7 @@
""" Views for Person, Name, and Surname """
## Gramps Modules
from webapp.utils import _, boolean, update_last_changed
from webapp.utils import _, boolean, update_last_changed, build_search
from webapp.grampsdb.models import Family
from webapp.grampsdb.forms import *
from webapp.libdjango import DjangoInterface
@ -47,12 +47,67 @@ def process_family(request, context, handle, act, add_to=None): # view, edit, sa
if request.POST.has_key("action"):
act = request.POST.get("action")
# Handle: edit, view, add, create, save, delete
if act == "add":
# Handle: edit, view, add, create, save, delete, share, save-share
if act == "share":
# Adds a person to an existing family
item, handle = add_to
context["pickform"] = PickForm("Pick family",
Family,
(),
request.POST)
context["object_handle"] = handle
context["object_type"] = "person"
return render_to_response("pick.html", context)
elif act == "save-share":
item, handle = add_to
pickform = PickForm("Pick family",
Family,
(),
request.POST)
if pickform.data["picklist"]:
person = Person.objects.get(handle=handle) # to add
ref_handle = pickform.data["picklist"]
ref_obj = Family.objects.get(handle=ref_handle)
if item == "child":
dji.add_child_ref_default(ref_obj, person) # add person to family
person.parent_families.add(ref_obj) # add family to child
elif item == "spouse":
if person.gender_type.name == "Female":
ref_obj.mother = person
elif person.gender_type.name == "Male":
ref_obj.father = person
else:
ref_obj.father = person # FIXME: Unknown gender, add to open
person.families.add(ref_obj) # add family to person
ref_obj.save()
person.save()
dji.rebuild_cache(person) # rebuild child
dji.rebuild_cache(ref_obj) # rebuild cache
return redirect("/%s/%s%s#tab-references" % ("person", handle, build_search(request)))
else:
context["pickform"] = pickform
context["object_handle"] = handle
context["object_type"] = "person"
return render_to_response("pick.html", context)
elif act == "add":
family = Family(
gramps_id=dji.get_next_id(Family, "F"),
family_rel_type=FamilyRelType.objects.get(
val=FamilyRelType._DEFAULT[0]))
if add_to:
what, phandle = add_to
person = Person.objects.get(handle=phandle)
gender = person.gender_type.name # Male, Female, Unknown
if what == "spouse":
if gender == "Male":
family.father = person
elif gender == "Female":
family.mother = person
elif what == "child":
pass # FIXME: can't show child in table?
# Table from children_table
else: # unknown gender!
family.father = person
familyform = FamilyForm(instance=family)
familyform.model = family
elif act in ["view", "edit"]:
@ -96,13 +151,25 @@ def process_family(request, context, handle, act, add_to=None): # view, edit, sa
if family not in family.father.families.all():
family.father.families.add(family)
dji.rebuild_cache(family)
if add_to: # FIXME: add family to... what??
if add_to: # add child or spouse to family
item, handle = add_to
model = dji.get_model(item)
obj = model.objects.get(handle=handle)
dji.add_family_ref(obj, family.handle)
dji.rebuild_cache(obj)
return redirect("/%s/%s" % (item, handle))
person = Person.objects.get(handle=handle)
if item == "child":
dji.add_child_ref_default(family, person) # add person to family
person.parent_families.add(family) # add family to child
elif item == "spouse":
if person.gender_type.name == "Female":
family.mother = person
elif person.gender_type.name == "Male":
family.father = person
else:
family.father = person # FIXME: Unknown gender, add to open
person.families.add(family) # add family to person
family.save()
person.save()
dji.rebuild_cache(person) # rebuild child
dji.rebuild_cache(family) # rebuild cache
return redirect("/%s/%s" % ("person", handle))
act = "view"
else:
act = "add"

View File

@ -429,6 +429,7 @@ def add_to(request, view, item, handle):
Add a new <view> referenced from <item>.
"""
# /view/add/person/handle
# /family/add/child/handle
return action(request, view, None, "add", (item, handle))
def action(request, view, handle, act, add_to=None):

View File

@ -68,19 +68,21 @@ urlpatterns += patterns('',
(r'^browse/$', browse_page),
(r'^login/$', 'django.contrib.auth.views.login'),
(r'^logout/$', logout_page),
(r'^(?P<view>(\w+))/$', view_list), # /view/
(r'^(?P<view>(\w+))/add$', action,
(r'^(?P<view>(\w+))/$',
view_list), # /view/
(r'^(?P<view>(\w+))/add$',
action,
{"handle": None, "act": "add"}), # /view/add
(r'^(?P<view>(\w+))/add/(?P<item>(\w+))/(?P<handle>(\w+))$',
add_to), # /view/add/item/handle
add_to), # /view/add/item/handle
(r'^(?P<view>(\w+))/share/(?P<item>(\w+))/(?P<handle>(\w+))$',
add_share), # /view/share/item/handle
add_share), # /view/share/item/handle
(r'^(?P<view>(\w+))/(?P<handle>(\w+))/$', action,
{"act": "view"}), # /view/handle/
{"act": "view"}), # /view/handle/
(r'^(?P<view>(\w+))/(?P<handle>(\w+))/(?P<act>(\w+))$',
action), # /view/handle/action
action), # /view/handle/action
(r'^(?P<ref_by>(\w+))/(?P<handle>(\w+))/reference/(?P<ref_to>(\w+))/(?P<order>(\w+))$',
process_reference), # /view/handle/reference/item/order
process_reference), # /view/handle/reference/item/order
(r'^person/(?P<handle>(\w+))/name/(?P<order>(\w+))$', process_name),
(r'^person/(?P<handle>(\w+))/name/(?P<order>(\w+))/(?P<act>(\w+))$',
process_name),

View File

@ -674,7 +674,14 @@ def person_reference_table(obj, user, act):
reference,
reference.gramps_id)
retval += table.get_html()
retval += nbsp("") # to keep tabs same height
retval += make_button(_("Add as Spouse to New Family"),
"/family/add/spouse/%s" % obj.handle)
retval += make_button(_("Add as Spouse to Existing Family"),
"/family/share/spouse/%s" % obj.handle)
retval += make_button(_("Add as Child to New Family"),
"/family/add/child/%s" % obj.handle)
retval += make_button(_("Add as Child to Existing Family"),
"/family/share/child/%s" % obj.handle)
return retval
def note_reference_table(obj, user, act):