Family main fields editing complete
svn: r19643
This commit is contained in:
parent
961a35b529
commit
394f9f9d12
@ -19,14 +19,8 @@
|
||||
<div id="summaryarea">
|
||||
<table class="infolist" style="width:90%;"> {% comment %} 4 cols {% endcomment %}
|
||||
<tbody>
|
||||
{% for error in personform.errors %}
|
||||
<p id="error">Error in person: {{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>
|
||||
{% for error in familyform.errors %}
|
||||
<p id="error">Error in family: {{error}}</p>
|
||||
{% endfor %}
|
||||
<form method="post">{% csrf_token %}
|
||||
<tr>
|
||||
|
@ -125,4 +125,4 @@ class SurnameForm(forms.ModelForm):
|
||||
class FamilyForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Family
|
||||
|
||||
exclude = ["handle"]
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user