Links as buttons; working on finishing person and name editing

svn: r19526
This commit is contained in:
Doug Blank 2012-05-15 14:45:47 +00:00
parent 215db01776
commit e5b31262ab
6 changed files with 106 additions and 25 deletions

View File

@ -27,14 +27,14 @@
{% for error in form.errors %}
{{error}}<br>
{% endfor %}
<form method="post">{% csrf_token %}
{% endifequal %}
{% endif %}
<form method="post">{% csrf_token %}
<tr>
<td class="ColumnAttribute">{{form.surname.label}}:</td>
<td class="ColumnValue" id="data"></td>
<td class="ColumnValue" id="data">{% render form.surname user action %}</td>
<td class="ColumnAttribute">{{form.prefix.label}}:</td>
<td class="ColumnValue" id="data"></td>
<td class="ColumnValue" id="data">{% render form.prefix user action %}</td>
</tr>
<tr>
<td class="ColumnAttribute">{{form.first_name.label}}:</td>
@ -71,7 +71,8 @@
<div class="ui-tabs ui-widget ui-widget-content ui-corner-all" id="tabs">
<ul class="ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all">
<li class="ui-state-default ui-corner-top ui-tabs-selected ui-state-active"><a href="#tab-general">General</a></li>
<li class="ui-corner-top ui-state-default"><a href="#tab-names">Names</a></li>
<li class="ui-corner-top ui-state-default"><a href="#tab-surnames">Surnames</a></li>
<li class="ui-corner-top ui-state-default"><a href="#tab-names">Other Names</a></li>
<li class="ui-corner-top ui-state-default"><a href="#tab-sources">Sources</a></li>
<li class="ui-corner-top ui-state-default"><a href="#tab-notes">Notes</a></li>
</ul>
@ -96,6 +97,9 @@
</div>
&nbsp;
</div>
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tab-surnames">
{% surname_table person user action "/person/%s/name/%s/surname" person.handle form.model.order %}
</div>
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tab-names">
{% name_table person user action "/person/%s/name" person.handle %}
</div>
@ -108,18 +112,26 @@
</div>
</div>
[<a href="/person/{{person.handle}}/">Back to Person</a>]
<input type="button"
value="Back to Person"
onclick="document.location.href='/person/{{person.handle}}'"/>
{% if user.is_authenticated %}
{% ifequal action "edit" %}
<input type="hidden" name="action" value="save"/>
<input type="submit" value="Submit"/>
</form>
<input type="submit" value="Save"/>
{% 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/add">Add Name</a>]
<input type="button"
value="Edit Name"
onclick="document.location.href='/person/{{person.handle}}/name/{{order}}/edit'"/>
<input type="button"
value="Add Name"
onclick="document.location.href='/person/{{person.handle}}/name/add'"/>
<input type="button"
value="Delete Name"
onclick="document.location.href='/person/{{person.handle}}/name/{{order}}/delete'"/>
{% endifequal %}
{% else %}
{% endif %}
</form>
{% endblock %}

View File

@ -25,10 +25,9 @@
{% for error in nameform.errors %}
Error in name: {{error}}<br>
{% endfor %}
<form method="post">{% csrf_token %}
{% endifequal %}
{% endif %}
<form method="post">{% csrf_token %}
<tr>
<td colspan="4">{{nameform|render_name:user}}</td>
<td class="ColumnAttribute" align="right">{{nameform.name_type.label}}:</td>
@ -124,20 +123,19 @@
</div>
</div>
{% make_button "Back to People" "/person" %}
{% if user.is_authenticated %}
{% ifequal action "edit" %}
{% make_button "Back to Person" "/person/%s" person.handle %}
<input type="hidden" name="action" value="save"/>
<input type="submit" value="Submit"/>
</form>
<input type="submit" value="Save"/>
{% else %}
{% make_button "Back to People" "/person/" %}
{% make_button "Add Person" "/person/add" %}
{% make_button "Edit Person" "/person/%s/edit" person.handle %}
{% make_button "Delete Person" "/person/%s/delete" person.handle %}
{% make_button "Edit Person" "/person/%s/edit" person.handle %}
{% make_button "Add Person" "/person/add" %}
{% make_button "Delete Person" "/person/%s/delete" person.handle %}
{% endifequal %}
{% else %}
{% endif %}
</form>
{% endblock %}

View File

@ -47,14 +47,16 @@ class NameForm(forms.ModelForm):
"sortval", "newyear", "person"]
# Add these because they are TextFields, which render as
# Textareas:
surname = forms.CharField(required=False,
surname = forms.CharField(label="Surname",
required=False,
widget=TextInput(attrs={'size':'30'}))
first_name = forms.CharField(label="Given",
required=False,
widget=TextInput(attrs={'size':'60'}))
title = forms.CharField(required=False,
widget=TextInput(attrs={'size':'15'}))
prefix = forms.CharField(required=False,
prefix = forms.CharField(label="Prefix",
required=False,
initial='prefix',
widget=TextInput(attrs={'size':'15',
'style': 'font-style: italic; color: gray; ',
@ -96,5 +98,5 @@ class NameFormFromPerson(NameForm):
#"quality_estimated", "quality_calculated",
#"quality_interpreted",
"year1", "day1", "month1",
"sortval", "newyear", "person",
"sortval", "newyear", "person",
"sort_as", "display_as"]

View File

@ -165,6 +165,39 @@ 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_detail(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]
if sorder == "add":
sorder = 0
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
form = NameForm(instance=name)
form.model = name
if action == "save":
active = "view"
context = RequestContext(request)
context["action"] = action
context["tview"] = _("Surname")
context["handle"] = handle
context["id"] = id
context["person"] = person
context["object"] = person
context["form"] = form
context["order"] = name.order
context["sorder"] = sorder
view_template = 'view_surname_detail.html'
return render_to_response(view_template, context)
def view_name_detail(request, handle, order, action="view"):
if order == "add":
order = 0
@ -221,7 +254,7 @@ def view_name_detail(request, handle, order, action="view"):
form.model = name
if form.is_valid():
# now it is preferred:
if name.preferred: # was preferred, stil must be
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
@ -500,17 +533,24 @@ def view_person_detail(request, view, handle, action="view"):
person = Person(handle=create_id())
if person.id: # editing
name = person.name_set.get(preferred=True)
surname = name.surname_set.get(primary=True)
else: # adding a new person with new name
name = Name(person=person, preferred=True)
surname = Surname(name=name, primary=True)
name.surname_set = [surname]
pf = PersonForm(request.POST, instance=person)
pf.model = person
nf = NameFormFromPerson(request.POST, instance=name)
nf.model = name
if nf.is_valid() and pf.is_valid():
surname.surname = nf.cleaned_data["surname"]
surname.prefix = nf.cleaned_data["prefix"]
surname.suffix = nf.cleaned_data["suffix"]
person = pf.save()
name = nf.save(commit=False)
name.person = person
name.save()
surname.save()
else:
action = "edit"
else: # view

View File

@ -40,7 +40,8 @@ admin.autodiscover()
from webapp.grampsdb.views import (main_page, user_page, logout_page,
process_action, view, view_detail,
view_name_detail, browse_page)
view_name_detail, view_surname_detail,
browse_page)
urlpatterns = patterns('',
# Specific matches first:
@ -76,6 +77,8 @@ urlpatterns += patterns('',
(r'^(?P<view>(\w+))/(?P<handle>(\w+))/$', view_detail),
(r'^person/(?P<handle>(\w+))/name/(?P<order>(\w+))$', view_name_detail),
(r'^person/(?P<handle>(\w+))/name/(?P<order>(\w+))/(?P<action>(\w+))$', view_name_detail),
(r'^person/(?P<handle>(\w+))/name/(?P<order>(\w+))/surname/(?P<sorder>(\w+))$', view_surname_detail),
(r'^person/(?P<handle>(\w+))/name/(?P<order>(\w+))/surname/(?P<sorder>(\w+))/(?P<action>(\w+))$', view_surname_detail),
(r'^(?P<view>(\w+))/(?P<handle>(\w+))/(?P<action>(\w+))$', process_action),
(r'^favicon\.ico$', 'django.views.generic.simple.redirect_to', {'url': '/styles/images/favicon.ico'}),
)

View File

@ -75,6 +75,7 @@ util_tags = [
"get_person_from_handle",
"event_table",
"name_table",
"surname_table",
"citation_table",
"source_table",
"note_table",
@ -213,7 +214,8 @@ _ = lambda text: text
def make_button(text, url, *args):
url = url % args
return """[ <a href="%s">%s</a> ] """ % (url, text)
#return """[ <a href="%s">%s</a> ] """ % (url, text)
return """<input type="button" value="%s" onclick="document.location.href='%s'"/>""" % (text, url)
def event_table(obj, user, action, url=None, *args):
retval = ""
@ -283,6 +285,30 @@ def name_table(obj, user, action, url=None, *args):
retval += nbsp("") # to keep tabs same height
return retval
def surname_table(obj, user, action, url=None, *args):
person_handle = args[0]
order = args[1]
retval = ""
table = Table()
table.columns(_("Surname"),)
if user.is_authenticated():
links = []
count = 1
name = obj.name_set.filter(order=order)[0]
for surname in name.surname_set.all():
table.row(surname.surname)
links.append(('URL',
# url is "/person/%s/name/%s/surname"
(url % args) + ("/%s" % count)))
count += 1
table.links(links)
retval += table.get_html()
if user.is_authenticated() and url and action == "view":
retval += make_button(_("Add surname"), (url + "/add") % args)
else:
retval += nbsp("") # to keep tabs same height
return retval
def source_table(obj, user, action, url=None, *args):
retval = ""
table = Table()