Working on name editing with refactor

svn: r19610
This commit is contained in:
Doug Blank 2012-05-20 22:31:11 +00:00
parent 9e148614c6
commit e495bb58df
4 changed files with 79 additions and 87 deletions

View File

@ -22,44 +22,41 @@
<table class="infolist" style="width:90%;"> {% comment %} 4 cols {% endcomment %} <table class="infolist" style="width:90%;"> {% comment %} 4 cols {% endcomment %}
<tbody> <tbody>
{% if user.is_authenticated %} {% for error in nameform.errors %}
{% ifequal action "edit" %} <p id="error">{{error}}</a><br>
{% for error in form.errors %} {% endfor %}
{{error}}<br>
{% endfor %}
{% endifequal %}
{% endif %}
<form method="post">{% csrf_token %} <form method="post">{% csrf_token %}
<tr> <tr>
<td class="ColumnAttribute">{{form.surname.label}}:</td> <td class="ColumnAttribute">{{surnameform.surname.label}}:</td>
<td class="ColumnValue" id="data">{% render form.surname user action False "" "get_focus" %}</td> <td class="ColumnValue" id="data">{% render surnameform.surname user action False "" "get_focus" %}</td>
<td class="ColumnAttribute">{{form.prefix.label}}:</td> <td class="ColumnAttribute">{{surnameform.prefix.label}}:</td>
<td class="ColumnValue" id="data">{% render form.prefix user action %}</td> <td class="ColumnValue" id="data">{% render surnameform.prefix user action %}</td>
</tr> </tr>
<tr> <tr>
<td class="ColumnAttribute">{{form.first_name.label}}:</td> <td class="ColumnAttribute">{{nameform.first_name.label}}:</td>
<td class="ColumnValue" id="data">{% render form.first_name user action %}</td> <td class="ColumnValue" id="data">{% render nameform.first_name user action %}</td>
<td class="ColumnAttribute">{{form.call.label}}:</td> <td class="ColumnAttribute">{{nameform.call.label}}:</td>
<td class="ColumnValue" id="data">{% render form.call user action %}</td> <td class="ColumnValue" id="data">{% render nameform.call user action %}</td>
<tr> <tr>
</tr> </tr>
<td class="ColumnAttribute">{{form.title.label}}:</td> <td class="ColumnAttribute">{{nameform.title.label}}:</td>
<td class="ColumnValue" id="data">{% render form.title user action %}</td> <td class="ColumnValue" id="data">{% render nameform.title user action %}</td>
<td class="ColumnAttribute">{{form.suffix.label}}:</td> <td class="ColumnAttribute">{{nameform.suffix.label}}:</td>
<td class="ColumnValue" id="data">{% render form.suffix user action %}</td> <td class="ColumnValue" id="data">{% render nameform.suffix user action %}</td>
<tr> <tr>
<td class="ColumnAttribute">{{form.name_type.label}}:</td> <td class="ColumnAttribute">{{nameform.name_type.label}}:</td>
<td class="ColumnValue" id="data">{% render form.name_type user action %}</td> <td class="ColumnValue" id="data">{% render nameform.name_type user action %}</td>
</tr> </tr>
<tr> <tr>
<td class="ColumnAttribute">{{form.preferred.label}}:</td> <td class="ColumnAttribute">{{nameform.preferred.label}}:</td>
{% if form.model.preferred %} {% if nameform.model.preferred %}
<td class="ColumnValue" id="data">True</td> <td class="ColumnValue" id="data">True</td>
{% else %} {% else %}
<td class="ColumnValue" id="data">{% render form.preferred user action %}</td> <td class="ColumnValue" id="data">{% render nameform.preferred user action %}</td>
{% endif %} {% endif %}
<td class="ColumnAttribute">{{form.private.label}}:</td> <td class="ColumnAttribute">{{nameform.private.label}}:</td>
<td class="ColumnValue" id="data">{% render form.private user action %}</td> <td class="ColumnValue" id="data">{% render nameform.private user action %}</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
@ -81,34 +78,34 @@
id="tab-general"> id="tab-general">
<div style="overflow: auto; height:150px;"> <div style="overflow: auto; height:150px;">
<table border="1"> <table border="1">
<tr><td style="background-color: #FFF2C5;">{{form.group_as.label}}: </td> <tr><td style="background-color: #FFF2C5;">{{nameform.group_as.label}}: </td>
<td>{% render form.group_as user action %}</td> <td>{% render nameform.group_as user action %}</td>
</tr> </tr>
<tr><td style="background-color: #FFF2C5;">{{form.sort_as.label}}: </td> <tr><td style="background-color: #FFF2C5;">{{nameform.sort_as.label}}: </td>
<td>{% render form.sort_as user action %}</td> <td>{% render nameform.sort_as user action %}</td>
</tr> </tr>
<tr><td style="background-color: #FFF2C5;">{{form.display_as.label}}: </td> <tr><td style="background-color: #FFF2C5;">{{nameform.display_as.label}}: </td>
<td>{% render form.display_as user action %}</td> <td>{% render nameform.display_as user action %}</td>
</tr> </tr>
<tr><td style="background-color: #FFF2C5;">{{form.text.label}}: </td> <tr><td style="background-color: #FFF2C5;">{{nameform.text.label}}: </td>
<td>{% render form.text user action %}</td> <td>{% render nameform.text user action %}</td>
</tr> </tr>
</table> </table>
</div> </div>
&nbsp; &nbsp;
</div> </div>
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tab-surnames"> <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 %} {% surname_table person user action "/person/%s/name/%s/surname" person.handle nameform.model.order %}
</div> </div>
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tab-names"> <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 %} {% name_table person user action "/person/%s/name" person.handle %}
</div> </div>
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tab-sources"> <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 %} {% source_table nameform.model user action "/person/%s/name/%s/source" person.handle nameform.model.order %}
</div> </div>
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom <div class="ui-tabs-panel ui-widget-content ui-corner-bottom
ui-tabs-hide" id="tab-notes"> ui-tabs-hide" id="tab-notes">
{% note_table form.model user action "/person/%s/name/%s/note" person.handle form.model.order %} {% note_table nameform.model user action "/person/%s/name/%s/note" person.handle nameform.model.order %}
</div> </div>
</div> </div>

View File

@ -116,35 +116,35 @@ class NameType(mGrampsType):
from gen.lib.nametype import NameType from gen.lib.nametype import NameType
_DATAMAP = get_datamap(NameType) _DATAMAP = get_datamap(NameType)
_CUSTOM = NameType._CUSTOM _CUSTOM = NameType._CUSTOM
_DEFAULT = [x for x in _DATAMAP if x[0] == NameType._DEFAULT] _DEFAULT = [x for x in _DATAMAP if x[0] == NameType._DEFAULT][0]
val = models.IntegerField('name type', choices=_DATAMAP, blank=False) val = models.IntegerField('name type', choices=_DATAMAP, blank=False)
class NameOriginType(mGrampsType): class NameOriginType(mGrampsType):
from gen.lib.nameorigintype import NameOriginType from gen.lib.nameorigintype import NameOriginType
_DATAMAP = get_datamap(NameOriginType) _DATAMAP = get_datamap(NameOriginType)
_CUSTOM = NameOriginType._CUSTOM _CUSTOM = NameOriginType._CUSTOM
_DEFAULT = [x for x in _DATAMAP if x[0] == NameOriginType._DEFAULT] _DEFAULT = [x for x in _DATAMAP if x[0] == NameOriginType._DEFAULT][0]
val = models.IntegerField('name origin type', choices=_DATAMAP, blank=False) val = models.IntegerField('name origin type', choices=_DATAMAP, blank=False)
class AttributeType(mGrampsType): class AttributeType(mGrampsType):
from gen.lib.attrtype import AttributeType from gen.lib.attrtype import AttributeType
_DATAMAP = get_datamap(AttributeType) _DATAMAP = get_datamap(AttributeType)
_CUSTOM = AttributeType._CUSTOM _CUSTOM = AttributeType._CUSTOM
_DEFAULT = [x for x in _DATAMAP if x[0] == AttributeType._DEFAULT] _DEFAULT = [x for x in _DATAMAP if x[0] == AttributeType._DEFAULT][0]
val = models.IntegerField('attribute type', choices=_DATAMAP, blank=False) val = models.IntegerField('attribute type', choices=_DATAMAP, blank=False)
class UrlType(mGrampsType): class UrlType(mGrampsType):
from gen.lib.urltype import UrlType from gen.lib.urltype import UrlType
_DATAMAP = get_datamap(UrlType) _DATAMAP = get_datamap(UrlType)
_CUSTOM = UrlType._CUSTOM _CUSTOM = UrlType._CUSTOM
_DEFAULT = [x for x in _DATAMAP if x[0] == UrlType._DEFAULT] _DEFAULT = [x for x in _DATAMAP if x[0] == UrlType._DEFAULT][0]
val = models.IntegerField('url type', choices=_DATAMAP, blank=False) val = models.IntegerField('url type', choices=_DATAMAP, blank=False)
class ChildRefType(mGrampsType): class ChildRefType(mGrampsType):
from gen.lib.childreftype import ChildRefType from gen.lib.childreftype import ChildRefType
_DATAMAP = get_datamap(ChildRefType) _DATAMAP = get_datamap(ChildRefType)
_CUSTOM = ChildRefType._CUSTOM _CUSTOM = ChildRefType._CUSTOM
_DEFAULT = [x for x in _DATAMAP if x[0] == ChildRefType._DEFAULT] _DEFAULT = [x for x in _DATAMAP if x[0] == ChildRefType._DEFAULT][0]
val = models.IntegerField('child reference type', choices=_DATAMAP, val = models.IntegerField('child reference type', choices=_DATAMAP,
blank=False) blank=False)
@ -152,14 +152,14 @@ class RepositoryType(mGrampsType):
from gen.lib.repotype import RepositoryType from gen.lib.repotype import RepositoryType
_DATAMAP = get_datamap(RepositoryType) _DATAMAP = get_datamap(RepositoryType)
_CUSTOM = RepositoryType._CUSTOM _CUSTOM = RepositoryType._CUSTOM
_DEFAULT = [x for x in _DATAMAP if x[0] == RepositoryType._DEFAULT] _DEFAULT = [x for x in _DATAMAP if x[0] == RepositoryType._DEFAULT][0]
val = models.IntegerField('repository type', choices=_DATAMAP, blank=False) val = models.IntegerField('repository type', choices=_DATAMAP, blank=False)
class EventType(mGrampsType): class EventType(mGrampsType):
from gen.lib.eventtype import EventType from gen.lib.eventtype import EventType
_DATAMAP = get_datamap(EventType) _DATAMAP = get_datamap(EventType)
_CUSTOM = EventType._CUSTOM _CUSTOM = EventType._CUSTOM
_DEFAULT = [x for x in _DATAMAP if x[0] == EventType._DEFAULT] _DEFAULT = [x for x in _DATAMAP if x[0] == EventType._DEFAULT][0]
BIRTH = 12 BIRTH = 12
DEATH = 13 DEATH = 13
val = models.IntegerField('event type', choices=_DATAMAP, blank=False) val = models.IntegerField('event type', choices=_DATAMAP, blank=False)
@ -168,7 +168,7 @@ class FamilyRelType(mGrampsType):
from gen.lib.familyreltype import FamilyRelType from gen.lib.familyreltype import FamilyRelType
_DATAMAP = get_datamap(FamilyRelType) _DATAMAP = get_datamap(FamilyRelType)
_CUSTOM = FamilyRelType._CUSTOM _CUSTOM = FamilyRelType._CUSTOM
_DEFAULT = [x for x in _DATAMAP if x[0] == FamilyRelType._DEFAULT] _DEFAULT = [x for x in _DATAMAP if x[0] == FamilyRelType._DEFAULT][0]
val = models.IntegerField('family relation type', choices=_DATAMAP, val = models.IntegerField('family relation type', choices=_DATAMAP,
blank=False) blank=False)
@ -176,7 +176,7 @@ class SourceMediaType(mGrampsType):
from gen.lib.srcmediatype import SourceMediaType from gen.lib.srcmediatype import SourceMediaType
_DATAMAP = get_datamap(SourceMediaType) _DATAMAP = get_datamap(SourceMediaType)
_CUSTOM = SourceMediaType._CUSTOM _CUSTOM = SourceMediaType._CUSTOM
_DEFAULT = [x for x in _DATAMAP if x[0] == SourceMediaType._DEFAULT] _DEFAULT = [x for x in _DATAMAP if x[0] == SourceMediaType._DEFAULT][0]
val = models.IntegerField('source medium type', choices=_DATAMAP, val = models.IntegerField('source medium type', choices=_DATAMAP,
blank=False) blank=False)
@ -184,14 +184,14 @@ class EventRoleType(mGrampsType):
from gen.lib.eventroletype import EventRoleType from gen.lib.eventroletype import EventRoleType
_DATAMAP = get_datamap(EventRoleType) _DATAMAP = get_datamap(EventRoleType)
_CUSTOM = EventRoleType._CUSTOM _CUSTOM = EventRoleType._CUSTOM
_DEFAULT = [x for x in _DATAMAP if x[0] == EventRoleType._DEFAULT] _DEFAULT = [x for x in _DATAMAP if x[0] == EventRoleType._DEFAULT][0]
val = models.IntegerField('event role type', choices=_DATAMAP, blank=False) val = models.IntegerField('event role type', choices=_DATAMAP, blank=False)
class NoteType(mGrampsType): class NoteType(mGrampsType):
from gen.lib.notetype import NoteType from gen.lib.notetype import NoteType
_DATAMAP = get_datamap(NoteType) _DATAMAP = get_datamap(NoteType)
_CUSTOM = NoteType._CUSTOM _CUSTOM = NoteType._CUSTOM
_DEFAULT = [x for x in _DATAMAP if x[0] == NoteType._DEFAULT] _DEFAULT = [x for x in _DATAMAP if x[0] == NoteType._DEFAULT][0]
val = models.IntegerField('note type', choices=_DATAMAP, blank=False) val = models.IntegerField('note type', choices=_DATAMAP, blank=False)
class MarkupType(mGrampsType): class MarkupType(mGrampsType):
@ -258,7 +258,7 @@ class CalendarType(mGrampsType):
(CAL_ISLAMIC, "Islamic"), (CAL_ISLAMIC, "Islamic"),
(CAL_SWEDISH, "Swedish")] (CAL_SWEDISH, "Swedish")]
_DEFAULT = [x for x in _DATAMAP if x[0] == CAL_GREGORIAN] _DEFAULT = [x for x in _DATAMAP if x[0] == CAL_GREGORIAN][0]
val = models.IntegerField('Calendar', choices=_DATAMAP, blank=False) val = models.IntegerField('Calendar', choices=_DATAMAP, blank=False)
class DateModifierType(mGrampsType): class DateModifierType(mGrampsType):
@ -278,7 +278,7 @@ class DateModifierType(mGrampsType):
(MOD_SPAN, "Span"), (MOD_SPAN, "Span"),
(MOD_TEXTONLY, "Text only")] (MOD_TEXTONLY, "Text only")]
_DEFAULT = [x for x in _DATAMAP if x[0] == MOD_NONE] _DEFAULT = [x for x in _DATAMAP if x[0] == MOD_NONE][0]
val = models.IntegerField('Date modifier', choices=_DATAMAP, blank=False) val = models.IntegerField('Date modifier', choices=_DATAMAP, blank=False)
class DateNewYearType(mGrampsType): class DateNewYearType(mGrampsType):
@ -292,7 +292,7 @@ class DateNewYearType(mGrampsType):
(NEWYEAR_MAR25, "March 25"), (NEWYEAR_MAR25, "March 25"),
(NEWYEAR_SEP1, "September 1")] (NEWYEAR_SEP1, "September 1")]
_DEFAULT = [x for x in _DATAMAP if x[0] == NEWYEAR_JAN1] _DEFAULT = [x for x in _DATAMAP if x[0] == NEWYEAR_JAN1][0]
val = models.IntegerField('New Year start date', choices=_DATAMAP, blank=False) val = models.IntegerField('New Year start date', choices=_DATAMAP, blank=False)
class ThemeType(mGrampsType): class ThemeType(mGrampsType):
@ -305,7 +305,6 @@ class ThemeType(mGrampsType):
"Web_Basic-Peach.css", "Web_Basic-Peach.css",
"Web_Visually.css", "Web_Visually.css",
"Web_Basic-Spruce.css",])) "Web_Basic-Spruce.css",]))
_DEFAULT = _DATAMAP[0] _DEFAULT = _DATAMAP[0]
val = models.IntegerField('Theme', choices=_DATAMAP, blank=False) val = models.IntegerField('Theme', choices=_DATAMAP, blank=False)

View File

@ -174,8 +174,8 @@ def view_surname(request, handle, order, sorder, action="view"):
person = Person.objects.get(handle=handle) person = Person.objects.get(handle=handle)
name = person.name_set.filter(order=order)[0] name = person.name_set.filter(order=order)[0]
surname = name.surname_set.filter()[int(sorder) - 1] # sorder is 1-based surname = name.surname_set.filter()[int(sorder) - 1] # sorder is 1-based
form = NameForm(instance=name) nameform = NameForm(instance=name)
form.model = name nameform.model = name
if action == "save": if action == "save":
active = "view" active = "view"
@ -187,7 +187,7 @@ 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["form"] = form context["nameform"] = form
context["order"] = name.order context["order"] = name.order
context["sorder"] = sorder context["sorder"] = sorder
view_template = 'view_surname.html' view_template = 'view_surname.html'
@ -199,19 +199,12 @@ def view_name(request, handle, order, action="view"):
action = "add" action = "add"
if request.POST.has_key("action"): if request.POST.has_key("action"):
action = request.POST.get("action") action = request.POST.get("action")
### Process action:
if action == "view": if action == "view":
person = Person.objects.get(handle=handle) pf, nf, sf, person = get_person_forms(handle)
try: name = nf.model
name = person.name_set.filter(order=order)[0]
except:
return fix_person(request, person)
form = NameForm(instance=name)
form.model = name
elif action == "edit": elif action == "edit":
person = Person.objects.get(handle=handle) pf, nf, sf, person = get_person_forms(handle)
name = person.name_set.filter(order=order)[0]
form = NameForm(instance=name)
form.model = name
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,17 +219,18 @@ def view_name(request, handle, order, action="view"):
was_preferred = False was_preferred = False
names[count].order = count names[count].order = count
names[count].save() names[count].save()
form = NameForm() nf = NameForm()
name = Name() name = Name()
nf.model = name
action = "back" action = "back"
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.objects.get(val=0), display_as=NameFormatType._DEFAULT[0],
sort_as=NameFormatType.objects.get(val=0), sort_as=NameFormatType._DEFAULT[0],
name_type=NameType.objects.get(val=2)) name_type=NameType._DEFAULT[0])
form = NameForm(instance=name) nf = NameForm(instance=name)
form.model = name nf.model = name
action = "edit" action = "edit"
elif action == "save": elif action == "save":
person = Person.objects.get(handle=handle) person = Person.objects.get(handle=handle)
@ -272,10 +266,11 @@ def view_name(request, handle, order, action="view"):
context["id"] = id context["id"] = id
context["person"] = person context["person"] = person
context["object"] = person context["object"] = person
context["form"] = form context["nameform"] = nf
context["surnameform"] = sf
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.html" view_template = "view_name_detail.html"
if action == "save": if action == "save":
context["action"] = "view" context["action"] = "view"
return redirect("/person/%s/name/%d" % (person.handle, name.order)) return redirect("/person/%s/name/%d" % (person.handle, name.order))
@ -939,14 +934,15 @@ def get_person_forms(handle, protect=False, empty=False):
name = person.name_set.get(preferred=True) name = person.name_set.get(preferred=True)
except: except:
name = Name(person=person, preferred=True, name = Name(person=person, preferred=True,
display_as=NameFormatType.objects.get(val=0), display_as=NameFormatType.objects.get(val=NameFormatType._DEFAULT[0]),
sort_as=NameFormatType.objects.get(val=0), sort_as=NameFormatType.objects.get(val=NameFormatType._DEFAULT[0]),
name_type=NameType.objects.get(val=2)) name_type=NameType.objects.get(val=NameType._DEFAULT[0]))
## get a surname ## get a surname
try: try:
surname = name.surname_set.get(primary=True) surname = name.surname_set.get(primary=True)
except: except:
surname = Surname(name=name, primary=True) surname = Surname(name=name, primary=True, name_origin_type=NameOriginType.objects.get(val=NameOriginType._DEFAULT[0]),)
if protect and person.probably_alive: if protect and person.probably_alive:
name.sanitize() name.sanitize()
pf = PersonForm(instance=person) pf = PersonForm(instance=person)

View File

@ -75,7 +75,7 @@ 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+))$', 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+))/(?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+))$', 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+))/surname/(?P<sorder>(\w+))/(?P<action>(\w+))$', view_surname),