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

View File

@ -21,7 +21,10 @@ class NameForm(forms.ModelForm):
class Meta: class Meta:
model = Name model = Name
fields = ("suffix", "first_name", "title", "prefix", 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()) surname = forms.CharField(required=False, widget=TextInput())
first_name = forms.CharField(required=False, widget=TextInput()) first_name = forms.CharField(required=False, widget=TextInput())
title = 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) register.filter('make_name', make_name)
def preferred(name_set, attr): 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: if name:
return escape(getattr(name, attr)) return escape(getattr(name, attr))
else: else:

View File

@ -41,11 +41,11 @@ from django.db.models import Q
#------------------------------------------------------------------------ #------------------------------------------------------------------------
import web import web
from web.grampsdb.models import * from web.grampsdb.models import *
from web.forms import NameForm from web.grampsdb.forms import NameForm
_ = lambda text: text _ = lambda text: text
# Views: [(Nice name plural, /name/handle, Model), ] # Views: [(<Nice name plural>, /<name>/handle, <Model>), ]
VIEWS = [(_('People'), 'person', Name), VIEWS = [(_('People'), 'person', Name),
(_('Families'), 'family', Family), (_('Families'), 'family', Family),
(_('Events'), 'event', Event), (_('Events'), 'event', Event),
@ -104,6 +104,9 @@ def user_page(request, username):
return render_to_response('user_page.html', context) return render_to_response('user_page.html', context)
def view_name_detail(request, handle, order, action="view"): def view_name_detail(request, handle, order, action="view"):
if order == "add":
order = 0
action = "add"
if request.POST.has_key("action"): if request.POST.has_key("action"):
action = request.POST.get("action") action = request.POST.get("action")
if action == "view": if action == "view":
@ -117,15 +120,39 @@ def view_name_detail(request, handle, order, action="view"):
form = NameForm(instance=name) form = NameForm(instance=name)
form.model = name form.model = name
elif action == "delete": elif action == "delete":
pass person = Person.objects.get(handle=handle)
person.name_set.get(order=order).delete()
action = "back"
elif action == "add": 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": elif action == "save":
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)
form = NameForm(request.POST, instance=name) form = NameForm(request.POST, instance=name)
form.model = name form.model = name
if form.is_valid(): 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() form.save()
else: else:
action = "edit" action = "edit"
@ -144,6 +171,9 @@ def view_name_detail(request, handle, order, action="view"):
context["action"] = "view" context["action"] = "view"
return redirect("/person/%s/name/%d" % return redirect("/person/%s/name/%d" %
(person.handle, name.order), context) (person.handle, name.order), context)
elif action == "back":
return redirect("/person/%s/" %
(person.handle), context)
else: else:
return render_to_response(view_template, context) return render_to_response(view_template, context)

View File

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