diff --git a/src/data/templates/view_name_detail.html b/src/data/templates/view_name_detail.html index 2ffe02fa0..d12c61bbd 100644 --- a/src/data/templates/view_name_detail.html +++ b/src/data/templates/view_name_detail.html @@ -22,44 +22,41 @@ {% comment %} 4 cols {% endcomment %} -{% if user.is_authenticated %} - {% ifequal action "edit" %} - {% for error in form.errors %} - {{error}}
- {% endfor %} - {% endifequal %} -{% endif %} +{% for error in nameform.errors %} +

{{error}}
+{% endfor %} +
{% csrf_token %}

- - - - + + + + - - - - + + + + - - - - + + + + - - + + - -{% if form.model.preferred %} + +{% if nameform.model.preferred %} {% else %} - + {% endif %} - - + +
{{form.surname.label}}:{% render form.surname user action False "" "get_focus" %}{{form.prefix.label}}:{% render form.prefix user action %}{{surnameform.surname.label}}:{% render surnameform.surname user action False "" "get_focus" %}{{surnameform.prefix.label}}:{% render surnameform.prefix user action %}
{{form.first_name.label}}:{% render form.first_name user action %}{{form.call.label}}:{% render form.call user action %}{{nameform.first_name.label}}:{% render nameform.first_name user action %}{{nameform.call.label}}:{% render nameform.call user action %}
{{form.title.label}}:{% render form.title user action %}{{form.suffix.label}}:{% render form.suffix user action %}{{nameform.title.label}}:{% render nameform.title user action %}{{nameform.suffix.label}}:{% render nameform.suffix user action %}
{{form.name_type.label}}:{% render form.name_type user action %}{{nameform.name_type.label}}:{% render nameform.name_type user action %}
{{form.preferred.label}}:{{nameform.preferred.label}}:True{% render form.preferred user action %}{% render nameform.preferred user action %}{{form.private.label}}:{% render form.private user action %}{{nameform.private.label}}:{% render nameform.private user action %}
@@ -81,34 +78,34 @@ id="tab-general">
- - + + - - + + - - + + - - + +
{{form.group_as.label}}: {% render form.group_as user action %}
{{nameform.group_as.label}}: {% render nameform.group_as user action %}
{{form.sort_as.label}}: {% render form.sort_as user action %}
{{nameform.sort_as.label}}: {% render nameform.sort_as user action %}
{{form.display_as.label}}: {% render form.display_as user action %}
{{nameform.display_as.label}}: {% render nameform.display_as user action %}
{{form.text.label}}: {% render form.text user action %}
{{nameform.text.label}}: {% render nameform.text user action %}
 
- {% 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 %}
{% name_table person user action "/person/%s/name" person.handle %}
- {% 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 %}
- {% 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 %}
diff --git a/src/webapp/grampsdb/models.py b/src/webapp/grampsdb/models.py index 252aed652..d19d82fd7 100644 --- a/src/webapp/grampsdb/models.py +++ b/src/webapp/grampsdb/models.py @@ -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) diff --git a/src/webapp/grampsdb/views.py b/src/webapp/grampsdb/views.py index e2239d4c6..7bafa20cc 100644 --- a/src/webapp/grampsdb/views.py +++ b/src/webapp/grampsdb/views.py @@ -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) diff --git a/src/webapp/urls.py b/src/webapp/urls.py index 59b12e1d8..17601756d 100644 --- a/src/webapp/urls.py +++ b/src/webapp/urls.py @@ -75,7 +75,7 @@ urlpatterns += patterns('', {"action": "view"}), # /object/handle/ (r'^(?P(\w+))/(?P(\w+))/(?P(\w+))$', action), # /object/handle/action -# (r'^person/(?P(\w+))/name/(?P(\w+))$', view_name), + (r'^person/(?P(\w+))/name/(?P(\w+))$', view_name), # (r'^person/(?P(\w+))/name/(?P(\w+))/(?P(\w+))$', view_name), # (r'^person/(?P(\w+))/name/(?P(\w+))/surname/(?P(\w+))$', view_surname), # (r'^person/(?P(\w+))/name/(?P(\w+))/surname/(?P(\w+))/(?P(\w+))$', view_surname),