Added functionality to add person to existing/new family as spouse/child
svn: r20040
This commit is contained in:
parent
d944dc918f
commit
685641ec27
@ -41,7 +41,7 @@
|
|||||||
<td class="ColumnValue" id="data">{{family.father|render_name:user}}</td>
|
<td class="ColumnValue" id="data">{{family.father|render_name:user}}</td>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<td class="ColumnAttribute">Name:</td>
|
<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>
|
<td class="ColumnValue" id="data">{% render familyform.mother user action %}</td>
|
||||||
{% else %}
|
{% else %}
|
||||||
<td class="ColumnValue" id="data">{{family.mother|render_name:user}}</td>
|
<td class="ColumnValue" id="data">{{family.mother|render_name:user}}</td>
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
""" Views for Person, Name, and Surname """
|
""" Views for Person, Name, and Surname """
|
||||||
|
|
||||||
## Gramps Modules
|
## 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.models import Family
|
||||||
from webapp.grampsdb.forms import *
|
from webapp.grampsdb.forms import *
|
||||||
from webapp.libdjango import DjangoInterface
|
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"):
|
if request.POST.has_key("action"):
|
||||||
act = request.POST.get("action")
|
act = request.POST.get("action")
|
||||||
|
|
||||||
# Handle: edit, view, add, create, save, delete
|
# Handle: edit, view, add, create, save, delete, share, save-share
|
||||||
if act == "add":
|
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(
|
family = Family(
|
||||||
gramps_id=dji.get_next_id(Family, "F"),
|
gramps_id=dji.get_next_id(Family, "F"),
|
||||||
family_rel_type=FamilyRelType.objects.get(
|
family_rel_type=FamilyRelType.objects.get(
|
||||||
val=FamilyRelType._DEFAULT[0]))
|
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 = FamilyForm(instance=family)
|
||||||
familyform.model = family
|
familyform.model = family
|
||||||
elif act in ["view", "edit"]:
|
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():
|
if family not in family.father.families.all():
|
||||||
family.father.families.add(family)
|
family.father.families.add(family)
|
||||||
dji.rebuild_cache(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
|
item, handle = add_to
|
||||||
model = dji.get_model(item)
|
person = Person.objects.get(handle=handle)
|
||||||
obj = model.objects.get(handle=handle)
|
if item == "child":
|
||||||
dji.add_family_ref(obj, family.handle)
|
dji.add_child_ref_default(family, person) # add person to family
|
||||||
dji.rebuild_cache(obj)
|
person.parent_families.add(family) # add family to child
|
||||||
return redirect("/%s/%s" % (item, handle))
|
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"
|
act = "view"
|
||||||
else:
|
else:
|
||||||
act = "add"
|
act = "add"
|
||||||
|
@ -429,6 +429,7 @@ def add_to(request, view, item, handle):
|
|||||||
Add a new <view> referenced from <item>.
|
Add a new <view> referenced from <item>.
|
||||||
"""
|
"""
|
||||||
# /view/add/person/handle
|
# /view/add/person/handle
|
||||||
|
# /family/add/child/handle
|
||||||
return action(request, view, None, "add", (item, handle))
|
return action(request, view, None, "add", (item, handle))
|
||||||
|
|
||||||
def action(request, view, handle, act, add_to=None):
|
def action(request, view, handle, act, add_to=None):
|
||||||
|
@ -68,8 +68,10 @@ urlpatterns += patterns('',
|
|||||||
(r'^browse/$', browse_page),
|
(r'^browse/$', browse_page),
|
||||||
(r'^login/$', 'django.contrib.auth.views.login'),
|
(r'^login/$', 'django.contrib.auth.views.login'),
|
||||||
(r'^logout/$', logout_page),
|
(r'^logout/$', logout_page),
|
||||||
(r'^(?P<view>(\w+))/$', view_list), # /view/
|
(r'^(?P<view>(\w+))/$',
|
||||||
(r'^(?P<view>(\w+))/add$', action,
|
view_list), # /view/
|
||||||
|
(r'^(?P<view>(\w+))/add$',
|
||||||
|
action,
|
||||||
{"handle": None, "act": "add"}), # /view/add
|
{"handle": None, "act": "add"}), # /view/add
|
||||||
(r'^(?P<view>(\w+))/add/(?P<item>(\w+))/(?P<handle>(\w+))$',
|
(r'^(?P<view>(\w+))/add/(?P<item>(\w+))/(?P<handle>(\w+))$',
|
||||||
add_to), # /view/add/item/handle
|
add_to), # /view/add/item/handle
|
||||||
|
@ -674,7 +674,14 @@ def person_reference_table(obj, user, act):
|
|||||||
reference,
|
reference,
|
||||||
reference.gramps_id)
|
reference.gramps_id)
|
||||||
retval += table.get_html()
|
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
|
return retval
|
||||||
|
|
||||||
def note_reference_table(obj, user, act):
|
def note_reference_table(obj, user, act):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user