Some basic name editing; moved forms to web/grampsdb

svn: r13833
This commit is contained in:
Doug Blank 2009-12-17 04:10:41 +00:00
parent 9f74bdacce
commit d0318dd1a2
5 changed files with 85 additions and 27 deletions

View File

@ -11,7 +11,7 @@
</script>
<div class="content" id="IndividualDetail">
<h3>NAME{# form|make_name:user #}</h3>
<h3>{{form|make_name:user}}</h3>
<div id="summaryarea">
<table class="infolist"> {% comment %} 4 cols {% endcomment %}
<tbody>
@ -24,27 +24,34 @@
<form method="post">
{% endifequal %}
<tr>
<td class="ColumnAttribute">Family:</td>
<td class="ColumnAttribute">{{form.surname.label}}:</td>
<td class="ColumnValue" id="data">{{form.surname|render:action}}</td>
<td class="ColumnAttribute">Prefix:</td>
<td class="ColumnAttribute">{{form.prefix.label}}:</td>
<td class="ColumnValue" id="data">{{form.prefix|render:action}}</td>
</tr>
<td class="ColumnAttribute">Given:</td>
<td class="ColumnAttribute">{{form.first_name.label}}:</td>
<td class="ColumnValue" id="data">{{form.first_name|render:action}}</td>
<td class="ColumnAttribute">Call Name:</td>
<td class="ColumnAttribute">{{form.call.label}}:</td>
<td class="ColumnValue" id="data">{{form.call|render:action}}</td>
<tr>
</tr>
<td class="ColumnAttribute">Title:</td>
<td class="ColumnAttribute">{{form.title.label}}:</td>
<td class="ColumnValue" id="data">{{form.title|render:action}}</td>
<td class="ColumnAttribute">Suffix:</td>
<td class="ColumnAttribute">{{form.suffix.label}}:</td>
<td class="ColumnValue" id="data">{{form.suffix|render:action}}</td>
<tr>
<td class="ColumnAttribute">Patronymic:</td>
<td class="ColumnAttribute">{{form.patronymic.label}}:</td>
<td class="ColumnValue" id="data">{{form.patronymic|render:action}}</td>
<td class="ColumnAttribute">Type:</td>
<td class="ColumnAttribute">{{form.name_type.label}}:</td>
<td class="ColumnValue" id="data">{{form.name_type|render:action}}</td>
</tr>
<tr>
<td class="ColumnAttribute">{{form.preferred.label}}:</td>
{% if form.model.preferred %}
<td class="ColumnValue" id="data" colspan="3">True</td>
{% else %}
<td class="ColumnValue" id="data" colspan="3">{{form.preferred|render:action}}</td>
{% endif %}
</tr>
</tbody>
</table>
@ -52,25 +59,25 @@
{% else %}
<tr>
<td class="ColumnAttribute">Family:</td>
<td class="ColumnAttribute">{{form.surname.label}}:</td>
<td class="ColumnValue" id="data">{{form.surname}}</td>
<td class="ColumnAttribute">Prefix:</td>
<td class="ColumnAttribute">{{form.prefix.label}}:</td>
<td class="ColumnValue" id="data">[Private]</td>
<tr>
<td class="ColumnAttribute">Given:</td>
<td class="ColumnAttribute">{{form.given.label}}:</td>
<td class="ColumnValue" id="data">[Private]</td>
<td class="ColumnAttribute">Call Name:</td>
<td class="ColumnAttribute">{{form.call.label}}:</td>
<td class="ColumnValue" id="data">[Private]</td>
</tr>
</tr>
<td class="ColumnAttribute">Title:</td>
<td class="ColumnAttribute">{{form.title.label}}:</td>
<td class="ColumnValue" id="data">[Private]</td>
<td class="ColumnAttribute">Suffix:</td>
<td class="ColumnAttribute">{{form.suffix.label}}:</td>
<td class="ColumnValue" id="data">[Private]</td>
<tr>
<td class="ColumnAttribute">Patronymic:</td>
<td class="ColumnAttribute">{{form.patronymic.label}}:</td>
<td class="ColumnValue" id="data">[Private]</td>
<td class="ColumnAttribute">Type:</td>
<td class="ColumnAttribute">{{form.name_type.label}}:</td>
<td class="ColumnValue" id="data">{{form.name_type}}</td>
</tr>
</tbody>
@ -105,7 +112,7 @@
{% else %}
[<a href="/person/{{person.handle}}/name/{{order}}/edit">Edit Name</a>]
[<a href="/person/{{person.handle}}/name/{{order}}/delete">Delete Name</a>]
[<a href="/person/{{person.handle}}/name/{{order}}/add">Add Name</a>]
[<a href="/person/{{person.handle}}/name/add">Add Name</a>]
{% endifequal %}
{% else %}
{% endif %}

View File

@ -21,7 +21,10 @@ class NameForm(forms.ModelForm):
class Meta:
model = Name
fields = ("suffix", "first_name", "title", "prefix",
"call", "surname", "patronymic", "name_type")
"call", "surname", "patronymic", "name_type",
"preferred")
# Add these because they are TextFields, which render as
# Textareas:
surname = forms.CharField(required=False, widget=TextInput())
first_name = forms.CharField(required=False, widget=TextInput())
title = forms.CharField(required=False, widget=TextInput())

View File

@ -49,7 +49,10 @@ make_name.is_safe = True
register.filter('make_name', make_name)
def preferred(name_set, attr):
name = name_set.get(preferred=True)
try:
name = name_set.get(preferred=True)
except:
return "[No preferred name]"
if name:
return escape(getattr(name, attr))
else:

View File

@ -41,11 +41,11 @@ from django.db.models import Q
#------------------------------------------------------------------------
import web
from web.grampsdb.models import *
from web.forms import NameForm
from web.grampsdb.forms import NameForm
_ = lambda text: text
# Views: [(Nice name plural, /name/handle, Model), ]
# Views: [(<Nice name plural>, /<name>/handle, <Model>), ]
VIEWS = [(_('People'), 'person', Name),
(_('Families'), 'family', Family),
(_('Events'), 'event', Event),
@ -104,6 +104,9 @@ def user_page(request, username):
return render_to_response('user_page.html', context)
def view_name_detail(request, handle, order, action="view"):
if order == "add":
order = 0
action = "add"
if request.POST.has_key("action"):
action = request.POST.get("action")
if action == "view":
@ -117,15 +120,39 @@ def view_name_detail(request, handle, order, action="view"):
form = NameForm(instance=name)
form.model = name
elif action == "delete":
pass
person = Person.objects.get(handle=handle)
person.name_set.get(order=order).delete()
action = "back"
elif action == "add":
pass
person = Person.objects.get(handle=handle)
name = Name()
form = NameForm()
form.model = name
action = "edit"
elif action == "new":
person = Person.objects.get(handle=handle)
form = NameForm(request.POST)
if form.is_valid():
name.save()
action = "save"
else:
action = "edit"
elif action == "save":
person = Person.objects.get(handle=handle)
name = person.name_set.get(order=order)
form = NameForm(request.POST, instance=name)
form.model = name
if form.is_valid():
# now it is preferred:
if form.cleaned_data["preferred"]:
# but it wasn't:
if not name.preferred:
# set all of the other names to be
# not preferred:
person.name_set.filter(~ Q(id=name.id)) \
.update(preferred=False)
# else it always was
# else some other name is preferred
form.save()
else:
action = "edit"
@ -144,6 +171,9 @@ def view_name_detail(request, handle, order, action="view"):
context["action"] = "view"
return redirect("/person/%s/name/%d" %
(person.handle, name.order), context)
elif action == "back":
return redirect("/person/%s/" %
(person.handle), context)
else:
return render_to_response(view_template, context)

View File

@ -27,6 +27,7 @@
#
#------------------------------------------------------------------------
import web.grampsdb.models as models
import web.grampsdb.forms as forms
from web import libdjango
from web.djangodb import DjangoDb
from Simple import SimpleTable, SimpleAccess, make_basic_stylesheet
@ -123,9 +124,9 @@ _ = lambda text: text
def render(formfield, action):
retval = "error"
name = formfield.name # 'surname'
fieldname = formfield.name # 'surname'
if action == "view": # gets the unicode from model
retval = str(getattr(formfield.form.model, name))
retval = str(getattr(formfield.form.model, fieldname))
else: # renders as default
retval = formfield.as_widget()
return retval
@ -449,8 +450,22 @@ def make_name(name, user):
return "%s, %s" % (surname, "[Living]")
else:
return "%s, %s" % (surname, name.first_name)
elif isinstance(name, forms.NameForm):
surname = name.model.surname.strip()
if not surname:
surname = "[Missing]"
if user.is_authenticated():
return "%s, %s" % (surname, name.model.first_name)
else:
if probably_alive(name.model.person.handle):
return "%s, %s" % (surname, "[Living]")
else:
return "%s, %s" % (surname, name.model.first_name)
elif name: # name_set
name = name.get(preferred=True)
try:
name = name.get(preferred=True)
except:
return "[No preferred name]"
if name:
return make_name(name, user)
else: