Working on name editing with refactor
svn: r19610
This commit is contained in:
parent
9e148614c6
commit
e495bb58df
@ -22,44 +22,41 @@
|
||||
<table class="infolist" style="width:90%;"> {% comment %} 4 cols {% endcomment %}
|
||||
<tbody>
|
||||
|
||||
{% if user.is_authenticated %}
|
||||
{% ifequal action "edit" %}
|
||||
{% for error in form.errors %}
|
||||
{{error}}<br>
|
||||
{% endfor %}
|
||||
{% endifequal %}
|
||||
{% endif %}
|
||||
{% for error in nameform.errors %}
|
||||
<p id="error">{{error}}</a><br>
|
||||
{% endfor %}
|
||||
|
||||
<form method="post">{% csrf_token %}
|
||||
<tr>
|
||||
<td class="ColumnAttribute">{{form.surname.label}}:</td>
|
||||
<td class="ColumnValue" id="data">{% render form.surname user action False "" "get_focus" %}</td>
|
||||
<td class="ColumnAttribute">{{form.prefix.label}}:</td>
|
||||
<td class="ColumnValue" id="data">{% render form.prefix user action %}</td>
|
||||
<td class="ColumnAttribute">{{surnameform.surname.label}}:</td>
|
||||
<td class="ColumnValue" id="data">{% render surnameform.surname user action False "" "get_focus" %}</td>
|
||||
<td class="ColumnAttribute">{{surnameform.prefix.label}}:</td>
|
||||
<td class="ColumnValue" id="data">{% render surnameform.prefix 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>
|
||||
<td class="ColumnAttribute">{{nameform.first_name.label}}:</td>
|
||||
<td class="ColumnValue" id="data">{% render nameform.first_name user action %}</td>
|
||||
<td class="ColumnAttribute">{{nameform.call.label}}:</td>
|
||||
<td class="ColumnValue" id="data">{% render nameform.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>
|
||||
<td class="ColumnAttribute">{{nameform.title.label}}:</td>
|
||||
<td class="ColumnValue" id="data">{% render nameform.title user action %}</td>
|
||||
<td class="ColumnAttribute">{{nameform.suffix.label}}:</td>
|
||||
<td class="ColumnValue" id="data">{% render nameform.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">{{nameform.name_type.label}}:</td>
|
||||
<td class="ColumnValue" id="data">{% render nameform.name_type user action %}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="ColumnAttribute">{{form.preferred.label}}:</td>
|
||||
{% if form.model.preferred %}
|
||||
<td class="ColumnAttribute">{{nameform.preferred.label}}:</td>
|
||||
{% if nameform.model.preferred %}
|
||||
<td class="ColumnValue" id="data">True</td>
|
||||
{% else %}
|
||||
<td class="ColumnValue" id="data">{% render form.preferred user action %}</td>
|
||||
<td class="ColumnValue" id="data">{% render nameform.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">{{nameform.private.label}}:</td>
|
||||
<td class="ColumnValue" id="data">{% render nameform.private user action %}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
@ -81,34 +78,34 @@
|
||||
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><td style="background-color: #FFF2C5;">{{nameform.group_as.label}}: </td>
|
||||
<td>{% render nameform.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><td style="background-color: #FFF2C5;">{{nameform.sort_as.label}}: </td>
|
||||
<td>{% render nameform.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><td style="background-color: #FFF2C5;">{{nameform.display_as.label}}: </td>
|
||||
<td>{% render nameform.display_as user action %}</td>
|
||||
</tr>
|
||||
<tr><td style="background-color: #FFF2C5;">{{form.text.label}}: </td>
|
||||
<td>{% render form.text user action %}</td>
|
||||
<tr><td style="background-color: #FFF2C5;">{{nameform.text.label}}: </td>
|
||||
<td>{% render nameform.text user action %}</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
</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 %}
|
||||
{% surname_table person user action "/person/%s/name/%s/surname" person.handle nameform.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>
|
||||
<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 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 %}
|
||||
{% note_table nameform.model user action "/person/%s/name/%s/note" person.handle nameform.model.order %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -116,35 +116,35 @@ class NameType(mGrampsType):
|
||||
from gen.lib.nametype import NameType
|
||||
_DATAMAP = get_datamap(NameType)
|
||||
_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)
|
||||
|
||||
class NameOriginType(mGrampsType):
|
||||
from gen.lib.nameorigintype import NameOriginType
|
||||
_DATAMAP = get_datamap(NameOriginType)
|
||||
_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)
|
||||
|
||||
class AttributeType(mGrampsType):
|
||||
from gen.lib.attrtype import AttributeType
|
||||
_DATAMAP = get_datamap(AttributeType)
|
||||
_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)
|
||||
|
||||
class UrlType(mGrampsType):
|
||||
from gen.lib.urltype import UrlType
|
||||
_DATAMAP = get_datamap(UrlType)
|
||||
_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)
|
||||
|
||||
class ChildRefType(mGrampsType):
|
||||
from gen.lib.childreftype import ChildRefType
|
||||
_DATAMAP = get_datamap(ChildRefType)
|
||||
_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,
|
||||
blank=False)
|
||||
|
||||
@ -152,14 +152,14 @@ class RepositoryType(mGrampsType):
|
||||
from gen.lib.repotype import RepositoryType
|
||||
_DATAMAP = get_datamap(RepositoryType)
|
||||
_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)
|
||||
|
||||
class EventType(mGrampsType):
|
||||
from gen.lib.eventtype import EventType
|
||||
_DATAMAP = get_datamap(EventType)
|
||||
_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
|
||||
DEATH = 13
|
||||
val = models.IntegerField('event type', choices=_DATAMAP, blank=False)
|
||||
@ -168,7 +168,7 @@ class FamilyRelType(mGrampsType):
|
||||
from gen.lib.familyreltype import FamilyRelType
|
||||
_DATAMAP = get_datamap(FamilyRelType)
|
||||
_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,
|
||||
blank=False)
|
||||
|
||||
@ -176,7 +176,7 @@ class SourceMediaType(mGrampsType):
|
||||
from gen.lib.srcmediatype import SourceMediaType
|
||||
_DATAMAP = get_datamap(SourceMediaType)
|
||||
_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,
|
||||
blank=False)
|
||||
|
||||
@ -184,14 +184,14 @@ class EventRoleType(mGrampsType):
|
||||
from gen.lib.eventroletype import EventRoleType
|
||||
_DATAMAP = get_datamap(EventRoleType)
|
||||
_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)
|
||||
|
||||
class NoteType(mGrampsType):
|
||||
from gen.lib.notetype import NoteType
|
||||
_DATAMAP = get_datamap(NoteType)
|
||||
_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)
|
||||
|
||||
class MarkupType(mGrampsType):
|
||||
@ -258,7 +258,7 @@ class CalendarType(mGrampsType):
|
||||
(CAL_ISLAMIC, "Islamic"),
|
||||
(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)
|
||||
|
||||
class DateModifierType(mGrampsType):
|
||||
@ -278,7 +278,7 @@ class DateModifierType(mGrampsType):
|
||||
(MOD_SPAN, "Span"),
|
||||
(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)
|
||||
|
||||
class DateNewYearType(mGrampsType):
|
||||
@ -292,20 +292,19 @@ class DateNewYearType(mGrampsType):
|
||||
(NEWYEAR_MAR25, "March 25"),
|
||||
(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)
|
||||
|
||||
class ThemeType(mGrampsType):
|
||||
_DATAMAP = list(enumerate(["Web_Mainz.css",
|
||||
"Web_Basic-Ash.css",
|
||||
"Web_Basic-Cypress.css",
|
||||
"Web_Nebraska.css",
|
||||
"Web_Basic-Lilac.css",
|
||||
"Web_Print-Default.css",
|
||||
"Web_Basic-Peach.css",
|
||||
"Web_Visually.css",
|
||||
"Web_Basic-Spruce.css",]))
|
||||
|
||||
"Web_Basic-Ash.css",
|
||||
"Web_Basic-Cypress.css",
|
||||
"Web_Nebraska.css",
|
||||
"Web_Basic-Lilac.css",
|
||||
"Web_Print-Default.css",
|
||||
"Web_Basic-Peach.css",
|
||||
"Web_Visually.css",
|
||||
"Web_Basic-Spruce.css",]))
|
||||
_DEFAULT = _DATAMAP[0]
|
||||
val = models.IntegerField('Theme', choices=_DATAMAP, blank=False)
|
||||
|
||||
|
@ -174,8 +174,8 @@ def view_surname(request, handle, order, sorder, action="view"):
|
||||
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
|
||||
nameform = NameForm(instance=name)
|
||||
nameform.model = name
|
||||
|
||||
if action == "save":
|
||||
active = "view"
|
||||
@ -187,7 +187,7 @@ def view_surname(request, handle, order, sorder, action="view"):
|
||||
context["id"] = id
|
||||
context["person"] = person
|
||||
context["object"] = person
|
||||
context["form"] = form
|
||||
context["nameform"] = form
|
||||
context["order"] = name.order
|
||||
context["sorder"] = sorder
|
||||
view_template = 'view_surname.html'
|
||||
@ -199,19 +199,12 @@ def view_name(request, handle, order, action="view"):
|
||||
action = "add"
|
||||
if request.POST.has_key("action"):
|
||||
action = request.POST.get("action")
|
||||
### Process action:
|
||||
if action == "view":
|
||||
person = Person.objects.get(handle=handle)
|
||||
try:
|
||||
name = person.name_set.filter(order=order)[0]
|
||||
except:
|
||||
return fix_person(request, person)
|
||||
form = NameForm(instance=name)
|
||||
form.model = name
|
||||
pf, nf, sf, person = get_person_forms(handle)
|
||||
name = nf.model
|
||||
elif action == "edit":
|
||||
person = Person.objects.get(handle=handle)
|
||||
name = person.name_set.filter(order=order)[0]
|
||||
form = NameForm(instance=name)
|
||||
form.model = name
|
||||
pf, nf, sf, person = get_person_forms(handle)
|
||||
elif action == "delete":
|
||||
person = Person.objects.get(handle=handle)
|
||||
names = person.name_set.all().order_by("order")
|
||||
@ -226,17 +219,18 @@ def view_name(request, handle, order, action="view"):
|
||||
was_preferred = False
|
||||
names[count].order = count
|
||||
names[count].save()
|
||||
form = NameForm()
|
||||
nf = NameForm()
|
||||
name = Name()
|
||||
nf.model = name
|
||||
action = "back"
|
||||
elif action == "add": # add name
|
||||
person = Person.objects.get(handle=handle)
|
||||
name = Name(person=person,
|
||||
display_as=NameFormatType.objects.get(val=0),
|
||||
sort_as=NameFormatType.objects.get(val=0),
|
||||
name_type=NameType.objects.get(val=2))
|
||||
form = NameForm(instance=name)
|
||||
form.model = name
|
||||
display_as=NameFormatType._DEFAULT[0],
|
||||
sort_as=NameFormatType._DEFAULT[0],
|
||||
name_type=NameType._DEFAULT[0])
|
||||
nf = NameForm(instance=name)
|
||||
nf.model = name
|
||||
action = "edit"
|
||||
elif action == "save":
|
||||
person = Person.objects.get(handle=handle)
|
||||
@ -272,10 +266,11 @@ def view_name(request, handle, order, action="view"):
|
||||
context["id"] = id
|
||||
context["person"] = person
|
||||
context["object"] = person
|
||||
context["form"] = form
|
||||
context["nameform"] = nf
|
||||
context["surnameform"] = sf
|
||||
context["order"] = 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":
|
||||
context["action"] = "view"
|
||||
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)
|
||||
except:
|
||||
name = Name(person=person, preferred=True,
|
||||
display_as=NameFormatType.objects.get(val=0),
|
||||
sort_as=NameFormatType.objects.get(val=0),
|
||||
name_type=NameType.objects.get(val=2))
|
||||
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]))
|
||||
## get a surname
|
||||
try:
|
||||
surname = name.surname_set.get(primary=True)
|
||||
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:
|
||||
name.sanitize()
|
||||
pf = PersonForm(instance=person)
|
||||
|
@ -75,7 +75,7 @@ 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+))$', 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),
|
||||
|
Loading…
Reference in New Issue
Block a user