Editing name done; working on surname

svn: r19612
This commit is contained in:
Doug Blank 2012-05-21 18:50:03 +00:00
parent e495bb58df
commit cd731f1e21
6 changed files with 92 additions and 105 deletions

View File

@ -27,6 +27,12 @@
{% endfor %} {% endfor %}
<form method="post">{% csrf_token %} <form method="post">{% csrf_token %}
<tr>
<td class="ColumnAttribute">{{surnameform.name_origin_type.label}}:</td>
<td class="ColumnValue" id="data">{% render surnameform.name_origin_type user action %}</td>
<td class="ColumnAttribute">{{nameform.name_type.label}}:</td>
<td class="ColumnValue" id="data">{% render nameform.name_type user action %}</td>
</tr>
<tr> <tr>
<td class="ColumnAttribute">{{surnameform.surname.label}}:</td> <td class="ColumnAttribute">{{surnameform.surname.label}}:</td>
<td class="ColumnValue" id="data">{% render surnameform.surname user action False "" "get_focus" %}</td> <td class="ColumnValue" id="data">{% render surnameform.surname user action False "" "get_focus" %}</td>
@ -45,8 +51,6 @@
<td class="ColumnAttribute">{{nameform.suffix.label}}:</td> <td class="ColumnAttribute">{{nameform.suffix.label}}:</td>
<td class="ColumnValue" id="data">{% render nameform.suffix user action %}</td> <td class="ColumnValue" id="data">{% render nameform.suffix user action %}</td>
<tr> <tr>
<td class="ColumnAttribute">{{nameform.name_type.label}}:</td>
<td class="ColumnValue" id="data">{% render nameform.name_type user action %}</td>
</tr> </tr>
<tr> <tr>
<td class="ColumnAttribute">{{nameform.preferred.label}}:</td> <td class="ColumnAttribute">{{nameform.preferred.label}}:</td>

View File

@ -31,35 +31,24 @@
{% endif %} {% endif %}
<form method="post">{% csrf_token %} <form method="post">{% csrf_token %}
<tr> <tr>
<td class="ColumnAttribute">{{form.surname.label}}:</td> <td class="ColumnAttribute">{{surnameform.name_origin_type.label}}:</td>
<td class="ColumnValue" id="data">{% render form.surname user action %}</td> <td class="ColumnValue" id="data">{% render surnameform.name_origin_type user action %}</td>
<td class="ColumnAttribute">{{form.prefix.label}}:</td>
<td class="ColumnValue" id="data">{% render form.prefix user action %}</td>
</tr> </tr>
<tr> <tr>
<td class="ColumnAttribute">{{form.first_name.label}}:</td> <td class="ColumnAttribute">{{surnameform.primary.label}}:</td>
<td class="ColumnValue" id="data">{% render form.first_name user action %}</td> <td class="ColumnValue" id="data">{% render surnameform.primary user action %}</td>
<td class="ColumnAttribute">{{form.call.label}}:</td>
<td class="ColumnValue" id="data">{% render form.call user action %}</td>
<tr>
</tr>
<td class="ColumnAttribute">{{form.title.label}}:</td>
<td class="ColumnValue" id="data">{% render form.title user action %}</td>
<td class="ColumnAttribute">{{form.suffix.label}}:</td>
<td class="ColumnValue" id="data">{% render form.suffix user action %}</td>
<tr>
<td class="ColumnAttribute">{{form.name_type.label}}:</td>
<td class="ColumnValue" id="data">{% render form.name_type user action %}</td>
</tr> </tr>
<tr> <tr>
<td class="ColumnAttribute">{{form.preferred.label}}:</td> <td class="ColumnAttribute">{{surnameform.prefix.label}}:</td>
{% if form.model.preferred %} <td class="ColumnValue" id="data">{% render surnameform.prefix user action %}</td>
<td class="ColumnValue" id="data">True</td> </tr>
{% else %} <tr>
<td class="ColumnValue" id="data">{% render form.preferred user action %}</td> <td class="ColumnAttribute">{{surnameform.surname.label}}:</td>
{% endif %} <td class="ColumnValue" id="data">{% render surnameform.surname user action %}</td>
<td class="ColumnAttribute">{{form.private.label}}:</td> </tr>
<td class="ColumnValue" id="data">{% render form.private user action %}</td> <tr>
<td class="ColumnAttribute">{{surnameform.connector.label}}:</td>
<td class="ColumnValue" id="data">{% render surnameform.connector user action %}</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
@ -75,33 +64,6 @@
<li class="ui-corner-top ui-state-default"><a href="#tab-notes">Notes</a></li> <li class="ui-corner-top ui-state-default"><a href="#tab-notes">Notes</a></li>
</ul> </ul>
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom"
id="tab-general">
<div style="overflow: auto; height:150px;">
<table border="1">
<tr><td style="background-color: #FFF2C5;">{{form.group_as.label}}: </td>
<td>{% render form.group_as user action %}</td>
</tr>
<tr><td style="background-color: #FFF2C5;">{{form.sort_as.label}}: </td>
<td>{% render form.sort_as user action %}</td>
</tr>
<tr><td style="background-color: #FFF2C5;">{{form.display_as.label}}: </td>
<td>{% render form.display_as user action %}</td>
</tr>
<tr><td style="background-color: #FFF2C5;">{{form.text.label}}: </td>
<td>{% render form.text user action %}</td>
</tr>
</table>
</div>
&nbsp;
</div>
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tab-sources">
{% source_table form.model user action "/person/%s/name/%s/source" person.handle form.model.order %}
</div>
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom
ui-tabs-hide" id="tab-notes">
{% note_table form.model user action "/person/%s/name/%s/note" person.handle form.model.order %}
</div>
</div> </div>
{% if user.is_authenticated %} {% if user.is_authenticated %}

View File

@ -59,6 +59,9 @@ class NameForm(forms.ModelForm):
nick = forms.CharField(label="Nick", nick = forms.CharField(label="Nick",
required=False, required=False,
widget=TextInput(attrs={'size':'15'})) widget=TextInput(attrs={'size':'15'}))
group_as = forms.CharField(label="Group as",
required=False,
widget=TextInput(attrs={'size':'30'}))
suffix = forms.CharField(required=False, suffix = forms.CharField(required=False,
initial=' suffix ', initial=' suffix ',
widget=TextInput(attrs={'size':'15', widget=TextInput(attrs={'size':'15',
@ -87,17 +90,21 @@ class NameFormFromPerson(NameForm):
#"quality_interpreted", #"quality_interpreted",
"year1", "day1", "month1", "year1", "day1", "month1",
"sortval", "newyear", "person", "sortval", "newyear", "person",
"sort_as", "display_as"] "group_as", "sort_as", "display_as"]
class SurnameForm(forms.ModelForm): class SurnameForm(forms.ModelForm):
class Meta: class Meta:
model = Surname model = Surname
exclude = ['name'] exclude = ['name', 'order']
surname = forms.CharField(label="Surname", surname = forms.CharField(label="Surname",
required=False, required=False,
widget=TextInput(attrs={'size':'30'})) widget=TextInput(attrs={'size':'30'}))
connector = forms.CharField(label="Connector",
required=False,
widget=TextInput(attrs={'size':'30'}))
prefix = forms.CharField(label="Prefix", prefix = forms.CharField(label="Prefix",
required=False, required=False,
initial=' prefix ', initial=' prefix ',

View File

@ -598,6 +598,7 @@ class Surname(models.Model):
primary = models.BooleanField('Primary surname?') primary = models.BooleanField('Primary surname?')
connector = models.TextField(blank=True) connector = models.TextField(blank=True)
name = models.ForeignKey("Name") name = models.ForeignKey("Name")
order = models.PositiveIntegerField()
def __unicode__(self): def __unicode__(self):
return "%s" % self.surname return "%s" % self.surname

View File

@ -160,25 +160,30 @@ 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 view_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 = 0 sorder = 1
action = "add" action = "add"
if request.POST.has_key("action"): if request.POST.has_key("action"):
print "override!"
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.filter(order=order)[0] name = person.name_set.get(order=order)
surname = name.surname_set.filter()[int(sorder) - 1] # sorder is 1-based surname = name.surname_set.get(order=sorder)
nameform = NameForm(instance=name) surname.prefix = make_empty(True, surname.prefix, " prefix ")
nameform.model = name surnameform = SurnameForm(instance=surname)
surnameform.model = surname
if action == "save": if action == "save":
active = "view" action = "view"
# FIXME: working on add/save/create
context = RequestContext(request) context = RequestContext(request)
context["action"] = action context["action"] = action
@ -187,13 +192,13 @@ def view_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["nameform"] = form context["surnameform"] = surnameform
context["order"] = name.order context["order"] = name.order
context["sorder"] = sorder context["sorder"] = sorder
view_template = 'view_surname.html' view_template = 'view_surname_detail.html'
return render_to_response(view_template, context) return render_to_response(view_template, context)
def view_name(request, handle, order, action="view"): def process_name(request, handle, order, action="view"):
if order == "add": if order == "add":
order = 0 order = 0
action = "add" action = "add"
@ -205,6 +210,7 @@ def view_name(request, handle, order, action="view"):
name = nf.model name = nf.model
elif action == "edit": elif action == "edit":
pf, nf, sf, person = get_person_forms(handle) pf, nf, sf, person = get_person_forms(handle)
name = nf.model
elif action == "delete": elif action == "delete":
person = Person.objects.get(handle=handle) person = Person.objects.get(handle=handle)
names = person.name_set.all().order_by("order") names = person.name_set.all().order_by("order")
@ -226,37 +232,48 @@ def view_name(request, handle, order, action="view"):
elif action == "add": # add name elif action == "add": # add name
person = Person.objects.get(handle=handle) person = Person.objects.get(handle=handle)
name = Name(person=person, name = Name(person=person,
display_as=NameFormatType._DEFAULT[0], display_as=NameFormatType.objects.get(val=NameFormatType._DEFAULT[0]),
sort_as=NameFormatType._DEFAULT[0], sort_as=NameFormatType.objects.get(val=NameFormatType._DEFAULT[0]),
name_type=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)
sf = SurnameForm(request.POST, instance=surname)
action = "edit" action = "edit"
elif action == "save": elif action == "save":
# look up old data, if any:
person = Person.objects.get(handle=handle) person = Person.objects.get(handle=handle)
try: oldname = person.name_set.get(preferred=True)
name = person.name_set.filter(order=order)[0] surname = oldname.surname_set.get(primary=True)
except: # combine with user data:
order = person.name_set.count() + 1 pf = PersonForm(request.POST, instance=person)
name = Name(person=person, order=order) pf.model = person
form = NameForm(request.POST, instance=name) nf = NameForm(request.POST, instance=oldname)
form.model = name nf.model = oldname
if form.is_valid(): sf = SurnameForm(request.POST, instance=surname)
# now it is preferred: if nf.is_valid() and sf.is_valid():
if name.preferred: # was preferred, still must be # name.preferred and surname.primary get set False in the above is_valid()
form.cleaned_data["preferred"] = True # person = pf.save()
elif form.cleaned_data["preferred"]: # now is # Process data:
# set all of the other names to be oldname.person = person
# not preferred: name = nf.save()
person.name_set.filter(~ Q(id=name.id)) \ # Manually set any data:
.update(preferred=False) name.suffix = nf.cleaned_data["suffix"] if nf.cleaned_data["suffix"] != " suffix " else ""
# else some other name is preferred name.preferred = True # FIXME: why is this False?
set_date(name) name.save()
n = form.save() # Process data:
surname.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: else:
action = "edit" action = "add"
# FIXME: need to update cache
# FIXME: need to reset probabily_alive
context = RequestContext(request) context = RequestContext(request)
context["action"] = action context["action"] = action
context["tview"] = _('Name') context["tview"] = _('Name')
@ -271,13 +288,7 @@ def view_name(request, handle, order, action="view"):
context["order"] = name.order context["order"] = name.order
context["next"] = "/person/%s/name/%d" % (person.handle, name.order) context["next"] = "/person/%s/name/%d" % (person.handle, name.order)
view_template = "view_name_detail.html" view_template = "view_name_detail.html"
if action == "save": return render_to_response(view_template, context)
context["action"] = "view"
return redirect("/person/%s/name/%d" % (person.handle, name.order))
elif action == "back":
return redirect("/person/%s/" % (person.handle))
else:
return render_to_response(view_template, context)
def send_file(request, filename, mimetype): def send_file(request, filename, mimetype):
""" """
@ -865,7 +876,7 @@ def process_person(request, context, handle, action): # view, edit, save
else: # create new item else: # create new item
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) surname = Surname(name=name, primary=True, order=1)
# 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
@ -941,7 +952,9 @@ def get_person_forms(handle, protect=False, empty=False):
try: try:
surname = name.surname_set.get(primary=True) surname = name.surname_set.get(primary=True)
except: except:
surname = Surname(name=name, primary=True, name_origin_type=NameOriginType.objects.get(val=NameOriginType._DEFAULT[0]),) surname = Surname(name=name, primary=True,
name_origin_type=NameOriginType.objects.get(val=NameOriginType._DEFAULT[0]),
order=1)
if protect and person.probably_alive: if protect and person.probably_alive:
name.sanitize() name.sanitize()

View File

@ -75,10 +75,10 @@ urlpatterns += patterns('',
{"action": "view"}), # /object/handle/ {"action": "view"}), # /object/handle/
(r'^(?P<view>(\w+))/(?P<handle>(\w+))/(?P<action>(\w+))$', (r'^(?P<view>(\w+))/(?P<handle>(\w+))/(?P<action>(\w+))$',
action), # /object/handle/action action), # /object/handle/action
(r'^person/(?P<handle>(\w+))/name/(?P<order>(\w+))$', view_name), (r'^person/(?P<handle>(\w+))/name/(?P<order>(\w+))$', process_name),
# (r'^person/(?P<handle>(\w+))/name/(?P<order>(\w+))/(?P<action>(\w+))$', view_name), (r'^person/(?P<handle>(\w+))/name/(?P<order>(\w+))/(?P<action>(\w+))$', process_name),
# (r'^person/(?P<handle>(\w+))/name/(?P<order>(\w+))/surname/(?P<sorder>(\w+))$', view_surname), (r'^person/(?P<handle>(\w+))/name/(?P<order>(\w+))/surname/(?P<sorder>(\w+))$', process_surname),
# (r'^person/(?P<handle>(\w+))/name/(?P<order>(\w+))/surname/(?P<sorder>(\w+))/(?P<action>(\w+))$', view_surname), (r'^person/(?P<handle>(\w+))/name/(?P<order>(\w+))/surname/(?P<sorder>(\w+))/(?P<action>(\w+))$', process_surname),
) )
# In urls: # In urls: