Editing of Person, Name, and surname is nearly complete (need to fix adding second name)
svn: r19633
This commit is contained in:
parent
50773ebd51
commit
48ef83fbcc
@ -117,6 +117,10 @@
|
|||||||
value="Back to Person"
|
value="Back to Person"
|
||||||
onclick="document.location.href='/person/{{person.handle}}'"/>
|
onclick="document.location.href='/person/{{person.handle}}'"/>
|
||||||
{% if user.is_authenticated %}
|
{% if user.is_authenticated %}
|
||||||
|
{% ifequal action "add" %}
|
||||||
|
<input type="hidden" name="action" value="create"/>
|
||||||
|
<input type="submit" value="Create"/>
|
||||||
|
{% else %}
|
||||||
{% ifequal action "edit" %}
|
{% ifequal action "edit" %}
|
||||||
<input type="hidden" name="action" value="save"/>
|
<input type="hidden" name="action" value="save"/>
|
||||||
<input type="submit" value="Save"/>
|
<input type="submit" value="Save"/>
|
||||||
@ -131,6 +135,7 @@
|
|||||||
value="Delete Name"
|
value="Delete Name"
|
||||||
onclick="document.location.href='/person/{{person.handle}}/name/{{order}}/delete'"/>
|
onclick="document.location.href='/person/{{person.handle}}/name/{{order}}/delete'"/>
|
||||||
{% endifequal %}
|
{% endifequal %}
|
||||||
|
{% endifequal %}
|
||||||
{% else %}
|
{% else %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</form>
|
</form>
|
||||||
|
@ -136,7 +136,7 @@
|
|||||||
{% ifequal action "add" %}
|
{% ifequal action "add" %}
|
||||||
{% make_button "Cancel" "/person/" %}
|
{% make_button "Cancel" "/person/" %}
|
||||||
<input type="hidden" name="action" value="create"/>
|
<input type="hidden" name="action" value="create"/>
|
||||||
<input type="submit" value="Add Person"/>
|
<input type="submit" value="Create"/>
|
||||||
{% else %}
|
{% else %}
|
||||||
{% make_button "Back to People" "/person" %}
|
{% make_button "Back to People" "/person" %}
|
||||||
{% make_button "Add Person" "/person/add" %}
|
{% make_button "Add Person" "/person/add" %}
|
||||||
|
@ -21,14 +21,9 @@
|
|||||||
<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 form.errors %}
|
||||||
{% if user.is_authenticated %}
|
<p id="error">{{error}}</p>
|
||||||
{% ifequal action "edit" %}
|
{% endfor %}
|
||||||
{% for error in form.errors %}
|
|
||||||
{{error}}<br>
|
|
||||||
{% endfor %}
|
|
||||||
{% endifequal %}
|
|
||||||
{% endif %}
|
|
||||||
<form method="post">{% csrf_token %}
|
<form method="post">{% csrf_token %}
|
||||||
<tr>
|
<tr>
|
||||||
<td class="ColumnAttribute">{{surnameform.name_origin_type.label}}:</td>
|
<td class="ColumnAttribute">{{surnameform.name_origin_type.label}}:</td>
|
||||||
@ -67,23 +62,34 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% if user.is_authenticated %}
|
{% if user.is_authenticated %}
|
||||||
{% ifequal action "edit" %}
|
{% if action == "edit" %}
|
||||||
<input type="hidden" name="action" value="save"/>
|
|
||||||
<input type="submit" value="Save">
|
|
||||||
<input type="button"
|
<input type="button"
|
||||||
value="Cancel"
|
value="Cancel"
|
||||||
onclick="document.location.href='/person/{{person.handle}}/name/{{order}}/surname/{{sorder}}'"/>
|
onclick="document.location.href='/person/{{person.handle}}/name/{{order}}/surname/{{sorder}}'"/>
|
||||||
{% else %}
|
<input type="hidden" name="action" value="save"/>
|
||||||
|
<input type="submit" value="Save">
|
||||||
|
{% else %}
|
||||||
|
{% if action == "add" %}
|
||||||
<input type="button"
|
<input type="button"
|
||||||
value="Edit Surname"
|
value="Cancel"
|
||||||
onclick="document.location.href='/person/{{person.handle}}/name/{{order}}/surname/{{sorder}}/edit'"/>
|
onclick="document.location.href='/person/{{person.handle}}/name/{{order}}/surname/{{sorder}}'"/>
|
||||||
|
<input type="hidden" name="action" value="create"/>
|
||||||
|
<input type="submit" value="Save">
|
||||||
|
{% else %}
|
||||||
<input type="button"
|
<input type="button"
|
||||||
value="Back to Person"
|
value="Back to Person"
|
||||||
onclick="document.location.href='/person/{{person.handle}}'"/>
|
onclick="document.location.href='/person/{{person.handle}}'"/>
|
||||||
<input type="button"
|
<input type="button"
|
||||||
value="Back to Name"
|
value="Back to Name"
|
||||||
onclick="document.location.href='/person/{{person.handle}}/name/order'"/>
|
onclick="document.location.href='/person/{{person.handle}}/name/{{order}}'"/>
|
||||||
{% endifequal %}
|
<input type="button"
|
||||||
|
value="Edit Surname"
|
||||||
|
onclick="document.location.href='/person/{{person.handle}}/name/{{order}}/surname/{{sorder}}/edit'"/>
|
||||||
|
<input type="button"
|
||||||
|
value="Delete Surname"
|
||||||
|
onclick="document.location.href='/person/{{person.handle}}/name/{{order}}/surname/{{sorder}}/delete'"/>
|
||||||
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
{% else %}
|
{% else %}
|
||||||
<input type="button"
|
<input type="button"
|
||||||
value="Back to Person"
|
value="Back to Person"
|
||||||
|
@ -19,7 +19,16 @@
|
|||||||
# $Id$
|
# $Id$
|
||||||
#
|
#
|
||||||
|
|
||||||
""" Main view handlers """
|
"""
|
||||||
|
Main view handlers
|
||||||
|
Each object can be operated on with the following actions:
|
||||||
|
view: show the data
|
||||||
|
delete: delete the object (FIXME: needs undo)
|
||||||
|
edit: show the data in its editing widget
|
||||||
|
save: action in the form in edit mode; write data to db
|
||||||
|
add: show blank data in their editing widget
|
||||||
|
create: action in the form in edit mode; add new data to db
|
||||||
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import cPickle
|
import cPickle
|
||||||
@ -160,30 +169,96 @@ def set_date(obj):
|
|||||||
obj.day1, obj.month1, obj.year1, obj.slash1 = 0, 0, 0, 0
|
obj.day1, obj.month1, obj.year1, obj.slash1 = 0, 0, 0, 0
|
||||||
obj.day2, obj.month2, obj.year2, obj.slash2 = 0, 0, 0, 0
|
obj.day2, obj.month2, obj.year2, obj.slash2 = 0, 0, 0, 0
|
||||||
|
|
||||||
|
|
||||||
|
def check_primary(surname, surnames):
|
||||||
|
if surname.primary:
|
||||||
|
# then all reast should not be:
|
||||||
|
for s in surnames:
|
||||||
|
if s.primary:
|
||||||
|
s.primary = False
|
||||||
|
s.save()
|
||||||
|
else:
|
||||||
|
# then one of them should be
|
||||||
|
if not any([s.primary for s in surnames]):
|
||||||
|
surnames[0].primary = True
|
||||||
|
surnames[0].save()
|
||||||
|
|
||||||
def process_surname(request, handle, order, sorder, action="view"):
|
def process_surname(request, handle, order, sorder, action="view"):
|
||||||
# /sdjhgsdjhdhgsd/name/1/surname/1 (view)
|
# /sdjhgsdjhdhgsd/name/1/surname/1 (view)
|
||||||
# /sdjhgsdjhdhgsd/name/1/surname/add
|
# /sdjhgsdjhdhgsd/name/1/surname/add
|
||||||
# /sdjhgsdjhdhgsd/name/1/surname/2/[edit|view|add|delete]
|
# /sdjhgsdjhdhgsd/name/1/surname/2/[edit|view|add|delete]
|
||||||
|
|
||||||
#import pdb; pdb.set_trace()
|
|
||||||
|
|
||||||
if sorder == "add":
|
if sorder == "add":
|
||||||
sorder = 1
|
|
||||||
action = "add"
|
action = "add"
|
||||||
if request.POST.has_key("action"):
|
if request.POST.has_key("action"):
|
||||||
action = request.POST.get("action")
|
action = request.POST.get("action")
|
||||||
|
|
||||||
person = Person.objects.get(handle=handle)
|
person = Person.objects.get(handle=handle)
|
||||||
name = person.name_set.get(order=order)
|
name = person.name_set.get(order=order)
|
||||||
surname = name.surname_set.get(order=sorder)
|
|
||||||
surname.prefix = make_empty(True, surname.prefix, " prefix ")
|
|
||||||
surnameform = SurnameForm(instance=surname)
|
|
||||||
surnameform.model = surname
|
|
||||||
|
|
||||||
if action == "save":
|
if action in ["view", "edit"]:
|
||||||
action = "view"
|
surname = name.surname_set.get(order=sorder)
|
||||||
|
if action == "edit":
|
||||||
|
surname.prefix = make_empty(True, surname.prefix, " prefix ")
|
||||||
|
elif action in ["delete"]:
|
||||||
|
surnames = name.surname_set.all().order_by("order")
|
||||||
|
if len(surnames) > 1:
|
||||||
|
neworder = 1
|
||||||
|
for surname in surnames:
|
||||||
|
if surname.order != neworder:
|
||||||
|
surname.order = neworder
|
||||||
|
surname.save()
|
||||||
|
neworder += 1
|
||||||
|
elif surname.order == int(sorder):
|
||||||
|
surname.delete()
|
||||||
|
else:
|
||||||
|
neworder += 1
|
||||||
|
else:
|
||||||
|
request.user.message_set.create(message="You can't delete the only surname")
|
||||||
|
return redirect("/person/%s/name/%s" % (person.handle, name.order))
|
||||||
|
elif action in ["add"]:
|
||||||
|
surname = Surname(name=name, primary=False,
|
||||||
|
name_origin_type=NameOriginType.objects.get(val=NameOriginType._DEFAULT[0]))
|
||||||
|
surname.prefix = make_empty(True, surname.prefix, " prefix ")
|
||||||
|
elif action == "create":
|
||||||
|
surnames = name.surname_set.all().order_by("order")
|
||||||
|
sorder = 1
|
||||||
|
for surname in surnames:
|
||||||
|
if surname.order != sorder:
|
||||||
|
surname.order = sorder
|
||||||
|
surname.save()
|
||||||
|
sorder += 1
|
||||||
|
surname = Surname(name=name, primary=True,
|
||||||
|
name_origin_type=NameOriginType.objects.get(val=NameOriginType._DEFAULT[0]),
|
||||||
|
order=sorder)
|
||||||
|
sf = SurnameForm(request.POST, instance=surname)
|
||||||
|
sf.model = surname
|
||||||
|
if sf.is_valid():
|
||||||
|
surname.prefix = ssf.cleaned_data["prefix"] if sf.cleaned_data["prefix"] != " prefix " else ""
|
||||||
|
check_primary(surname, surnames)
|
||||||
|
sf.save()
|
||||||
|
return redirect("/person/%s/name/%s/surname/%s" %
|
||||||
|
(person.handle, name.order, sorder))
|
||||||
|
action = "edit"
|
||||||
|
surname.prefix = make_empty(True, surname.prefix, " prefix ")
|
||||||
|
elif action == "save":
|
||||||
|
surname = name.surname_set.get(order=sorder)
|
||||||
|
sf = SurnameForm(request.POST, instance=surname)
|
||||||
|
sf.model = surname
|
||||||
|
if sf.is_valid():
|
||||||
|
surname.prefix = ssf.cleaned_data["prefix"] if sf.cleaned_data["prefix"] != " prefix " else ""
|
||||||
|
check_primary(surname, name.surname_set.all().exclude(order=surname.order))
|
||||||
|
sf.save()
|
||||||
|
return redirect("/person/%s/name/%s/surname/%s" %
|
||||||
|
(person.handle, name.order, sorder))
|
||||||
|
action = "edit"
|
||||||
|
surname.prefix = make_empty(True, surname.prefix, " prefix ")
|
||||||
|
# else, edit again
|
||||||
|
else:
|
||||||
|
raise
|
||||||
|
|
||||||
# FIXME: working on add/save/create
|
sf = SurnameForm(instance=surname)
|
||||||
|
sf.model = surname
|
||||||
|
|
||||||
context = RequestContext(request)
|
context = RequestContext(request)
|
||||||
context["action"] = action
|
context["action"] = action
|
||||||
@ -192,13 +267,14 @@ def process_surname(request, handle, order, sorder, action="view"):
|
|||||||
context["id"] = id
|
context["id"] = id
|
||||||
context["person"] = person
|
context["person"] = person
|
||||||
context["object"] = person
|
context["object"] = person
|
||||||
context["surnameform"] = surnameform
|
context["surnameform"] = sf
|
||||||
context["order"] = name.order
|
context["order"] = name.order
|
||||||
context["sorder"] = sorder
|
context["sorder"] = sorder
|
||||||
view_template = 'view_surname_detail.html'
|
view_template = 'view_surname_detail.html'
|
||||||
return render_to_response(view_template, context)
|
return render_to_response(view_template, context)
|
||||||
|
|
||||||
def process_name(request, handle, order, action="view"):
|
def process_name(request, handle, order, action="view"):
|
||||||
|
## FIXME: can't add second name
|
||||||
if order == "add":
|
if order == "add":
|
||||||
order = 0
|
order = 0
|
||||||
action = "add"
|
action = "add"
|
||||||
@ -237,29 +313,37 @@ def process_name(request, handle, order, action="view"):
|
|||||||
name_type=NameType.objects.get(val=NameType._DEFAULT[0]))
|
name_type=NameType.objects.get(val=NameType._DEFAULT[0]))
|
||||||
nf = NameForm(instance=name)
|
nf = NameForm(instance=name)
|
||||||
nf.model = name
|
nf.model = name
|
||||||
surname = Surname(name=name, primary=True, order=1)
|
surname = Surname(name=name,
|
||||||
|
primary=True,
|
||||||
|
order=1,
|
||||||
|
name_origin_type=NameOriginType.objects.get(val=NameOriginType._DEFAULT[0]))
|
||||||
sf = SurnameForm(request.POST, instance=surname)
|
sf = SurnameForm(request.POST, instance=surname)
|
||||||
action = "edit"
|
elif action == "create":
|
||||||
elif action == "save":
|
# look up old data:
|
||||||
# look up old data, if any:
|
|
||||||
person = Person.objects.get(handle=handle)
|
person = Person.objects.get(handle=handle)
|
||||||
oldname = person.name_set.get(preferred=True)
|
name = Name(preferred=False)
|
||||||
surname = oldname.surname_set.get(primary=True)
|
name.person = person
|
||||||
|
next_order = max([name.order for name in person.name_set.all()]) + 1
|
||||||
|
surname = Surname(name=name,
|
||||||
|
primary=True,
|
||||||
|
order=next_order,
|
||||||
|
name_origin_type=NameOriginType.objects.get(val=NameOriginType._DEFAULT[0]))
|
||||||
# combine with user data:
|
# combine with user data:
|
||||||
pf = PersonForm(request.POST, instance=person)
|
pf = PersonForm(request.POST, instance=person)
|
||||||
pf.model = person
|
pf.model = person
|
||||||
nf = NameForm(request.POST, instance=oldname)
|
nf = NameForm(request.POST, instance=name)
|
||||||
nf.model = oldname
|
nf.model = name
|
||||||
sf = SurnameForm(request.POST, instance=surname)
|
sf = SurnameForm(request.POST, instance=surname)
|
||||||
if nf.is_valid() and sf.is_valid():
|
if nf.is_valid() and sf.is_valid():
|
||||||
# name.preferred and surname.primary get set False in the above is_valid()
|
# name.preferred and surname.primary get set False in the above is_valid()
|
||||||
# person = pf.save()
|
# person = pf.save()
|
||||||
# Process data:
|
# Process data:
|
||||||
oldname.person = person
|
name.person = person
|
||||||
name = nf.save()
|
name = nf.save()
|
||||||
# Manually set any data:
|
# Manually set any data:
|
||||||
name.suffix = nf.cleaned_data["suffix"] if nf.cleaned_data["suffix"] != " suffix " else ""
|
name.suffix = nf.cleaned_data["suffix"] if nf.cleaned_data["suffix"] != " suffix " else ""
|
||||||
name.preferred = True # FIXME: why is this False?
|
name.preferred = False # FIXME: why is this False?
|
||||||
|
name.order = next_order
|
||||||
name.save()
|
name.save()
|
||||||
# Process data:
|
# Process data:
|
||||||
surname.name = name
|
surname.name = name
|
||||||
@ -274,6 +358,40 @@ def process_name(request, handle, order, action="view"):
|
|||||||
return redirect("/person/%s/name/%s" % (person.handle, name.order))
|
return redirect("/person/%s/name/%s" % (person.handle, name.order))
|
||||||
else:
|
else:
|
||||||
action = "add"
|
action = "add"
|
||||||
|
elif action == "save":
|
||||||
|
# look up old data:
|
||||||
|
person = Person.objects.get(handle=handle)
|
||||||
|
oldname = person.name_set.get(preferred=True)
|
||||||
|
oldsurname = oldname.surname_set.get(primary=True)
|
||||||
|
# combine with user data:
|
||||||
|
pf = PersonForm(request.POST, instance=person)
|
||||||
|
pf.model = person
|
||||||
|
nf = NameForm(request.POST, instance=oldname)
|
||||||
|
nf.model = oldname
|
||||||
|
sf = SurnameForm(request.POST, instance=oldsurname)
|
||||||
|
if nf.is_valid() and sf.is_valid():
|
||||||
|
# name.preferred and surname.primary get set False in the above is_valid()
|
||||||
|
# person = pf.save()
|
||||||
|
# Process data:
|
||||||
|
oldname.person = person
|
||||||
|
name = nf.save()
|
||||||
|
# Manually set any data:
|
||||||
|
name.suffix = nf.cleaned_data["suffix"] if nf.cleaned_data["suffix"] != " suffix " else ""
|
||||||
|
name.preferred = True # FIXME: why is this False?
|
||||||
|
name.save()
|
||||||
|
# Process data:
|
||||||
|
oldsurname.name = name
|
||||||
|
surname = sf.save(commit=False)
|
||||||
|
# Manually set any data:
|
||||||
|
surname.prefix = sf.cleaned_data["prefix"] if sf.cleaned_data["prefix"] != " prefix " else ""
|
||||||
|
surname.primary = True # FIXME: why is this False?
|
||||||
|
surname.save()
|
||||||
|
# FIXME: last_saved, last_changed, last_changed_by
|
||||||
|
dji.rebuild_cache(person)
|
||||||
|
# FIXME: update probably_alive
|
||||||
|
return redirect("/person/%s/name/%s" % (person.handle, name.order))
|
||||||
|
else:
|
||||||
|
action = "edit"
|
||||||
context = RequestContext(request)
|
context = RequestContext(request)
|
||||||
context["action"] = action
|
context["action"] = action
|
||||||
context["tview"] = _('Name')
|
context["tview"] = _('Name')
|
||||||
@ -877,6 +995,10 @@ def process_person(request, context, handle, action): # view, edit, save
|
|||||||
person = Person(handle=create_id())
|
person = Person(handle=create_id())
|
||||||
name = Name(person=person, preferred=True)
|
name = Name(person=person, preferred=True)
|
||||||
surname = Surname(name=name, primary=True, order=1)
|
surname = Surname(name=name, primary=True, order=1)
|
||||||
|
surname = Surname(name=name,
|
||||||
|
primary=True,
|
||||||
|
order=1,
|
||||||
|
name_origin_type=NameOriginType.objects.get(val=NameOriginType._DEFAULT[0]))
|
||||||
# combine with user data:
|
# combine with user data:
|
||||||
pf = PersonForm(request.POST, instance=person)
|
pf = PersonForm(request.POST, instance=person)
|
||||||
pf.model = person
|
pf.model = person
|
||||||
|
@ -636,6 +636,7 @@ class DjangoInterface(object):
|
|||||||
self.add_event_ref(obj, event_ref)
|
self.add_event_ref(obj, event_ref)
|
||||||
|
|
||||||
def add_surname_list(self, name, surname_list):
|
def add_surname_list(self, name, surname_list):
|
||||||
|
order = 1
|
||||||
for data in surname_list:
|
for data in surname_list:
|
||||||
(surname_text, prefix, primary, origin_type,
|
(surname_text, prefix, primary, origin_type,
|
||||||
connector) = data
|
connector) = data
|
||||||
@ -647,7 +648,9 @@ class DjangoInterface(object):
|
|||||||
origin_type)
|
origin_type)
|
||||||
surname.connector = connector
|
surname.connector = connector
|
||||||
surname.name = name
|
surname.name = name
|
||||||
|
surname.order = order
|
||||||
surname.save()
|
surname.save()
|
||||||
|
order += 1
|
||||||
|
|
||||||
def add_note_list(self, obj, note_list):
|
def add_note_list(self, obj, note_list):
|
||||||
for handle in note_list:
|
for handle in note_list:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user