From cd731f1e21e05835cd7b6f1368ed848849fd062c Mon Sep 17 00:00:00 2001 From: Doug Blank Date: Mon, 21 May 2012 18:50:03 +0000 Subject: [PATCH] Editing name done; working on surname svn: r19612 --- src/data/templates/view_name_detail.html | 8 +- src/data/templates/view_surname_detail.html | 66 +++---------- src/webapp/grampsdb/forms.py | 11 ++- src/webapp/grampsdb/models.py | 1 + src/webapp/grampsdb/views.py | 103 +++++++++++--------- src/webapp/urls.py | 8 +- 6 files changed, 92 insertions(+), 105 deletions(-) diff --git a/src/data/templates/view_name_detail.html b/src/data/templates/view_name_detail.html index d12c61bbd..5864d39dc 100644 --- a/src/data/templates/view_name_detail.html +++ b/src/data/templates/view_name_detail.html @@ -27,6 +27,12 @@ {% endfor %}
{% csrf_token %} + + {{surnameform.name_origin_type.label}}: + {% render surnameform.name_origin_type user action %} + {{nameform.name_type.label}}: + {% render nameform.name_type user action %} + {{surnameform.surname.label}}: {% render surnameform.surname user action False "" "get_focus" %} @@ -45,8 +51,6 @@ {{nameform.suffix.label}}: {% render nameform.suffix user action %} - {{nameform.name_type.label}}: - {% render nameform.name_type user action %} {{nameform.preferred.label}}: diff --git a/src/data/templates/view_surname_detail.html b/src/data/templates/view_surname_detail.html index 8259d05dd..e8719eeea 100644 --- a/src/data/templates/view_surname_detail.html +++ b/src/data/templates/view_surname_detail.html @@ -31,35 +31,24 @@ {% endif %} {% csrf_token %} - {{form.surname.label}}: - {% render form.surname user action %} - {{form.prefix.label}}: - {% render form.prefix user action %} + {{surnameform.name_origin_type.label}}: + {% render surnameform.name_origin_type user action %} - {{form.first_name.label}}: - {% render form.first_name user action %} - {{form.call.label}}: - {% render form.call user action %} - - - {{form.title.label}}: - {% render form.title user action %} - {{form.suffix.label}}: - {% render form.suffix user action %} - - {{form.name_type.label}}: - {% render form.name_type user action %} + {{surnameform.primary.label}}: + {% render surnameform.primary user action %} - {{form.preferred.label}}: -{% if form.model.preferred %} - True -{% else %} - {% render form.preferred user action %} -{% endif %} - {{form.private.label}}: - {% render form.private user action %} + {{surnameform.prefix.label}}: + {% render surnameform.prefix user action %} + + + {{surnameform.surname.label}}: + {% render surnameform.surname user action %} + + + {{surnameform.connector.label}}: + {% render surnameform.connector user action %} @@ -75,33 +64,6 @@
  • Notes
  • -
    -
    - - - - - - - - - - - - - -
    {{form.group_as.label}}: {% render form.group_as user action %}
    {{form.sort_as.label}}: {% render form.sort_as user action %}
    {{form.display_as.label}}: {% render form.display_as user action %}
    {{form.text.label}}: {% render form.text user action %}
    -
    -   -
    -
    - {% source_table form.model user action "/person/%s/name/%s/source" person.handle form.model.order %} -
    -
    - {% note_table form.model user action "/person/%s/name/%s/note" person.handle form.model.order %} -
    {% if user.is_authenticated %} diff --git a/src/webapp/grampsdb/forms.py b/src/webapp/grampsdb/forms.py index 4a5647ffc..b21a43552 100644 --- a/src/webapp/grampsdb/forms.py +++ b/src/webapp/grampsdb/forms.py @@ -59,6 +59,9 @@ class NameForm(forms.ModelForm): nick = forms.CharField(label="Nick", required=False, widget=TextInput(attrs={'size':'15'})) + group_as = forms.CharField(label="Group as", + required=False, + widget=TextInput(attrs={'size':'30'})) suffix = forms.CharField(required=False, initial=' suffix ', widget=TextInput(attrs={'size':'15', @@ -87,17 +90,21 @@ class NameFormFromPerson(NameForm): #"quality_interpreted", "year1", "day1", "month1", "sortval", "newyear", "person", - "sort_as", "display_as"] + "group_as", "sort_as", "display_as"] class SurnameForm(forms.ModelForm): class Meta: model = Surname - exclude = ['name'] + exclude = ['name', 'order'] surname = forms.CharField(label="Surname", required=False, widget=TextInput(attrs={'size':'30'})) + connector = forms.CharField(label="Connector", + required=False, + widget=TextInput(attrs={'size':'30'})) + prefix = forms.CharField(label="Prefix", required=False, initial=' prefix ', diff --git a/src/webapp/grampsdb/models.py b/src/webapp/grampsdb/models.py index d19d82fd7..b95556fbb 100644 --- a/src/webapp/grampsdb/models.py +++ b/src/webapp/grampsdb/models.py @@ -598,6 +598,7 @@ class Surname(models.Model): primary = models.BooleanField('Primary surname?') connector = models.TextField(blank=True) name = models.ForeignKey("Name") + order = models.PositiveIntegerField() def __unicode__(self): return "%s" % self.surname diff --git a/src/webapp/grampsdb/views.py b/src/webapp/grampsdb/views.py index 7bafa20cc..a5baf1bf1 100644 --- a/src/webapp/grampsdb/views.py +++ b/src/webapp/grampsdb/views.py @@ -160,25 +160,30 @@ def set_date(obj): obj.day1, obj.month1, obj.year1, obj.slash1 = 0, 0, 0, 0 obj.day2, obj.month2, obj.year2, obj.slash2 = 0, 0, 0, 0 -def view_surname(request, handle, order, sorder, action="view"): +def process_surname(request, handle, order, sorder, action="view"): # /sdjhgsdjhdhgsd/name/1/surname/1 (view) # /sdjhgsdjhdhgsd/name/1/surname/add # /sdjhgsdjhdhgsd/name/1/surname/2/[edit|view|add|delete] + + #import pdb; pdb.set_trace() + if sorder == "add": - sorder = 0 + sorder = 1 action = "add" if request.POST.has_key("action"): - print "override!" action = request.POST.get("action") 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 - nameform = NameForm(instance=name) - nameform.model = name + name = person.name_set.get(order=order) + surname = name.surname_set.get(order=sorder) + surname.prefix = make_empty(True, surname.prefix, " prefix ") + surnameform = SurnameForm(instance=surname) + surnameform.model = surname if action == "save": - active = "view" + action = "view" + + # FIXME: working on add/save/create context = RequestContext(request) context["action"] = action @@ -187,13 +192,13 @@ def view_surname(request, handle, order, sorder, action="view"): context["id"] = id context["person"] = person context["object"] = person - context["nameform"] = form + context["surnameform"] = surnameform context["order"] = name.order context["sorder"] = sorder - view_template = 'view_surname.html' + view_template = 'view_surname_detail.html' return render_to_response(view_template, context) -def view_name(request, handle, order, action="view"): +def process_name(request, handle, order, action="view"): if order == "add": order = 0 action = "add" @@ -205,6 +210,7 @@ def view_name(request, handle, order, action="view"): name = nf.model elif action == "edit": pf, nf, sf, person = get_person_forms(handle) + name = nf.model elif action == "delete": person = Person.objects.get(handle=handle) names = person.name_set.all().order_by("order") @@ -226,37 +232,48 @@ def view_name(request, handle, order, action="view"): elif action == "add": # add name person = Person.objects.get(handle=handle) name = Name(person=person, - display_as=NameFormatType._DEFAULT[0], - sort_as=NameFormatType._DEFAULT[0], - name_type=NameType._DEFAULT[0]) + 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])) nf = NameForm(instance=name) nf.model = name + surname = Surname(name=name, primary=True, order=1) + sf = SurnameForm(request.POST, instance=surname) action = "edit" elif action == "save": + # look up old data, if any: person = Person.objects.get(handle=handle) - try: - name = person.name_set.filter(order=order)[0] - except: - order = person.name_set.count() + 1 - name = Name(person=person, order=order) - form = NameForm(request.POST, instance=name) - form.model = name - if form.is_valid(): - # now it is preferred: - if name.preferred: # was preferred, still must be - form.cleaned_data["preferred"] = True - elif form.cleaned_data["preferred"]: # now is - # set all of the other names to be - # not preferred: - person.name_set.filter(~ Q(id=name.id)) \ - .update(preferred=False) - # else some other name is preferred - set_date(name) - n = form.save() + oldname = person.name_set.get(preferred=True) + surname = oldname.surname_set.get(primary=True) + # combine with user data: + pf = PersonForm(request.POST, instance=person) + pf.model = person + nf = NameForm(request.POST, instance=oldname) + nf.model = oldname + sf = SurnameForm(request.POST, instance=surname) + if nf.is_valid() and sf.is_valid(): + # name.preferred and surname.primary get set False in the above is_valid() + # person = pf.save() + # Process data: + oldname.person = person + name = nf.save() + # 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() + # Process data: + surname.name = name + 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 + dji.rebuild_cache(person) + # FIXME: update probably_alive + return redirect("/person/%s/name/%s" % (person.handle, name.order)) else: - action = "edit" - # FIXME: need to update cache - # FIXME: need to reset probabily_alive + action = "add" context = RequestContext(request) context["action"] = action context["tview"] = _('Name') @@ -271,13 +288,7 @@ def view_name(request, handle, order, action="view"): context["order"] = name.order context["next"] = "/person/%s/name/%d" % (person.handle, name.order) view_template = "view_name_detail.html" - if action == "save": - context["action"] = "view" - return redirect("/person/%s/name/%d" % (person.handle, name.order)) - elif action == "back": - return redirect("/person/%s/" % (person.handle)) - else: - return render_to_response(view_template, context) + return render_to_response(view_template, context) def send_file(request, filename, mimetype): """ @@ -865,7 +876,7 @@ def process_person(request, context, handle, action): # view, edit, save else: # create new item person = Person(handle=create_id()) name = Name(person=person, preferred=True) - surname = Surname(name=name, primary=True) + surname = Surname(name=name, primary=True, order=1) # combine with user data: pf = PersonForm(request.POST, instance=person) pf.model = person @@ -941,7 +952,9 @@ def get_person_forms(handle, protect=False, empty=False): try: surname = name.surname_set.get(primary=True) except: - surname = Surname(name=name, primary=True, name_origin_type=NameOriginType.objects.get(val=NameOriginType._DEFAULT[0]),) + surname = Surname(name=name, primary=True, + name_origin_type=NameOriginType.objects.get(val=NameOriginType._DEFAULT[0]), + order=1) if protect and person.probably_alive: name.sanitize() diff --git a/src/webapp/urls.py b/src/webapp/urls.py index 17601756d..9ef8bccd4 100644 --- a/src/webapp/urls.py +++ b/src/webapp/urls.py @@ -75,10 +75,10 @@ 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+))/(?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), + (r'^person/(?P(\w+))/name/(?P(\w+))$', process_name), + (r'^person/(?P(\w+))/name/(?P(\w+))/(?P(\w+))$', process_name), + (r'^person/(?P(\w+))/name/(?P(\w+))/surname/(?P(\w+))$', process_surname), + (r'^person/(?P(\w+))/name/(?P(\w+))/surname/(?P(\w+))/(?P(\w+))$', process_surname), ) # In urls: