Editing name done; working on surname
svn: r19612
This commit is contained in:
parent
e495bb58df
commit
cd731f1e21
@ -27,6 +27,12 @@
|
||||
{% endfor %}
|
||||
|
||||
<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>
|
||||
<td class="ColumnAttribute">{{surnameform.surname.label}}:</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="ColumnValue" id="data">{% render nameform.suffix user action %}</td>
|
||||
<tr>
|
||||
<td class="ColumnAttribute">{{nameform.name_type.label}}:</td>
|
||||
<td class="ColumnValue" id="data">{% render nameform.name_type user action %}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="ColumnAttribute">{{nameform.preferred.label}}:</td>
|
||||
|
@ -31,35 +31,24 @@
|
||||
{% endif %}
|
||||
<form method="post">{% csrf_token %}
|
||||
<tr>
|
||||
<td class="ColumnAttribute">{{form.surname.label}}:</td>
|
||||
<td class="ColumnValue" id="data">{% render form.surname user action %}</td>
|
||||
<td class="ColumnAttribute">{{form.prefix.label}}:</td>
|
||||
<td class="ColumnValue" id="data">{% render form.prefix user action %}</td>
|
||||
<td class="ColumnAttribute">{{surnameform.name_origin_type.label}}:</td>
|
||||
<td class="ColumnValue" id="data">{% render surnameform.name_origin_type user action %}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="ColumnAttribute">{{form.first_name.label}}:</td>
|
||||
<td class="ColumnValue" id="data">{% render form.first_name 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>
|
||||
<td class="ColumnAttribute">{{surnameform.primary.label}}:</td>
|
||||
<td class="ColumnValue" id="data">{% render surnameform.primary user action %}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="ColumnAttribute">{{form.preferred.label}}:</td>
|
||||
{% if form.model.preferred %}
|
||||
<td class="ColumnValue" id="data">True</td>
|
||||
{% else %}
|
||||
<td class="ColumnValue" id="data">{% render form.preferred user action %}</td>
|
||||
{% endif %}
|
||||
<td class="ColumnAttribute">{{form.private.label}}:</td>
|
||||
<td class="ColumnValue" id="data">{% render form.private user action %}</td>
|
||||
<td class="ColumnAttribute">{{surnameform.prefix.label}}:</td>
|
||||
<td class="ColumnValue" id="data">{% render surnameform.prefix user action %}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="ColumnAttribute">{{surnameform.surname.label}}:</td>
|
||||
<td class="ColumnValue" id="data">{% render surnameform.surname user action %}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="ColumnAttribute">{{surnameform.connector.label}}:</td>
|
||||
<td class="ColumnValue" id="data">{% render surnameform.connector user action %}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
@ -75,33 +64,6 @@
|
||||
<li class="ui-corner-top ui-state-default"><a href="#tab-notes">Notes</a></li>
|
||||
</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>
|
||||
|
||||
</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>
|
||||
|
||||
{% if user.is_authenticated %}
|
||||
|
@ -59,6 +59,9 @@ class NameForm(forms.ModelForm):
|
||||
nick = forms.CharField(label="Nick",
|
||||
required=False,
|
||||
widget=TextInput(attrs={'size':'15'}))
|
||||
group_as = forms.CharField(label="Group as",
|
||||
required=False,
|
||||
widget=TextInput(attrs={'size':'30'}))
|
||||
suffix = forms.CharField(required=False,
|
||||
initial=' suffix ',
|
||||
widget=TextInput(attrs={'size':'15',
|
||||
@ -87,17 +90,21 @@ class NameFormFromPerson(NameForm):
|
||||
#"quality_interpreted",
|
||||
"year1", "day1", "month1",
|
||||
"sortval", "newyear", "person",
|
||||
"sort_as", "display_as"]
|
||||
"group_as", "sort_as", "display_as"]
|
||||
|
||||
class SurnameForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Surname
|
||||
exclude = ['name']
|
||||
exclude = ['name', 'order']
|
||||
|
||||
surname = forms.CharField(label="Surname",
|
||||
required=False,
|
||||
widget=TextInput(attrs={'size':'30'}))
|
||||
|
||||
connector = forms.CharField(label="Connector",
|
||||
required=False,
|
||||
widget=TextInput(attrs={'size':'30'}))
|
||||
|
||||
prefix = forms.CharField(label="Prefix",
|
||||
required=False,
|
||||
initial=' prefix ',
|
||||
|
@ -598,6 +598,7 @@ class Surname(models.Model):
|
||||
primary = models.BooleanField('Primary surname?')
|
||||
connector = models.TextField(blank=True)
|
||||
name = models.ForeignKey("Name")
|
||||
order = models.PositiveIntegerField()
|
||||
|
||||
def __unicode__(self):
|
||||
return "%s" % self.surname
|
||||
|
@ -160,25 +160,30 @@ def set_date(obj):
|
||||
obj.day1, obj.month1, obj.year1, obj.slash1 = 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/add
|
||||
# /sdjhgsdjhdhgsd/name/1/surname/2/[edit|view|add|delete]
|
||||
|
||||
#import pdb; pdb.set_trace()
|
||||
|
||||
if sorder == "add":
|
||||
sorder = 0
|
||||
sorder = 1
|
||||
action = "add"
|
||||
if request.POST.has_key("action"):
|
||||
print "override!"
|
||||
action = request.POST.get("action")
|
||||
|
||||
person = Person.objects.get(handle=handle)
|
||||
name = person.name_set.filter(order=order)[0]
|
||||
surname = name.surname_set.filter()[int(sorder) - 1] # sorder is 1-based
|
||||
nameform = NameForm(instance=name)
|
||||
nameform.model = name
|
||||
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":
|
||||
active = "view"
|
||||
action = "view"
|
||||
|
||||
# FIXME: working on add/save/create
|
||||
|
||||
context = RequestContext(request)
|
||||
context["action"] = action
|
||||
@ -187,13 +192,13 @@ def view_surname(request, handle, order, sorder, action="view"):
|
||||
context["id"] = id
|
||||
context["person"] = person
|
||||
context["object"] = person
|
||||
context["nameform"] = form
|
||||
context["surnameform"] = surnameform
|
||||
context["order"] = name.order
|
||||
context["sorder"] = sorder
|
||||
view_template = 'view_surname.html'
|
||||
view_template = 'view_surname_detail.html'
|
||||
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":
|
||||
order = 0
|
||||
action = "add"
|
||||
@ -205,6 +210,7 @@ def view_name(request, handle, order, action="view"):
|
||||
name = nf.model
|
||||
elif action == "edit":
|
||||
pf, nf, sf, person = get_person_forms(handle)
|
||||
name = nf.model
|
||||
elif action == "delete":
|
||||
person = Person.objects.get(handle=handle)
|
||||
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
|
||||
person = Person.objects.get(handle=handle)
|
||||
name = Name(person=person,
|
||||
display_as=NameFormatType._DEFAULT[0],
|
||||
sort_as=NameFormatType._DEFAULT[0],
|
||||
name_type=NameType._DEFAULT[0])
|
||||
display_as=NameFormatType.objects.get(val=NameFormatType._DEFAULT[0]),
|
||||
sort_as=NameFormatType.objects.get(val=NameFormatType._DEFAULT[0]),
|
||||
name_type=NameType.objects.get(val=NameType._DEFAULT[0]))
|
||||
nf = NameForm(instance=name)
|
||||
nf.model = name
|
||||
surname = Surname(name=name, primary=True, order=1)
|
||||
sf = SurnameForm(request.POST, instance=surname)
|
||||
action = "edit"
|
||||
elif action == "save":
|
||||
# look up old data, if any:
|
||||
person = Person.objects.get(handle=handle)
|
||||
try:
|
||||
name = person.name_set.filter(order=order)[0]
|
||||
except:
|
||||
order = person.name_set.count() + 1
|
||||
name = Name(person=person, order=order)
|
||||
form = NameForm(request.POST, instance=name)
|
||||
form.model = name
|
||||
if form.is_valid():
|
||||
# now it is preferred:
|
||||
if name.preferred: # was preferred, still must be
|
||||
form.cleaned_data["preferred"] = True
|
||||
elif form.cleaned_data["preferred"]: # now is
|
||||
# set all of the other names to be
|
||||
# not preferred:
|
||||
person.name_set.filter(~ Q(id=name.id)) \
|
||||
.update(preferred=False)
|
||||
# else some other name is preferred
|
||||
set_date(name)
|
||||
n = form.save()
|
||||
oldname = person.name_set.get(preferred=True)
|
||||
surname = 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=surname)
|
||||
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:
|
||||
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:
|
||||
action = "edit"
|
||||
# FIXME: need to update cache
|
||||
# FIXME: need to reset probabily_alive
|
||||
action = "add"
|
||||
context = RequestContext(request)
|
||||
context["action"] = action
|
||||
context["tview"] = _('Name')
|
||||
@ -271,13 +288,7 @@ def view_name(request, handle, order, action="view"):
|
||||
context["order"] = name.order
|
||||
context["next"] = "/person/%s/name/%d" % (person.handle, name.order)
|
||||
view_template = "view_name_detail.html"
|
||||
if action == "save":
|
||||
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)
|
||||
return render_to_response(view_template, context)
|
||||
|
||||
def send_file(request, filename, mimetype):
|
||||
"""
|
||||
@ -865,7 +876,7 @@ def process_person(request, context, handle, action): # view, edit, save
|
||||
else: # create new item
|
||||
person = Person(handle=create_id())
|
||||
name = Name(person=person, preferred=True)
|
||||
surname = Surname(name=name, primary=True)
|
||||
surname = Surname(name=name, primary=True, order=1)
|
||||
# combine with user data:
|
||||
pf = PersonForm(request.POST, instance=person)
|
||||
pf.model = person
|
||||
@ -941,7 +952,9 @@ def get_person_forms(handle, protect=False, empty=False):
|
||||
try:
|
||||
surname = name.surname_set.get(primary=True)
|
||||
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:
|
||||
name.sanitize()
|
||||
|
@ -75,10 +75,10 @@ urlpatterns += patterns('',
|
||||
{"action": "view"}), # /object/handle/
|
||||
(r'^(?P<view>(\w+))/(?P<handle>(\w+))/(?P<action>(\w+))$',
|
||||
action), # /object/handle/action
|
||||
(r'^person/(?P<handle>(\w+))/name/(?P<order>(\w+))$', view_name),
|
||||
# (r'^person/(?P<handle>(\w+))/name/(?P<order>(\w+))/(?P<action>(\w+))$', view_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+))/(?P<action>(\w+))$', view_surname),
|
||||
(r'^person/(?P<handle>(\w+))/name/(?P<order>(\w+))$', process_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+))$', process_surname),
|
||||
(r'^person/(?P<handle>(\w+))/name/(?P<order>(\w+))/surname/(?P<sorder>(\w+))/(?P<action>(\w+))$', process_surname),
|
||||
)
|
||||
|
||||
# In urls:
|
||||
|
Loading…
Reference in New Issue
Block a user