Adding Children to Families now working
svn: r19828
This commit is contained in:
parent
e3b5f6b3a5
commit
dd50e437f7
@ -106,7 +106,7 @@
|
|||||||
</ul>
|
</ul>
|
||||||
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom" id="tab-children">
|
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom" id="tab-children">
|
||||||
<!-- Events -->
|
<!-- 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>
|
||||||
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tab-events">
|
<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 %}
|
{% event_table family user action "/event/$act/family/%s" family.handle %}
|
||||||
|
@ -854,7 +854,7 @@ class RepositoryRef(BaseRef):
|
|||||||
|
|
||||||
class PersonRef(BaseRef):
|
class PersonRef(BaseRef):
|
||||||
ref_object = models.ForeignKey('Person')
|
ref_object = models.ForeignKey('Person')
|
||||||
description = models.CharField(max_length=50)
|
description = models.CharField(max_length=50, blank=True, null=True)
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return "PersonRef to " + str(self.ref_object)
|
return "PersonRef to " + str(self.ref_object)
|
||||||
|
@ -351,7 +351,7 @@ def process_person(request, context, handle, action, add_to=None): # view, edit,
|
|||||||
return redirect("/person/%s" % build_search(request))
|
return redirect("/person/%s" % build_search(request))
|
||||||
elif action in ["save", "create"]: # could be create a new person
|
elif action in ["save", "create"]: # could be create a new person
|
||||||
# look up old data, if any:
|
# look up old data, if any:
|
||||||
if handle:
|
if handle:
|
||||||
person = Person.objects.get(handle=handle)
|
person = Person.objects.get(handle=handle)
|
||||||
name = person.name_set.get(preferred=True)
|
name = person.name_set.get(preferred=True)
|
||||||
surname = name.surname_set.get(primary=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.prefix = sf.cleaned_data["prefix"] if sf.cleaned_data["prefix"] != " prefix " else ""
|
||||||
surname.primary = True # FIXME: why is this False? Remove from form?
|
surname.primary = True # FIXME: why is this False? Remove from form?
|
||||||
surname.save()
|
surname.save()
|
||||||
dji.rebuild_cache(person)
|
if add_to: # Adding a child to the family
|
||||||
if add_to:
|
item, handle = add_to # ("Family", handle)
|
||||||
item, handle = add_to
|
model = dji.get_model(item) # what model?
|
||||||
model = dji.get_model(item)
|
obj = model.objects.get(handle=handle) # get family
|
||||||
obj = model.objects.get(handle=handle)
|
dji.add_child_ref_default(obj, person) # add person to family
|
||||||
dji.add_person_ref_default(obj, person)
|
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)))
|
return redirect("/%s/%s%s" % (item, handle, build_search(request)))
|
||||||
|
dji.rebuild_cache(person)
|
||||||
return redirect("/person/%s%s" % (person.handle, build_search(request)))
|
return redirect("/person/%s%s" % (person.handle, build_search(request)))
|
||||||
else:
|
else:
|
||||||
# need to edit again
|
# need to edit again
|
||||||
|
@ -423,7 +423,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
|
||||||
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):
|
def action(request, view, handle, action, add_to=None):
|
||||||
"""
|
"""
|
||||||
|
@ -879,6 +879,17 @@ class DjangoInterface(object):
|
|||||||
self.add_media_ref_list(citation, media_list)
|
self.add_media_ref_list(citation, media_list)
|
||||||
self.add_citation_datamap_dict(citation, datamap)
|
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):
|
def add_child_ref(self, obj, data):
|
||||||
(private, citation_list, note_list, ref, frel, mrel) = data
|
(private, citation_list, note_list, ref, frel, mrel) = data
|
||||||
try:
|
try:
|
||||||
|
@ -840,7 +840,8 @@ def children_table(obj, user, action, url=None, *args):
|
|||||||
table.links(links)
|
table.links(links)
|
||||||
retval += table.get_html()
|
retval += table.get_html()
|
||||||
if user.is_superuser and url and action == "view":
|
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:
|
else:
|
||||||
retval += nbsp("") # to keep tabs same height
|
retval += nbsp("") # to keep tabs same height
|
||||||
return retval
|
return retval
|
||||||
|
Loading…
Reference in New Issue
Block a user