Proper editing of person, name, surname; fixed default types
svn: r19544
This commit is contained in:
parent
ba4f791bb7
commit
82bcb4018c
@ -25,6 +25,9 @@
|
||||
{% for error in nameform.errors %}
|
||||
Error in name: {{error}}<br>
|
||||
{% endfor %}
|
||||
{% for error in surnameform.errors %}
|
||||
Error in surname: {{error}}<br>
|
||||
{% endfor %}
|
||||
{% endifequal %}
|
||||
{% endif %}
|
||||
<form method="post">{% csrf_token %}
|
||||
@ -47,11 +50,11 @@
|
||||
<td class="ColumnValue" id="data">{% render nameform.suffix user action %}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="ColumnAttribute" align="right">{{nameform.surname.label}}:</td>
|
||||
<td class="ColumnValue" id="data">{% render nameform.prefix user action %}</td>
|
||||
<td class="ColumnValue" id="data" colspan="2">{% render nameform.surname user action %}</td>
|
||||
<td class="ColumnAttribute" align="right">{{nameform.name_origin_type.label}}:</td>
|
||||
<td class="ColumnValue" id="data" colspan="2">{% render nameform.name_origin_type user action %}</td>
|
||||
<td class="ColumnAttribute" align="right">{{surnameform.surname.label}}:</td>
|
||||
<td class="ColumnValue" id="data">{% render surnameform.prefix user action %}</td>
|
||||
<td class="ColumnValue" id="data" colspan="2">{% render surnameform.surname user action %}</td>
|
||||
<td class="ColumnAttribute" align="right">{{surnameform.name_origin_type.label}}:</td>
|
||||
<td class="ColumnValue" id="data" colspan="2">{% render surnameform.name_origin_type user action %}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="ColumnAttribute" align="right">{{personform.gender_type.label}}:</td>
|
||||
|
@ -33,7 +33,8 @@ import datetime
|
||||
class PersonForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Person
|
||||
exclude = ["death", "birth", "handle", "birth_ref_index", "death_ref_index"]
|
||||
exclude = ["death", "birth", "handle", "birth_ref_index",
|
||||
"death_ref_index"]
|
||||
|
||||
class NameForm(forms.ModelForm):
|
||||
class Meta:
|
||||
@ -47,14 +48,56 @@ class NameForm(forms.ModelForm):
|
||||
"sortval", "newyear", "person"]
|
||||
# Add these because they are TextFields, which render as
|
||||
# Textareas:
|
||||
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'}))
|
||||
call = forms.CharField(label="Call",
|
||||
required=False,
|
||||
widget=TextInput(attrs={'size':'15'}))
|
||||
nick = forms.CharField(label="Nick",
|
||||
required=False,
|
||||
widget=TextInput(attrs={'size':'15'}))
|
||||
suffix = forms.CharField(required=False,
|
||||
initial=' suffix ',
|
||||
widget=TextInput(attrs={'size':'15',
|
||||
'style': 'font-style: italic; color: gray; ',
|
||||
'onFocus': """if (this.value == ' suffix ') {
|
||||
this.value = '';
|
||||
}
|
||||
this.style.color = "black";
|
||||
this.style.fontStyle = 'normal';
|
||||
""",
|
||||
'onBlur': """if (this.value == '') {
|
||||
this.value = ' suffix ';
|
||||
this.style.color = "gray";
|
||||
this.style.fontStyle = 'italic';
|
||||
}
|
||||
"""}))
|
||||
|
||||
class NameFormFromPerson(NameForm):
|
||||
class Meta:
|
||||
model = Name
|
||||
# Exclude these, so they don't get checked:
|
||||
# Excludes sort_as and display_as
|
||||
exclude = ["order", "calendar", "modifier",
|
||||
"quality",
|
||||
#"quality_estimated", "quality_calculated",
|
||||
#"quality_interpreted",
|
||||
"year1", "day1", "month1",
|
||||
"sortval", "newyear", "person",
|
||||
"sort_as", "display_as"]
|
||||
|
||||
class SurnameForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Surname
|
||||
exclude = ['name']
|
||||
|
||||
surname = forms.CharField(label="Surname",
|
||||
required=False,
|
||||
widget=TextInput(attrs={'size':'30'}))
|
||||
|
||||
prefix = forms.CharField(label="Prefix",
|
||||
required=False,
|
||||
initial=' prefix ',
|
||||
@ -72,41 +115,3 @@ class NameForm(forms.ModelForm):
|
||||
this.style.fontStyle = 'italic';
|
||||
}
|
||||
"""}))
|
||||
suffix = forms.CharField(required=False,
|
||||
initial=' suffix ',
|
||||
widget=TextInput(attrs={'size':'15',
|
||||
'style': 'font-style: italic; color: gray; ',
|
||||
'onFocus': """if (this.value == ' suffix ') {
|
||||
this.value = '';
|
||||
}
|
||||
this.style.color = "black";
|
||||
this.style.fontStyle = 'normal';
|
||||
""",
|
||||
'onBlur': """if (this.value == '') {
|
||||
this.value = ' suffix ';
|
||||
this.style.color = "gray";
|
||||
this.style.fontStyle = 'italic';
|
||||
}
|
||||
"""}))
|
||||
call = forms.CharField(label="Call",
|
||||
required=False,
|
||||
widget=TextInput(attrs={'size':'15'}))
|
||||
nick = forms.CharField(label="Nick",
|
||||
required=False,
|
||||
widget=TextInput(attrs={'size':'15'}))
|
||||
|
||||
name_origin_type = forms.ChoiceField()
|
||||
|
||||
class NameFormFromPerson(NameForm):
|
||||
class Meta:
|
||||
model = Name
|
||||
# Exclude these, so they don't get checked:
|
||||
# Excludes sort_as and display_as
|
||||
exclude = ["order", "calendar", "modifier",
|
||||
"quality",
|
||||
#"quality_estimated", "quality_calculated",
|
||||
#"quality_interpreted",
|
||||
"year1", "day1", "month1",
|
||||
"sortval", "newyear", "person",
|
||||
"sort_as", "display_as"]
|
||||
|
||||
|
@ -115,35 +115,35 @@ class NameType(mGrampsType):
|
||||
from gen.lib.nametype import NameType
|
||||
_DATAMAP = get_datamap(NameType)
|
||||
_CUSTOM = NameType._CUSTOM
|
||||
_DEFAULT = _DATAMAP[NameType._DEFAULT]
|
||||
_DEFAULT = [x for x in _DATAMAP if x[0] == NameType._DEFAULT]
|
||||
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 = _DATAMAP[NameOriginType._DEFAULT]
|
||||
_DEFAULT = [x for x in _DATAMAP if x[0] == NameOriginType._DEFAULT]
|
||||
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 = _DATAMAP[AttributeType._DEFAULT]
|
||||
_DEFAULT = [x for x in _DATAMAP if x[0] == AttributeType._DEFAULT]
|
||||
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 = _DATAMAP[UrlType._DEFAULT]
|
||||
_DEFAULT = [x for x in _DATAMAP if x[0] == UrlType._DEFAULT]
|
||||
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 = _DATAMAP[ChildRefType._DEFAULT]
|
||||
_DEFAULT = [x for x in _DATAMAP if x[0] == ChildRefType._DEFAULT]
|
||||
val = models.IntegerField('child reference type', choices=_DATAMAP,
|
||||
blank=False)
|
||||
|
||||
@ -151,14 +151,14 @@ class RepositoryType(mGrampsType):
|
||||
from gen.lib.repotype import RepositoryType
|
||||
_DATAMAP = get_datamap(RepositoryType)
|
||||
_CUSTOM = RepositoryType._CUSTOM
|
||||
_DEFAULT = _DATAMAP[RepositoryType._DEFAULT]
|
||||
_DEFAULT = [x for x in _DATAMAP if x[0] == RepositoryType._DEFAULT]
|
||||
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 = _DATAMAP[EventType._DEFAULT]
|
||||
_DEFAULT = [x for x in _DATAMAP if x[0] == EventType._DEFAULT]
|
||||
BIRTH = 12
|
||||
DEATH = 13
|
||||
val = models.IntegerField('event type', choices=_DATAMAP, blank=False)
|
||||
@ -167,7 +167,7 @@ class FamilyRelType(mGrampsType):
|
||||
from gen.lib.familyreltype import FamilyRelType
|
||||
_DATAMAP = get_datamap(FamilyRelType)
|
||||
_CUSTOM = FamilyRelType._CUSTOM
|
||||
_DEFAULT = _DATAMAP[FamilyRelType._DEFAULT]
|
||||
_DEFAULT = [x for x in _DATAMAP if x[0] == FamilyRelType._DEFAULT]
|
||||
val = models.IntegerField('family relation type', choices=_DATAMAP,
|
||||
blank=False)
|
||||
|
||||
@ -175,7 +175,7 @@ class SourceMediaType(mGrampsType):
|
||||
from gen.lib.srcmediatype import SourceMediaType
|
||||
_DATAMAP = get_datamap(SourceMediaType)
|
||||
_CUSTOM = SourceMediaType._CUSTOM
|
||||
_DEFAULT = _DATAMAP[SourceMediaType._DEFAULT]
|
||||
_DEFAULT = [x for x in _DATAMAP if x[0] == SourceMediaType._DEFAULT]
|
||||
val = models.IntegerField('source medium type', choices=_DATAMAP,
|
||||
blank=False)
|
||||
|
||||
@ -183,14 +183,14 @@ class EventRoleType(mGrampsType):
|
||||
from gen.lib.eventroletype import EventRoleType
|
||||
_DATAMAP = get_datamap(EventRoleType)
|
||||
_CUSTOM = EventRoleType._CUSTOM
|
||||
_DEFAULT = _DATAMAP[EventRoleType._DEFAULT]
|
||||
_DEFAULT = [x for x in _DATAMAP if x[0] == EventRoleType._DEFAULT]
|
||||
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 = _DATAMAP[NoteType._DEFAULT]
|
||||
_DEFAULT = [x for x in _DATAMAP if x[0] == NoteType._DEFAULT]
|
||||
val = models.IntegerField('note type', choices=_DATAMAP, blank=False)
|
||||
|
||||
class MarkupType(mGrampsType):
|
||||
@ -257,7 +257,7 @@ class CalendarType(mGrampsType):
|
||||
(CAL_ISLAMIC, "Islamic"),
|
||||
(CAL_SWEDISH, "Swedish")]
|
||||
|
||||
_DEFAULT = _DATAMAP[CAL_GREGORIAN]
|
||||
_DEFAULT = [x for x in _DATAMAP if x[0] == CAL_GREGORIAN]
|
||||
val = models.IntegerField('Calendar', choices=_DATAMAP, blank=False)
|
||||
|
||||
class DateModifierType(mGrampsType):
|
||||
@ -277,7 +277,7 @@ class DateModifierType(mGrampsType):
|
||||
(MOD_SPAN, "Span"),
|
||||
(MOD_TEXTONLY, "Text only")]
|
||||
|
||||
_DEFAULT = _DATAMAP[MOD_NONE]
|
||||
_DEFAULT = [x for x in _DATAMAP if x[0] == MOD_NONE]
|
||||
val = models.IntegerField('Date modifier', choices=_DATAMAP, blank=False)
|
||||
|
||||
class DateNewYearType(mGrampsType):
|
||||
@ -291,7 +291,7 @@ class DateNewYearType(mGrampsType):
|
||||
(NEWYEAR_MAR25, "March 25"),
|
||||
(NEWYEAR_SEP1, "September 1")]
|
||||
|
||||
_DEFAULT = _DATAMAP[NEWYEAR_JAN1]
|
||||
_DEFAULT = [x for x in _DATAMAP if x[0] == NEWYEAR_JAN1]
|
||||
val = models.IntegerField('New Year start date', choices=_DATAMAP, blank=False)
|
||||
|
||||
class ThemeType(mGrampsType):
|
||||
|
@ -495,7 +495,7 @@ def view_person_detail(request, view, handle, action="view"):
|
||||
action = request.POST.get("action")
|
||||
if request.user.is_authenticated():
|
||||
if action == "edit":
|
||||
pf, nf, person = get_person_forms(handle, empty=True)
|
||||
pf, nf, sf, person = get_person_forms(handle, empty=True)
|
||||
elif action == "add":
|
||||
# make new data:
|
||||
person = Person()
|
||||
@ -530,16 +530,20 @@ def view_person_detail(request, view, handle, action="view"):
|
||||
pf.model = person
|
||||
nf = NameFormFromPerson(request.POST, instance=name)
|
||||
nf.model = name
|
||||
if nf.is_valid() and pf.is_valid():
|
||||
sf = SurnameForm(request.POST, instance=surname)
|
||||
if nf.is_valid() and pf.is_valid() and sf.is_valid():
|
||||
person = pf.save()
|
||||
# Process data:
|
||||
name = nf.save(commit=False)
|
||||
# Manually set any name data:
|
||||
# Manually set any data:
|
||||
name.suffix = nf.cleaned_data["suffix"] if nf.cleaned_data["suffix"] != " suffix " else ""
|
||||
name.preferred = True # FIXME: why is this False?
|
||||
name.save()
|
||||
# Manually set surname data:
|
||||
surname.surname = nf.cleaned_data["surname"]
|
||||
surname.prefix = nf.cleaned_data["prefix"] if nf.cleaned_data["prefix"] != " prefix " else ""
|
||||
surname.name = name
|
||||
# Process data:
|
||||
surname = sf.save(commit=False)
|
||||
# Manually set any data:
|
||||
surname.prefix = sf.cleaned_data["prefix"] if sf.cleaned_data["prefix"] != " prefix " else ""
|
||||
surname.primary = True # FIXME: why is this False?
|
||||
surname.save()
|
||||
# FIXME: last_saved, last_changed, last_changed_by
|
||||
# FIXME: update cache
|
||||
@ -548,7 +552,7 @@ def view_person_detail(request, view, handle, action="view"):
|
||||
else: # not valid, try again:
|
||||
action = "edit"
|
||||
else: # view
|
||||
pf, nf, person = get_person_forms(handle)
|
||||
pf, nf, sf, person = get_person_forms(handle)
|
||||
else: # view person detail
|
||||
# BEGIN NON-AUTHENTICATED ACCESS
|
||||
try:
|
||||
@ -557,13 +561,14 @@ def view_person_detail(request, view, handle, action="view"):
|
||||
raise Http404(_("Requested %s does not exist.") % view)
|
||||
if person.private:
|
||||
raise Http404(_("Requested %s is not accessible.") % view)
|
||||
pf, nf, person = get_person_forms(handle, protect=True)
|
||||
pf, nf, sf, person = get_person_forms(handle, protect=True)
|
||||
# END NON-AUTHENTICATED ACCESS
|
||||
context["action"] = action
|
||||
context["view"] = view
|
||||
context["tview"] = _("Person")
|
||||
context["personform"] = pf
|
||||
context["nameform"] = nf
|
||||
context["surnameform"] = sf
|
||||
context["person"] = person
|
||||
context["object"] = person
|
||||
context["next"] = "/person/%s" % person.handle
|
||||
@ -577,26 +582,20 @@ def get_person_forms(handle, protect=False, empty=False):
|
||||
except:
|
||||
name = Name(person=person, preferred=True)
|
||||
try:
|
||||
primary_surname = name.surname_set.get(primary=True)
|
||||
surname = name.surname_set.get(primary=True)
|
||||
except:
|
||||
primary_surname = Surname(name=name, primary=True)
|
||||
surname = Surname(name=name, primary=True)
|
||||
if protect and person.probably_alive:
|
||||
name.sanitize()
|
||||
default_data = {"surname": primary_surname.surname,
|
||||
"prefix": make_empty(empty, primary_surname.prefix, " prefix "),
|
||||
"suffix": make_empty(empty, name.suffix, " suffix "),
|
||||
"first_name": name.first_name,
|
||||
"name_type": name.name_type,
|
||||
"name_origin_type": primary_surname.name_origin_type,
|
||||
"title": name.title,
|
||||
"nick": name.nick,
|
||||
"call": name.call,
|
||||
}
|
||||
pf = PersonForm(instance=person)
|
||||
pf.model = person
|
||||
nf = NameForm(default_data, instance=name)
|
||||
name.suffix = make_empty(empty, name.suffix, " suffix ")
|
||||
nf = NameForm(instance=name)
|
||||
nf.model = name
|
||||
return pf, nf, person
|
||||
surname.prefix = make_empty(empty, surname.prefix, " prefix ")
|
||||
sf = SurnameForm(instance=surname)
|
||||
sf.model = surname
|
||||
return pf, nf, sf, person
|
||||
|
||||
def make_empty(empty, value, empty_value):
|
||||
if value:
|
||||
|
Loading…
Reference in New Issue
Block a user