Family main fields editing complete
svn: r19643
This commit is contained in:
parent
961a35b529
commit
394f9f9d12
@ -19,14 +19,8 @@
|
|||||||
<div id="summaryarea">
|
<div id="summaryarea">
|
||||||
<table class="infolist" style="width:90%;"> {% comment %} 4 cols {% endcomment %}
|
<table class="infolist" style="width:90%;"> {% comment %} 4 cols {% endcomment %}
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for error in personform.errors %}
|
{% for error in familyform.errors %}
|
||||||
<p id="error">Error in person: {{error}}</p>
|
<p id="error">Error in family: {{error}}</p>
|
||||||
{% endfor %}
|
|
||||||
{% for error in nameform.errors %}
|
|
||||||
<p id="error">Error in name: {{error}}</p>
|
|
||||||
{% endfor %}
|
|
||||||
{% for error in surnameform.errors %}
|
|
||||||
<p id="error">Error in surname: {{error}}</p>
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
<form method="post">{% csrf_token %}
|
<form method="post">{% csrf_token %}
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -125,4 +125,4 @@ class SurnameForm(forms.ModelForm):
|
|||||||
class FamilyForm(forms.ModelForm):
|
class FamilyForm(forms.ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Family
|
model = Family
|
||||||
|
exclude = ["handle"]
|
||||||
|
@ -47,11 +47,43 @@ def process_family(request, context, handle, action): # view, edit, save
|
|||||||
if request.POST.has_key("action"):
|
if request.POST.has_key("action"):
|
||||||
action = request.POST.get("action")
|
action = request.POST.get("action")
|
||||||
|
|
||||||
family = Family(father=Person.objects.all()[0],
|
# Handle: edit, view, add, create, save, delete
|
||||||
family_rel_type=FamilyRelType.objects.get(
|
if action == "add":
|
||||||
|
family = Family(family_rel_type=FamilyRelType.objects.get(
|
||||||
val=FamilyRelType._DEFAULT[0]))
|
val=FamilyRelType._DEFAULT[0]))
|
||||||
familyform = FamilyForm(instance=family)
|
familyform = FamilyForm(instance=family)
|
||||||
familyform.model = 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["familyform"] = familyform
|
||||||
context["object"] = family
|
context["object"] = family
|
||||||
|
Loading…
Reference in New Issue
Block a user