prefix/suffix updates; working on editing person

svn: r19532
This commit is contained in:
Doug Blank 2012-05-15 20:27:53 +00:00
parent 70b9a8bef0
commit 23114ebe86
2 changed files with 62 additions and 37 deletions

View File

@ -57,29 +57,37 @@ class NameForm(forms.ModelForm):
widget=TextInput(attrs={'size':'15'}))
prefix = forms.CharField(label="Prefix",
required=False,
initial='prefix',
initial=' prefix ',
widget=TextInput(attrs={'size':'15',
'style': 'font-style: italic; color: gray; ',
'onFocus': """if (this.value == 'prefix') {this.value = '';
this.style.color = "black";
this.style.fontStyle = 'normal';
}""",
'onBlur': """if (this.value == '') {this.value = 'prefix';
this.style.color = "gray";
this.style.fontStyle = 'italic';
}"""}))
'onFocus': """if (this.value == ' prefix ') {
this.value = '';
}
this.style.color = "black";
this.style.fontStyle = 'normal';
""",
'onBlur': """if (this.value == '') {
this.value = ' prefix ';
this.style.color = "gray";
this.style.fontStyle = 'italic';
}
"""}))
suffix = forms.CharField(required=False,
initial='suffix',
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';
}"""}))
'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'}))
@ -87,7 +95,7 @@ class NameForm(forms.ModelForm):
required=False,
widget=TextInput(attrs={'size':'15'}))
origin = forms.CharField(required=False,
widget=TextInput(attrs={'size':'15'}))
widget=TextInput(attrs={'size':'15'}))
class NameFormFromPerson(NameForm):
class Meta:

View File

@ -500,10 +500,13 @@ def view_person_detail(request, view, handle, action="view"):
name = person.name_set.get(preferred=True)
except:
name = Name(person=person, preferred=True)
primary_surname = name.surname_set.get(primary=True)
try:
primary_surname = name.surname_set.get(primary=True)
except:
primary_surname = Surname(name=name, primary=True)
default_data = {"surname": primary_surname.surname,
"prefix": primary_surname.prefix or "prefix",
"suffix": name.suffix or "suffix",
"prefix": primary_surname.prefix or " prefix ",
"suffix": name.suffix or " suffix ",
"first_name": name.first_name,
"name_type": name.name_type,
"title": name.title,
@ -532,8 +535,16 @@ def view_person_detail(request, view, handle, action="view"):
except:
person = Person(handle=create_id())
if person.id: # editing
name = person.name_set.get(preferred=True)
surname = name.surname_set.get(primary=True)
try:
name = person.name_set.get(preferred=True)
except:
name = Name(person=person, preferred=True)
name.save()
try:
surname = name.surname_set.get(primary=True)
except:
surname = Surname(name=name, primary=True)
name.surname_set = [surname]
else: # adding a new person with new name
name = Name(person=person, preferred=True)
surname = Surname(name=name, primary=True)
@ -544,32 +555,38 @@ def view_person_detail(request, view, handle, action="view"):
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"]
surname.prefix = nf.cleaned_data["prefix"] if nf.cleaned_data["prefix"] != " prefix " else ""
name.suffix = nf.cleaned_data["suffix"] if nf.cleaned_data["suffix"] != " suffix " else ""
person = pf.save()
name = nf.save(commit=False)
name.person = person
name.save()
surname.save()
name.save()
else:
action = "edit"
else: # view
# get all of the data:
person = Person.objects.get(handle=handle)
try:
name = person.name_set.get(preferred=True)
except:
return fix_person(request, person)
name = Name(person=person, preferred=True)
try:
primary_surname = name.surname_set.get(primary=True)
except:
primary_surname = Surname(name=name, primary=True)
default_data = {"surname": primary_surname.surname,
"prefix": primary_surname.prefix or " prefix ",
"suffix": name.suffix or " suffix ",
"first_name": name.first_name,
"name_type": name.name_type,
"title": name.title,
"nick": name.nick,
"call": name.call,
}
pf = PersonForm(instance=person)
pf.model = person
nf = NameForm(instance=name)
try:
primary = name.surname_set.get(primary=True)
except:
primary = Surname()
primary.name = name
nf.prefix=primary.prefix
nf.surname=primary.surname
nf.origin=primary.name_origin_type
nf = NameForm(default_data, instance=name)
nf.model = name
else: # view person detail
# BEGIN NON-AUTHENTICATED ACCESS