Adding Children to Families now working

svn: r19828
This commit is contained in:
Doug Blank 2012-06-12 01:13:26 +00:00
parent e3b5f6b3a5
commit dd50e437f7
6 changed files with 26 additions and 11 deletions

View File

@ -106,7 +106,7 @@
</ul>
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom" id="tab-children">
<!-- Events -->
{% children_table family user action "/family/%s/children/$act" family.handle %}
{% children_table family user action "/person/$act/family/%s" family.handle %}
</div>
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tab-events">
{% event_table family user action "/event/$act/family/%s" family.handle %}

View File

@ -854,7 +854,7 @@ class RepositoryRef(BaseRef):
class PersonRef(BaseRef):
ref_object = models.ForeignKey('Person')
description = models.CharField(max_length=50)
description = models.CharField(max_length=50, blank=True, null=True)
def __unicode__(self):
return "PersonRef to " + str(self.ref_object)

View File

@ -351,7 +351,7 @@ def process_person(request, context, handle, action, add_to=None): # view, edit,
return redirect("/person/%s" % build_search(request))
elif action in ["save", "create"]: # could be create a new person
# look up old data, if any:
if handle:
if handle:
person = Person.objects.get(handle=handle)
name = person.name_set.get(preferred=True)
surname = name.surname_set.get(primary=True)
@ -391,13 +391,16 @@ def process_person(request, context, handle, action, add_to=None): # view, edit,
surname.prefix = sf.cleaned_data["prefix"] if sf.cleaned_data["prefix"] != " prefix " else ""
surname.primary = True # FIXME: why is this False? Remove from form?
surname.save()
dji.rebuild_cache(person)
if add_to:
item, handle = add_to
model = dji.get_model(item)
obj = model.objects.get(handle=handle)
dji.add_person_ref_default(obj, person)
if add_to: # Adding a child to the family
item, handle = add_to # ("Family", handle)
model = dji.get_model(item) # what model?
obj = model.objects.get(handle=handle) # get family
dji.add_child_ref_default(obj, person) # add person to family
person.parent_familes.add(obj) # add family to child
dji.rebuild_cache(person) # rebuild child
dji.rebuild_cache(obj) # rebuild family
return redirect("/%s/%s%s" % (item, handle, build_search(request)))
dji.rebuild_cache(person)
return redirect("/person/%s%s" % (person.handle, build_search(request)))
else:
# need to edit again

View File

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

View File

@ -879,6 +879,17 @@ class DjangoInterface(object):
self.add_media_ref_list(citation, media_list)
self.add_citation_datamap_dict(citation, datamap)
def add_child_ref_default(self, obj, child, frel=1, mrel=1, private=False):
object_type = ContentType.objects.get_for_model(obj) # obj is family
count = models.ChildRef.objects.filter(object_id=obj.id,object_type=object_type).count()
child_ref = models.ChildRef(private=private,
referenced_by=obj,
ref_object=child,
order=count + 1,
father_rel_type=models.get_type(models.ChildRefType, frel), # birth
mother_rel_type=models.get_type(models.ChildRefType, mrel))
child_ref.save()
def add_child_ref(self, obj, data):
(private, citation_list, note_list, ref, frel, mrel) = data
try:

View File

@ -840,7 +840,8 @@ def children_table(obj, user, action, url=None, *args):
table.links(links)
retval += table.get_html()
if user.is_superuser and url and action == "view":
retval += make_button(_("Add Child"), (url % args))
retval += make_button(_("Add Child"), (url.replace("$act", "add") % args))
retval += make_button(_("Share Child"), (url.replace("$act", "share") % args))
else:
retval += nbsp("") # to keep tabs same height
return retval