diff --git a/src/data/templates/view_family_detail.html b/src/data/templates/view_family_detail.html index d62732aa0..acbe63205 100644 --- a/src/data/templates/view_family_detail.html +++ b/src/data/templates/view_family_detail.html @@ -19,14 +19,8 @@
{% comment %} 4 cols {% endcomment %} - {% for error in personform.errors %} -

Error in person: {{error}}

- {% endfor %} - {% for error in nameform.errors %} -

Error in name: {{error}}

- {% endfor %} - {% for error in surnameform.errors %} -

Error in surname: {{error}}

+ {% for error in familyform.errors %} +

Error in family: {{error}}

{% endfor %} {% csrf_token %} diff --git a/src/webapp/grampsdb/forms.py b/src/webapp/grampsdb/forms.py index 3b9515380..b7b6843f2 100644 --- a/src/webapp/grampsdb/forms.py +++ b/src/webapp/grampsdb/forms.py @@ -125,4 +125,4 @@ class SurnameForm(forms.ModelForm): class FamilyForm(forms.ModelForm): class Meta: model = Family - + exclude = ["handle"] diff --git a/src/webapp/grampsdb/view/family.py b/src/webapp/grampsdb/view/family.py index 2a9749978..986b36d16 100644 --- a/src/webapp/grampsdb/view/family.py +++ b/src/webapp/grampsdb/view/family.py @@ -46,12 +46,44 @@ def process_family(request, context, handle, action): # view, edit, save action = "add" if request.POST.has_key("action"): action = request.POST.get("action") - - family = Family(father=Person.objects.all()[0], - family_rel_type=FamilyRelType.objects.get( - val=FamilyRelType._DEFAULT[0])) - familyform = FamilyForm(instance=family) - familyform.model = family + + # Handle: edit, view, add, create, save, delete + if action == "add": + family = Family(family_rel_type=FamilyRelType.objects.get( + val=FamilyRelType._DEFAULT[0])) + familyform = FamilyForm(instance=family) + familyform.model = family + elif action in ["view", "edit"]: + family = Family.objects.get(handle=handle) + familyform = FamilyForm(instance=family) + familyform.model = family + elif action == "save": + family = Family.objects.get(handle=handle) + familyform = FamilyForm(request.POST, instance=family) + familyform.model = family + if familyform.is_valid(): + familyform.save() + action = "view" + else: + action = "edit" + elif action == "create": + family = Family(family_rel_type=FamilyRelType.objects.get( + val=FamilyRelType._DEFAULT[0]), + handle=create_id()) + familyform = FamilyForm(request.POST, instance=family) + familyform.model = family + familyform.handle = create_id() + if familyform.is_valid(): + familyform.save() + action = "view" + else: + action = "add" + elif action == "delete": + family = Family.objects.get(handle=handle) + family.delete() + return redirect("/family/") + else: + raise Exception("Unhandled action: '%s'" % action) context["familyform"] = familyform context["object"] = family