From bb1bf9ac7a9a7a83be7d630d55e1b5497da567ac Mon Sep 17 00:00:00 2001 From: Doug Blank Date: Thu, 24 May 2012 20:51:46 +0000 Subject: [PATCH] Working on the rest of the main objects svn: r19640 --- src/data/templates/view_citations.html | 3 + src/data/templates/view_events.html | 3 + src/data/templates/view_families.html | 3 + src/data/templates/view_media.html | 3 + src/data/templates/view_notes.html | 3 + src/data/templates/view_places.html | 3 + src/data/templates/view_repositories.html | 3 + src/data/templates/view_sources.html | 3 + src/data/templates/view_surname_detail.html | 2 +- src/data/templates/view_tags.html | 3 + src/webapp/grampsdb/models.py | 1 + src/webapp/grampsdb/view/__init__.py | 10 + src/webapp/grampsdb/view/citation.py | 128 ++++ src/webapp/grampsdb/view/event.py | 129 ++++ src/webapp/grampsdb/view/family.py | 129 ++++ src/webapp/grampsdb/view/media.py | 128 ++++ src/webapp/grampsdb/view/note.py | 128 ++++ src/webapp/grampsdb/view/person.py | 465 +++++++++++++++ src/webapp/grampsdb/view/place.py | 128 ++++ src/webapp/grampsdb/view/repository.py | 128 ++++ src/webapp/grampsdb/view/source.py | 129 ++++ src/webapp/grampsdb/view/tag.py | 129 ++++ src/webapp/grampsdb/views.py | 615 ++------------------ src/webapp/utils.py | 11 +- 24 files changed, 1726 insertions(+), 561 deletions(-) create mode 100644 src/webapp/grampsdb/view/__init__.py create mode 100644 src/webapp/grampsdb/view/citation.py create mode 100644 src/webapp/grampsdb/view/event.py create mode 100644 src/webapp/grampsdb/view/family.py create mode 100644 src/webapp/grampsdb/view/media.py create mode 100644 src/webapp/grampsdb/view/note.py create mode 100644 src/webapp/grampsdb/view/person.py create mode 100644 src/webapp/grampsdb/view/place.py create mode 100644 src/webapp/grampsdb/view/repository.py create mode 100644 src/webapp/grampsdb/view/source.py create mode 100644 src/webapp/grampsdb/view/tag.py diff --git a/src/data/templates/view_citations.html b/src/data/templates/view_citations.html index 1fc820ff1..68a9a0267 100644 --- a/src/data/templates/view_citations.html +++ b/src/data/templates/view_citations.html @@ -33,5 +33,8 @@ +{% if user.is_superuser %} + {% make_button "Add Citation" "/citation/add" %} +{% endif %} {% endblock %} diff --git a/src/data/templates/view_events.html b/src/data/templates/view_events.html index 3da9a9936..514ee0145 100644 --- a/src/data/templates/view_events.html +++ b/src/data/templates/view_events.html @@ -40,5 +40,8 @@ +{% if user.is_superuser %} + {% make_button "Add Event" "/event/add" %} +{% endif %} {% endblock %} diff --git a/src/data/templates/view_families.html b/src/data/templates/view_families.html index 8c7a9c37c..9aa371c86 100644 --- a/src/data/templates/view_families.html +++ b/src/data/templates/view_families.html @@ -30,5 +30,8 @@ +{% if user.is_superuser %} + {% make_button "Add Family" "/family/add" %} +{% endif %} {% endblock %} diff --git a/src/data/templates/view_media.html b/src/data/templates/view_media.html index a4bf3a2ca..da85476a6 100644 --- a/src/data/templates/view_media.html +++ b/src/data/templates/view_media.html @@ -33,5 +33,8 @@ +{% if user.is_superuser %} + {% make_button "Add Media" "/media/add" %} +{% endif %} {% endblock %} diff --git a/src/data/templates/view_notes.html b/src/data/templates/view_notes.html index b4acde9cd..f1e6d77f0 100644 --- a/src/data/templates/view_notes.html +++ b/src/data/templates/view_notes.html @@ -30,5 +30,8 @@ +{% if user.is_superuser %} + {% make_button "Add Note" "/note/add" %} +{% endif %} {% endblock %} diff --git a/src/data/templates/view_places.html b/src/data/templates/view_places.html index 61b2cdc3d..78c034633 100644 --- a/src/data/templates/view_places.html +++ b/src/data/templates/view_places.html @@ -27,5 +27,8 @@ +{% if user.is_superuser %} + {% make_button "Add Places" "/place/add" %} +{% endif %} {% endblock %} diff --git a/src/data/templates/view_repositories.html b/src/data/templates/view_repositories.html index a730c6d2c..ef2c1f6e3 100644 --- a/src/data/templates/view_repositories.html +++ b/src/data/templates/view_repositories.html @@ -31,5 +31,8 @@ +{% if user.is_superuser %} + {% make_button "Add Repository" "/repository/add" %} +{% endif %} {% endblock %} diff --git a/src/data/templates/view_sources.html b/src/data/templates/view_sources.html index 1fc820ff1..cc9037a13 100644 --- a/src/data/templates/view_sources.html +++ b/src/data/templates/view_sources.html @@ -33,5 +33,8 @@ +{% if user.is_superuser %} + {% make_button "Add Source" "/source/add" %} +{% endif %} {% endblock %} diff --git a/src/data/templates/view_surname_detail.html b/src/data/templates/view_surname_detail.html index fe91a9712..0674e79e9 100644 --- a/src/data/templates/view_surname_detail.html +++ b/src/data/templates/view_surname_detail.html @@ -72,7 +72,7 @@ {% if action == "add" %} + onclick="document.location.href='/person/{{person.handle}}/name/{{order}}'"/> {% else %} diff --git a/src/data/templates/view_tags.html b/src/data/templates/view_tags.html index 7b0ae11fe..d480fbfd0 100644 --- a/src/data/templates/view_tags.html +++ b/src/data/templates/view_tags.html @@ -31,5 +31,8 @@ +{% if user.is_superuser %} + {% make_button "Add Tag" "/tag/add" %} +{% endif %} {% endblock %} diff --git a/src/webapp/grampsdb/models.py b/src/webapp/grampsdb/models.py index 2a9f28b68..6406c7a90 100644 --- a/src/webapp/grampsdb/models.py +++ b/src/webapp/grampsdb/models.py @@ -384,6 +384,7 @@ class Config(models.Model): class Tag(models.Model): handle = models.CharField(max_length=19, unique=True) + gramps_id = models.TextField(blank=True, null=True) last_saved = models.DateTimeField('last changed', auto_now=True) last_changed = models.DateTimeField('last changed', null=True, blank=True) # user edits diff --git a/src/webapp/grampsdb/view/__init__.py b/src/webapp/grampsdb/view/__init__.py new file mode 100644 index 000000000..5d82fbabf --- /dev/null +++ b/src/webapp/grampsdb/view/__init__.py @@ -0,0 +1,10 @@ +from person import * +from family import * +from event import * +from note import * +from media import * +from citation import * +from source import * +from place import * +from repository import * +from tag import * diff --git a/src/webapp/grampsdb/view/citation.py b/src/webapp/grampsdb/view/citation.py new file mode 100644 index 000000000..9dcb3e35e --- /dev/null +++ b/src/webapp/grampsdb/view/citation.py @@ -0,0 +1,128 @@ +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2009 Douglas S. Blank +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# $Id: utils.py 19637 2012-05-24 17:22:14Z dsblank $ +# + +""" Views for Person, Name, and Surname """ + +## Gramps Modules +from webapp.utils import _, boolean +from webapp.grampsdb.models import Citation +from webapp.grampsdb.forms import * +from webapp.libdjango import DjangoInterface + +## Django Modules +from django.shortcuts import get_object_or_404, render_to_response, redirect +from django.template import Context, RequestContext + +## Globals +dji = DjangoInterface() + +def process_citation(request, context, handle, action): # view, edit, save + """ + Process action on person. Can return a redirect. + """ + context["tview"] = _("Citation") + context["tviews"] = _("Citations") + context["action"] = "view" + context["object"] = Citation() + view_template = "view_citation_detail.html" + + return render_to_response(view_template, context) + if request.user.is_authenticated(): + if action in ["edit", "view"]: + pf, nf, sf, person = get_person_forms(handle, empty=False) + elif action == "add": + pf, nf, sf, person = get_person_forms(handle=None, protect=False, empty=True) + elif action == "delete": + pf, nf, sf, person = get_person_forms(handle, protect=False, empty=True) + person.delete() + return redirect("/person/") + elif action in ["save", "create"]: # could be create a new person + # look up old data, if any: + if handle: + person = Person.objects.get(handle=handle) + name = person.name_set.get(preferred=True) + surname = name.surname_set.get(primary=True) + else: # create new item + person = Person(handle=create_id()) + name = Name(person=person, preferred=True) + surname = Surname(name=name, primary=True, order=1) + surname = Surname(name=name, + primary=True, + order=1, + name_origin_type=NameOriginType.objects.get(val=NameOriginType._DEFAULT[0])) + # combine with user data: + pf = PersonForm(request.POST, instance=person) + pf.model = person + nf = NameFormFromPerson(request.POST, instance=name) + nf.model = name + sf = SurnameForm(request.POST, instance=surname) + # check if valid: + if nf.is_valid() and pf.is_valid() and sf.is_valid(): + # name.preferred and surname.primary get set False in the above is_valid() + person = pf.save() + # Process data: + name.person = person + name = nf.save(commit=False) + # 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? + check_preferred(name, person) + 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" % person.handle) + else: + # need to edit again + if handle: + action = "edit" + else: + action = "add" + else: # error? + raise Http404(_("Requested %s does not exist.") % "person") + else: # not authenticated + # BEGIN NON-AUTHENTICATED ACCESS + try: + person = Person.objects.get(handle=handle) + except: + raise Http404(_("Requested %s does not exist.") % "person") + if person.private: + raise Http404(_("Requested %s does not exist.") % "person") + pf, nf, sf, person = get_person_forms(handle, protect=True) + # END NON-AUTHENTICATED ACCESS + context["action"] = action + context["view"] = "person" + context["tview"] = _("Person") + context["tviews"] = _("People") + context["personform"] = pf + context["nameform"] = nf + context["surnameform"] = sf + context["person"] = person + context["object"] = person + context["next"] = "/person/%s" % person.handle + diff --git a/src/webapp/grampsdb/view/event.py b/src/webapp/grampsdb/view/event.py new file mode 100644 index 000000000..e744b0e37 --- /dev/null +++ b/src/webapp/grampsdb/view/event.py @@ -0,0 +1,129 @@ +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2009 Douglas S. Blank +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# $Id: utils.py 19637 2012-05-24 17:22:14Z dsblank $ +# + +""" Views for Person, Name, and Surname """ + +## Gramps Modules +from webapp.utils import _, boolean +from webapp.grampsdb.models import Event +from webapp.grampsdb.forms import * +from webapp.libdjango import DjangoInterface + +## Django Modules +from django.shortcuts import get_object_or_404, render_to_response, redirect +from django.template import Context, RequestContext + +## Globals +dji = DjangoInterface() + +def process_event(request, context, handle, action): # view, edit, save + """ + Process action on person. Can return a redirect. + """ + context["tview"] = _("Event") + context["tviews"] = _("Events") + context["action"] = "view" + context["event"] = Event() + context["object"] = Event() + view_template = "view_event_detail.html" + + return render_to_response(view_template, context) + if request.user.is_authenticated(): + if action in ["edit", "view"]: + pf, nf, sf, person = get_person_forms(handle, empty=False) + elif action == "add": + pf, nf, sf, person = get_person_forms(handle=None, protect=False, empty=True) + elif action == "delete": + pf, nf, sf, person = get_person_forms(handle, protect=False, empty=True) + person.delete() + return redirect("/person/") + elif action in ["save", "create"]: # could be create a new person + # look up old data, if any: + if handle: + person = Person.objects.get(handle=handle) + name = person.name_set.get(preferred=True) + surname = name.surname_set.get(primary=True) + else: # create new item + person = Person(handle=create_id()) + name = Name(person=person, preferred=True) + surname = Surname(name=name, primary=True, order=1) + surname = Surname(name=name, + primary=True, + order=1, + name_origin_type=NameOriginType.objects.get(val=NameOriginType._DEFAULT[0])) + # combine with user data: + pf = PersonForm(request.POST, instance=person) + pf.model = person + nf = NameFormFromPerson(request.POST, instance=name) + nf.model = name + sf = SurnameForm(request.POST, instance=surname) + # check if valid: + if nf.is_valid() and pf.is_valid() and sf.is_valid(): + # name.preferred and surname.primary get set False in the above is_valid() + person = pf.save() + # Process data: + name.person = person + name = nf.save(commit=False) + # 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? + check_preferred(name, person) + 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" % person.handle) + else: + # need to edit again + if handle: + action = "edit" + else: + action = "add" + else: # error? + raise Http404(_("Requested %s does not exist.") % "person") + else: # not authenticated + # BEGIN NON-AUTHENTICATED ACCESS + try: + person = Person.objects.get(handle=handle) + except: + raise Http404(_("Requested %s does not exist.") % "person") + if person.private: + raise Http404(_("Requested %s does not exist.") % "person") + pf, nf, sf, person = get_person_forms(handle, protect=True) + # END NON-AUTHENTICATED ACCESS + context["action"] = action + context["view"] = "person" + context["tview"] = _("Person") + context["tviews"] = _("People") + context["personform"] = pf + context["nameform"] = nf + context["surnameform"] = sf + context["person"] = person + context["object"] = person + context["next"] = "/person/%s" % person.handle + diff --git a/src/webapp/grampsdb/view/family.py b/src/webapp/grampsdb/view/family.py new file mode 100644 index 000000000..ca959cf6f --- /dev/null +++ b/src/webapp/grampsdb/view/family.py @@ -0,0 +1,129 @@ +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2009 Douglas S. Blank +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# $Id: utils.py 19637 2012-05-24 17:22:14Z dsblank $ +# + +""" Views for Person, Name, and Surname """ + +## Gramps Modules +from webapp.utils import _, boolean +from webapp.grampsdb.models import Family +from webapp.grampsdb.forms import * +from webapp.libdjango import DjangoInterface + +## Django Modules +from django.shortcuts import get_object_or_404, render_to_response, redirect +from django.template import Context, RequestContext + +## Globals +dji = DjangoInterface() + +def process_family(request, context, handle, action): # view, edit, save + """ + Process action on person. Can return a redirect. + """ + context["tview"] = _("Family") + context["tviews"] = _("Familes") + context["action"] = "view" + context["family"] = Family() + context["object"] = Family() + view_template = "view_family_detail.html" + + return render_to_response(view_template, context) + if request.user.is_authenticated(): + if action in ["edit", "view"]: + pf, nf, sf, person = get_person_forms(handle, empty=False) + elif action == "add": + pf, nf, sf, person = get_person_forms(handle=None, protect=False, empty=True) + elif action == "delete": + pf, nf, sf, person = get_person_forms(handle, protect=False, empty=True) + person.delete() + return redirect("/person/") + elif action in ["save", "create"]: # could be create a new person + # look up old data, if any: + if handle: + person = Person.objects.get(handle=handle) + name = person.name_set.get(preferred=True) + surname = name.surname_set.get(primary=True) + else: # create new item + person = Person(handle=create_id()) + name = Name(person=person, preferred=True) + surname = Surname(name=name, primary=True, order=1) + surname = Surname(name=name, + primary=True, + order=1, + name_origin_type=NameOriginType.objects.get(val=NameOriginType._DEFAULT[0])) + # combine with user data: + pf = PersonForm(request.POST, instance=person) + pf.model = person + nf = NameFormFromPerson(request.POST, instance=name) + nf.model = name + sf = SurnameForm(request.POST, instance=surname) + # check if valid: + if nf.is_valid() and pf.is_valid() and sf.is_valid(): + # name.preferred and surname.primary get set False in the above is_valid() + person = pf.save() + # Process data: + name.person = person + name = nf.save(commit=False) + # 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? + check_preferred(name, person) + 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" % person.handle) + else: + # need to edit again + if handle: + action = "edit" + else: + action = "add" + else: # error? + raise Http404(_("Requested %s does not exist.") % "person") + else: # not authenticated + # BEGIN NON-AUTHENTICATED ACCESS + try: + person = Person.objects.get(handle=handle) + except: + raise Http404(_("Requested %s does not exist.") % "person") + if person.private: + raise Http404(_("Requested %s does not exist.") % "person") + pf, nf, sf, person = get_person_forms(handle, protect=True) + # END NON-AUTHENTICATED ACCESS + context["action"] = action + context["view"] = "person" + context["tview"] = _("Person") + context["tviews"] = _("People") + context["personform"] = pf + context["nameform"] = nf + context["surnameform"] = sf + context["person"] = person + context["object"] = person + context["next"] = "/person/%s" % person.handle + diff --git a/src/webapp/grampsdb/view/media.py b/src/webapp/grampsdb/view/media.py new file mode 100644 index 000000000..86cd21674 --- /dev/null +++ b/src/webapp/grampsdb/view/media.py @@ -0,0 +1,128 @@ +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2009 Douglas S. Blank +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# $Id: utils.py 19637 2012-05-24 17:22:14Z dsblank $ +# + +""" Views for Person, Name, and Surname """ + +## Gramps Modules +from webapp.utils import _, boolean +from webapp.grampsdb.models import Media +from webapp.grampsdb.forms import * +from webapp.libdjango import DjangoInterface + +## Django Modules +from django.shortcuts import get_object_or_404, render_to_response, redirect +from django.template import Context, RequestContext + +## Globals +dji = DjangoInterface() + +def process_media(request, context, handle, action): # view, edit, save + """ + Process action on person. Can return a redirect. + """ + context["tview"] = _("Media") + context["tviews"] = _("Media") + context["action"] = "view" + context["object"] = Media() + view_template = "view_media_detail.html" + + return render_to_response(view_template, context) + if request.user.is_authenticated(): + if action in ["edit", "view"]: + pf, nf, sf, person = get_person_forms(handle, empty=False) + elif action == "add": + pf, nf, sf, person = get_person_forms(handle=None, protect=False, empty=True) + elif action == "delete": + pf, nf, sf, person = get_person_forms(handle, protect=False, empty=True) + person.delete() + return redirect("/person/") + elif action in ["save", "create"]: # could be create a new person + # look up old data, if any: + if handle: + person = Person.objects.get(handle=handle) + name = person.name_set.get(preferred=True) + surname = name.surname_set.get(primary=True) + else: # create new item + person = Person(handle=create_id()) + name = Name(person=person, preferred=True) + surname = Surname(name=name, primary=True, order=1) + surname = Surname(name=name, + primary=True, + order=1, + name_origin_type=NameOriginType.objects.get(val=NameOriginType._DEFAULT[0])) + # combine with user data: + pf = PersonForm(request.POST, instance=person) + pf.model = person + nf = NameFormFromPerson(request.POST, instance=name) + nf.model = name + sf = SurnameForm(request.POST, instance=surname) + # check if valid: + if nf.is_valid() and pf.is_valid() and sf.is_valid(): + # name.preferred and surname.primary get set False in the above is_valid() + person = pf.save() + # Process data: + name.person = person + name = nf.save(commit=False) + # 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? + check_preferred(name, person) + 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" % person.handle) + else: + # need to edit again + if handle: + action = "edit" + else: + action = "add" + else: # error? + raise Http404(_("Requested %s does not exist.") % "person") + else: # not authenticated + # BEGIN NON-AUTHENTICATED ACCESS + try: + person = Person.objects.get(handle=handle) + except: + raise Http404(_("Requested %s does not exist.") % "person") + if person.private: + raise Http404(_("Requested %s does not exist.") % "person") + pf, nf, sf, person = get_person_forms(handle, protect=True) + # END NON-AUTHENTICATED ACCESS + context["action"] = action + context["view"] = "person" + context["tview"] = _("Person") + context["tviews"] = _("People") + context["personform"] = pf + context["nameform"] = nf + context["surnameform"] = sf + context["person"] = person + context["object"] = person + context["next"] = "/person/%s" % person.handle + diff --git a/src/webapp/grampsdb/view/note.py b/src/webapp/grampsdb/view/note.py new file mode 100644 index 000000000..bdeb768c4 --- /dev/null +++ b/src/webapp/grampsdb/view/note.py @@ -0,0 +1,128 @@ +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2009 Douglas S. Blank +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# $Id: utils.py 19637 2012-05-24 17:22:14Z dsblank $ +# + +""" Views for Person, Name, and Surname """ + +## Gramps Modules +from webapp.utils import _, boolean +from webapp.grampsdb.models import Note +from webapp.grampsdb.forms import * +from webapp.libdjango import DjangoInterface + +## Django Modules +from django.shortcuts import get_object_or_404, render_to_response, redirect +from django.template import Context, RequestContext + +## Globals +dji = DjangoInterface() + +def process_note(request, context, handle, action): # view, edit, save + """ + Process action on person. Can return a redirect. + """ + context["tview"] = _("Note") + context["tviews"] = _("Notes") + context["action"] = "view" + context["object"] = Note() + view_template = "view_note_detail.html" + + return render_to_response(view_template, context) + if request.user.is_authenticated(): + if action in ["edit", "view"]: + pf, nf, sf, person = get_person_forms(handle, empty=False) + elif action == "add": + pf, nf, sf, person = get_person_forms(handle=None, protect=False, empty=True) + elif action == "delete": + pf, nf, sf, person = get_person_forms(handle, protect=False, empty=True) + person.delete() + return redirect("/person/") + elif action in ["save", "create"]: # could be create a new person + # look up old data, if any: + if handle: + person = Person.objects.get(handle=handle) + name = person.name_set.get(preferred=True) + surname = name.surname_set.get(primary=True) + else: # create new item + person = Person(handle=create_id()) + name = Name(person=person, preferred=True) + surname = Surname(name=name, primary=True, order=1) + surname = Surname(name=name, + primary=True, + order=1, + name_origin_type=NameOriginType.objects.get(val=NameOriginType._DEFAULT[0])) + # combine with user data: + pf = PersonForm(request.POST, instance=person) + pf.model = person + nf = NameFormFromPerson(request.POST, instance=name) + nf.model = name + sf = SurnameForm(request.POST, instance=surname) + # check if valid: + if nf.is_valid() and pf.is_valid() and sf.is_valid(): + # name.preferred and surname.primary get set False in the above is_valid() + person = pf.save() + # Process data: + name.person = person + name = nf.save(commit=False) + # 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? + check_preferred(name, person) + 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" % person.handle) + else: + # need to edit again + if handle: + action = "edit" + else: + action = "add" + else: # error? + raise Http404(_("Requested %s does not exist.") % "person") + else: # not authenticated + # BEGIN NON-AUTHENTICATED ACCESS + try: + person = Person.objects.get(handle=handle) + except: + raise Http404(_("Requested %s does not exist.") % "person") + if person.private: + raise Http404(_("Requested %s does not exist.") % "person") + pf, nf, sf, person = get_person_forms(handle, protect=True) + # END NON-AUTHENTICATED ACCESS + context["action"] = action + context["view"] = "person" + context["tview"] = _("Person") + context["tviews"] = _("People") + context["personform"] = pf + context["nameform"] = nf + context["surnameform"] = sf + context["person"] = person + context["object"] = person + context["next"] = "/person/%s" % person.handle + diff --git a/src/webapp/grampsdb/view/person.py b/src/webapp/grampsdb/view/person.py new file mode 100644 index 000000000..d781bdc3e --- /dev/null +++ b/src/webapp/grampsdb/view/person.py @@ -0,0 +1,465 @@ +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2009 Douglas S. Blank +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# $Id: utils.py 19637 2012-05-24 17:22:14Z dsblank $ +# + +""" Views for Person, Name, and Surname """ + +## Gramps Modules +from webapp.utils import _, boolean +from webapp.grampsdb.models import Person, Name, Surname +from webapp.grampsdb.forms import * +from webapp.libdjango import DjangoInterface + +## Django Modules +from django.shortcuts import get_object_or_404, render_to_response, redirect +from django.template import Context, RequestContext + +## Globals +dji = DjangoInterface() + +## Functions +def check_order(person): + """ + Check for proper ordering 1..., and for a preferred name. + """ + order = 1 + preferred = False + for name in person.name_set.all().order_by("order"): + if name.preferred: + preferred = True + if name.order != order: + name.order = order + name.save() + order += 1 + if not preferred: + name = person.name_set.get(order=1) + name.preferred = True + name.save() + +def check_primary(surname, surnames): + """ + Check for a proper primary surname. + """ + if surname.primary: + # then all rest should not be: + for s in surnames: + if s.primary: + s.primary = False + s.save() + else: + # then one of them should be + ok = False + for s in surnames: + if s.id != surname.id: + if s.primary: + ok = True + break + else: + s.primary = False + s.save() + ok = True + break + if not ok: + surname.primary = True + +def check_preferred(name, person): + """ + Check for a proper preferred name. + """ + names = [] + if person: + names = person.name_set.all() + if name.preferred: + # then all reast should not be: + for s in names: + if s.preferred and s.id != name.id: + s.preferred = False + s.save() + else: + # then one of them should be + ok = False + for s in names: + if s.id != name.id: + if s.preferred: + ok = True + break + else: + s.preferred = False + s.save() + ok = True + break + if not ok: + name.preferred = True + +def process_surname(request, handle, order, sorder, action="view"): + #import pdb; pdb.set_trace() + # /sdjhgsdjhdhgsd/name/1/surname/1 (view) + # /sdjhgsdjhdhgsd/name/1/surname/add + # /sdjhgsdjhdhgsd/name/1/surname/2/[edit|view|add|delete] + + if sorder == "add": + action = "add" + if request.POST.has_key("action"): + action = request.POST.get("action") + + person = Person.objects.get(handle=handle) + name = person.name_set.get(order=order) + + if action in ["view", "edit"]: + surname = name.surname_set.get(order=sorder) + if action == "edit": + surname.prefix = make_empty(True, surname.prefix, " prefix ") + elif action in ["delete"]: + surnames = name.surname_set.all().order_by("order") + if len(surnames) > 1: + neworder = 1 + for surname in surnames: + if surname.order != neworder: + surname.order = neworder + surname.save() + neworder += 1 + elif surname.order == int(sorder): + surname.delete() + else: + neworder += 1 + else: + request.user.message_set.create(message="You can't delete the only surname") + return redirect("/person/%s/name/%s" % (person.handle, name.order)) + elif action in ["add"]: + surname = Surname(name=name, primary=False, + name_origin_type=NameOriginType.objects.get(val=NameOriginType._DEFAULT[0])) + surname.prefix = make_empty(True, surname.prefix, " prefix ") + elif action == "create": + import pdb; pdb.set_trace() + + surnames = name.surname_set.all().order_by("order") + sorder = 1 + for surname in surnames: + sorder += 1 + surname = Surname(name=name, primary=True, + name_origin_type=NameOriginType.objects.get(val=NameOriginType._DEFAULT[0]), + order=sorder) + sf = SurnameForm(request.POST, instance=surname) + sf.model = surname + if sf.is_valid(): + surname.prefix = ssf.cleaned_data["prefix"] if sf.cleaned_data["prefix"] != " prefix " else "" + surname = sf.save(commit=False) + check_primary(surname, surnames) + surname.save() + return redirect("/person/%s/name/%s/surname/%s" % + (person.handle, name.order, sorder)) + action = "add" + surname.prefix = make_empty(True, surname.prefix, " prefix ") + elif action == "save": + surname = name.surname_set.get(order=sorder) + sf = SurnameForm(request.POST, instance=surname) + sf.model = surname + if sf.is_valid(): + surname.prefix = ssf.cleaned_data["prefix"] if sf.cleaned_data["prefix"] != " prefix " else "" + surname = sf.save(commit=False) + check_primary(surname, name.surname_set.all().exclude(order=surname.order)) + surname.save() + return redirect("/person/%s/name/%s/surname/%s" % + (person.handle, name.order, sorder)) + action = "edit" + surname.prefix = make_empty(True, surname.prefix, " prefix ") + # else, edit again + else: + raise + + sf = SurnameForm(instance=surname) + sf.model = surname + + context = RequestContext(request) + context["action"] = action + context["tview"] = _("Surname") + context["handle"] = handle + context["id"] = id + context["person"] = person + context["object"] = person + context["surnameform"] = sf + context["order"] = name.order + context["sorder"] = sorder + view_template = 'view_surname_detail.html' + return render_to_response(view_template, context) + +def process_name(request, handle, order, action="view"): + if order == "add": + action = "add" + if request.POST.has_key("action"): + action = request.POST.get("action") + ### Process action: + if action == "view": + pf, nf, sf, person = get_person_forms(handle, order=order) + name = nf.model + elif action == "edit": + pf, nf, sf, person = get_person_forms(handle, order=order) + name = nf.model + elif action == "delete": + person = Person.objects.get(handle=handle) + name = person.name_set.filter(order=order) + names = person.name_set.all() + if len(names) > 1: + name.delete() + check_order(person) + else: + request.user.message_set.create(message = "Can't delete only name.") + return redirect("/person/%s" % person.handle) + elif action == "add": # add name + person = Person.objects.get(handle=handle) + name = Name(person=person, + preferred=False, + 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, + name_origin_type=NameOriginType.objects.get(val=NameOriginType._DEFAULT[0])) + sf = SurnameForm(request.POST, instance=surname) + elif action == "create": + # make new data + person = Person.objects.get(handle=handle) + name = Name(preferred=False) + next_order = max([name.order for name in person.name_set.all()]) + 1 + surname = Surname(name=name, + primary=True, + order=next_order, + name_origin_type=NameOriginType.objects.get(val=NameOriginType._DEFAULT[0])) + # combine with user data: + nf = NameForm(request.POST, instance=name) + name.id = None # FIXME: why did this get set to an existing name? Should be new. + name.preferred = False + nf.model = name + sf = SurnameForm(request.POST, instance=surname) + sf.model = 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: + name = nf.save(commit=False) + name.person = person + # Manually set any data: + name.suffix = nf.cleaned_data["suffix"] if nf.cleaned_data["suffix"] != " suffix " else "" + name.preferred = False # FIXME: why is this False? + name.order = next_order + name.save() + # Process data: + surname = sf.save(commit=False) + surname.name = name + # 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 = "add" + elif action == "save": + # look up old data: + person = Person.objects.get(handle=handle) + oldname = person.name_set.get(order=order) + oldsurname = 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=oldsurname) + 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? + check_preferred(name, person) + name.save() + # Process data: + oldsurname.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" + context = RequestContext(request) + context["action"] = action + context["tview"] = _('Name') + context["tviews"] = _('Names') + context["view"] = 'name' + context["handle"] = handle + context["id"] = id + context["person"] = person + context["object"] = person + context["nameform"] = nf + context["surnameform"] = sf + context["order"] = order + context["next"] = "/person/%s/name/%d" % (person.handle, name.order) + view_template = "view_name_detail.html" + return render_to_response(view_template, context) + +def process_person(request, context, handle, action): # view, edit, save + """ + Process action on person. Can return a redirect. + """ + context["tview"] = _("Person") + context["tviews"] = _("People") + if request.user.is_authenticated(): + if action in ["edit", "view"]: + pf, nf, sf, person = get_person_forms(handle, empty=False) + elif action == "add": + pf, nf, sf, person = get_person_forms(handle=None, protect=False, empty=True) + elif action == "delete": + pf, nf, sf, person = get_person_forms(handle, protect=False, empty=True) + person.delete() + return redirect("/person/") + elif action in ["save", "create"]: # could be create a new person + # look up old data, if any: + if handle: + person = Person.objects.get(handle=handle) + name = person.name_set.get(preferred=True) + surname = name.surname_set.get(primary=True) + else: # create new item + person = Person(handle=create_id()) + name = Name(person=person, preferred=True) + surname = Surname(name=name, primary=True, order=1) + surname = Surname(name=name, + primary=True, + order=1, + name_origin_type=NameOriginType.objects.get(val=NameOriginType._DEFAULT[0])) + # combine with user data: + pf = PersonForm(request.POST, instance=person) + pf.model = person + nf = NameFormFromPerson(request.POST, instance=name) + nf.model = name + sf = SurnameForm(request.POST, instance=surname) + # check if valid: + if nf.is_valid() and pf.is_valid() and sf.is_valid(): + # name.preferred and surname.primary get set False in the above is_valid() + person = pf.save() + # Process data: + name.person = person + name = nf.save(commit=False) + # 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? + check_preferred(name, person) + 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" % person.handle) + else: + # need to edit again + if handle: + action = "edit" + else: + action = "add" + else: # error? + raise Http404(_("Requested %s does not exist.") % "person") + else: # not authenticated + # BEGIN NON-AUTHENTICATED ACCESS + try: + person = Person.objects.get(handle=handle) + except: + raise Http404(_("Requested %s does not exist.") % "person") + if person.private: + raise Http404(_("Requested %s does not exist.") % "person") + pf, nf, sf, person = get_person_forms(handle, protect=True) + # END NON-AUTHENTICATED ACCESS + context["action"] = action + context["view"] = "person" + context["tview"] = _("Person") + context["tviews"] = _("People") + context["personform"] = pf + context["nameform"] = nf + context["surnameform"] = sf + context["person"] = person + context["object"] = person + context["next"] = "/person/%s" % person.handle + +def get_person_forms(handle, protect=False, empty=False, order=None): + if handle: + person = Person.objects.get(handle=handle) + else: + person = Person() + #person.gramps_id = "I0000" # FIXME: get next ID + ## get a name + name = None + if order is not None: + try: + name = person.name_set.get(order=order) + except: + pass + if name is None: + try: + name = person.name_set.get(preferred=True) + except: + name = Name(person=person, preferred=True, + 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, + name_origin_type=NameOriginType.objects.get(val=NameOriginType._DEFAULT[0]), + order=1) + + if protect and person.probably_alive: + name.sanitize() + pf = PersonForm(instance=person) + pf.model = person + name.suffix = make_empty(empty, name.suffix, " suffix ") + nf = NameForm(instance=name) + nf.model = name + 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: + return value + elif empty: + return empty_value + else: + return value + diff --git a/src/webapp/grampsdb/view/place.py b/src/webapp/grampsdb/view/place.py new file mode 100644 index 000000000..1cec2f3a3 --- /dev/null +++ b/src/webapp/grampsdb/view/place.py @@ -0,0 +1,128 @@ +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2009 Douglas S. Blank +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# $Id: utils.py 19637 2012-05-24 17:22:14Z dsblank $ +# + +""" Views for Person, Name, and Surname """ + +## Gramps Modules +from webapp.utils import _, boolean +from webapp.grampsdb.models import Place +from webapp.grampsdb.forms import * +from webapp.libdjango import DjangoInterface + +## Django Modules +from django.shortcuts import get_object_or_404, render_to_response, redirect +from django.template import Context, RequestContext + +## Globals +dji = DjangoInterface() + +def process_place(request, context, handle, action): # view, edit, save + """ + Process action on person. Can return a redirect. + """ + context["tview"] = _("Place") + context["tviews"] = _("Places") + context["action"] = "view" + context["object"] = Place() + view_template = "view_place_detail.html" + + return render_to_response(view_template, context) + if request.user.is_authenticated(): + if action in ["edit", "view"]: + pf, nf, sf, person = get_person_forms(handle, empty=False) + elif action == "add": + pf, nf, sf, person = get_person_forms(handle=None, protect=False, empty=True) + elif action == "delete": + pf, nf, sf, person = get_person_forms(handle, protect=False, empty=True) + person.delete() + return redirect("/person/") + elif action in ["save", "create"]: # could be create a new person + # look up old data, if any: + if handle: + person = Person.objects.get(handle=handle) + name = person.name_set.get(preferred=True) + surname = name.surname_set.get(primary=True) + else: # create new item + person = Person(handle=create_id()) + name = Name(person=person, preferred=True) + surname = Surname(name=name, primary=True, order=1) + surname = Surname(name=name, + primary=True, + order=1, + name_origin_type=NameOriginType.objects.get(val=NameOriginType._DEFAULT[0])) + # combine with user data: + pf = PersonForm(request.POST, instance=person) + pf.model = person + nf = NameFormFromPerson(request.POST, instance=name) + nf.model = name + sf = SurnameForm(request.POST, instance=surname) + # check if valid: + if nf.is_valid() and pf.is_valid() and sf.is_valid(): + # name.preferred and surname.primary get set False in the above is_valid() + person = pf.save() + # Process data: + name.person = person + name = nf.save(commit=False) + # 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? + check_preferred(name, person) + 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" % person.handle) + else: + # need to edit again + if handle: + action = "edit" + else: + action = "add" + else: # error? + raise Http404(_("Requested %s does not exist.") % "person") + else: # not authenticated + # BEGIN NON-AUTHENTICATED ACCESS + try: + person = Person.objects.get(handle=handle) + except: + raise Http404(_("Requested %s does not exist.") % "person") + if person.private: + raise Http404(_("Requested %s does not exist.") % "person") + pf, nf, sf, person = get_person_forms(handle, protect=True) + # END NON-AUTHENTICATED ACCESS + context["action"] = action + context["view"] = "person" + context["tview"] = _("Person") + context["tviews"] = _("People") + context["personform"] = pf + context["nameform"] = nf + context["surnameform"] = sf + context["person"] = person + context["object"] = person + context["next"] = "/person/%s" % person.handle + diff --git a/src/webapp/grampsdb/view/repository.py b/src/webapp/grampsdb/view/repository.py new file mode 100644 index 000000000..f783c4c9c --- /dev/null +++ b/src/webapp/grampsdb/view/repository.py @@ -0,0 +1,128 @@ +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2009 Douglas S. Blank +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# $Id: utils.py 19637 2012-05-24 17:22:14Z dsblank $ +# + +""" Views for Person, Name, and Surname """ + +## Gramps Modules +from webapp.utils import _, boolean +from webapp.grampsdb.models import Repository +from webapp.grampsdb.forms import * +from webapp.libdjango import DjangoInterface + +## Django Modules +from django.shortcuts import get_object_or_404, render_to_response, redirect +from django.template import Context, RequestContext + +## Globals +dji = DjangoInterface() + +def process_repository(request, context, handle, action): # view, edit, save + """ + Process action on person. Can return a redirect. + """ + context["tview"] = _("Repository") + context["tviews"] = _("Repositories") + context["action"] = "view" + context["object"] = Repository() + view_template = "view_repository_detail.html" + + return render_to_response(view_template, context) + if request.user.is_authenticated(): + if action in ["edit", "view"]: + pf, nf, sf, person = get_person_forms(handle, empty=False) + elif action == "add": + pf, nf, sf, person = get_person_forms(handle=None, protect=False, empty=True) + elif action == "delete": + pf, nf, sf, person = get_person_forms(handle, protect=False, empty=True) + person.delete() + return redirect("/person/") + elif action in ["save", "create"]: # could be create a new person + # look up old data, if any: + if handle: + person = Person.objects.get(handle=handle) + name = person.name_set.get(preferred=True) + surname = name.surname_set.get(primary=True) + else: # create new item + person = Person(handle=create_id()) + name = Name(person=person, preferred=True) + surname = Surname(name=name, primary=True, order=1) + surname = Surname(name=name, + primary=True, + order=1, + name_origin_type=NameOriginType.objects.get(val=NameOriginType._DEFAULT[0])) + # combine with user data: + pf = PersonForm(request.POST, instance=person) + pf.model = person + nf = NameFormFromPerson(request.POST, instance=name) + nf.model = name + sf = SurnameForm(request.POST, instance=surname) + # check if valid: + if nf.is_valid() and pf.is_valid() and sf.is_valid(): + # name.preferred and surname.primary get set False in the above is_valid() + person = pf.save() + # Process data: + name.person = person + name = nf.save(commit=False) + # 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? + check_preferred(name, person) + 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" % person.handle) + else: + # need to edit again + if handle: + action = "edit" + else: + action = "add" + else: # error? + raise Http404(_("Requested %s does not exist.") % "person") + else: # not authenticated + # BEGIN NON-AUTHENTICATED ACCESS + try: + person = Person.objects.get(handle=handle) + except: + raise Http404(_("Requested %s does not exist.") % "person") + if person.private: + raise Http404(_("Requested %s does not exist.") % "person") + pf, nf, sf, person = get_person_forms(handle, protect=True) + # END NON-AUTHENTICATED ACCESS + context["action"] = action + context["view"] = "person" + context["tview"] = _("Person") + context["tviews"] = _("People") + context["personform"] = pf + context["nameform"] = nf + context["surnameform"] = sf + context["person"] = person + context["object"] = person + context["next"] = "/person/%s" % person.handle + diff --git a/src/webapp/grampsdb/view/source.py b/src/webapp/grampsdb/view/source.py new file mode 100644 index 000000000..91d96774a --- /dev/null +++ b/src/webapp/grampsdb/view/source.py @@ -0,0 +1,129 @@ +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2009 Douglas S. Blank +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# $Id: utils.py 19637 2012-05-24 17:22:14Z dsblank $ +# + +""" Views for Person, Name, and Surname """ + +## Gramps Modules +from webapp.utils import _, boolean +from webapp.grampsdb.models import Source +from webapp.grampsdb.forms import * +from webapp.libdjango import DjangoInterface + +## Django Modules +from django.shortcuts import get_object_or_404, render_to_response, redirect +from django.template import Context, RequestContext + +## Globals +dji = DjangoInterface() + +def process_source(request, context, handle, action): # view, edit, save + """ + Process action on person. Can return a redirect. + """ + context["tview"] = _("Source") + context["tviews"] = _("Sources") + context["action"] = "view" + context["object"] = Source() + view_template = "view_source_detail.html" + + return render_to_response(view_template, context) + + if request.user.is_authenticated(): + if action in ["edit", "view"]: + pf, nf, sf, person = get_person_forms(handle, empty=False) + elif action == "add": + pf, nf, sf, person = get_person_forms(handle=None, protect=False, empty=True) + elif action == "delete": + pf, nf, sf, person = get_person_forms(handle, protect=False, empty=True) + person.delete() + return redirect("/person/") + elif action in ["save", "create"]: # could be create a new person + # look up old data, if any: + if handle: + person = Person.objects.get(handle=handle) + name = person.name_set.get(preferred=True) + surname = name.surname_set.get(primary=True) + else: # create new item + person = Person(handle=create_id()) + name = Name(person=person, preferred=True) + surname = Surname(name=name, primary=True, order=1) + surname = Surname(name=name, + primary=True, + order=1, + name_origin_type=NameOriginType.objects.get(val=NameOriginType._DEFAULT[0])) + # combine with user data: + pf = PersonForm(request.POST, instance=person) + pf.model = person + nf = NameFormFromPerson(request.POST, instance=name) + nf.model = name + sf = SurnameForm(request.POST, instance=surname) + # check if valid: + if nf.is_valid() and pf.is_valid() and sf.is_valid(): + # name.preferred and surname.primary get set False in the above is_valid() + person = pf.save() + # Process data: + name.person = person + name = nf.save(commit=False) + # 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? + check_preferred(name, person) + 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" % person.handle) + else: + # need to edit again + if handle: + action = "edit" + else: + action = "add" + else: # error? + raise Http404(_("Requested %s does not exist.") % "person") + else: # not authenticated + # BEGIN NON-AUTHENTICATED ACCESS + try: + person = Person.objects.get(handle=handle) + except: + raise Http404(_("Requested %s does not exist.") % "person") + if person.private: + raise Http404(_("Requested %s does not exist.") % "person") + pf, nf, sf, person = get_person_forms(handle, protect=True) + # END NON-AUTHENTICATED ACCESS + context["action"] = action + context["view"] = "person" + context["tview"] = _("Person") + context["tviews"] = _("People") + context["personform"] = pf + context["nameform"] = nf + context["surnameform"] = sf + context["person"] = person + context["object"] = person + context["next"] = "/person/%s" % person.handle + diff --git a/src/webapp/grampsdb/view/tag.py b/src/webapp/grampsdb/view/tag.py new file mode 100644 index 000000000..13e3f3515 --- /dev/null +++ b/src/webapp/grampsdb/view/tag.py @@ -0,0 +1,129 @@ +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2009 Douglas S. Blank +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# $Id: utils.py 19637 2012-05-24 17:22:14Z dsblank $ +# + +""" Views for Person, Name, and Surname """ + +## Gramps Modules +from webapp.utils import _, boolean +from webapp.grampsdb.models import Tag +from webapp.grampsdb.forms import * +from webapp.libdjango import DjangoInterface + +## Django Modules +from django.shortcuts import get_object_or_404, render_to_response, redirect +from django.template import Context, RequestContext + +## Globals +dji = DjangoInterface() + +def process_tag(request, context, handle, action): # view, edit, save + """ + Process action on person. Can return a redirect. + """ + context["tview"] = _("Tag") + context["tviews"] = _("Tags") + context["action"] = "view" + context["object"] = Tag() + view_template = "view_tag_detail.html" + + return render_to_response(view_template, context) + + if request.user.is_authenticated(): + if action in ["edit", "view"]: + pf, nf, sf, person = get_person_forms(handle, empty=False) + elif action == "add": + pf, nf, sf, person = get_person_forms(handle=None, protect=False, empty=True) + elif action == "delete": + pf, nf, sf, person = get_person_forms(handle, protect=False, empty=True) + person.delete() + return redirect("/person/") + elif action in ["save", "create"]: # could be create a new person + # look up old data, if any: + if handle: + person = Person.objects.get(handle=handle) + name = person.name_set.get(preferred=True) + surname = name.surname_set.get(primary=True) + else: # create new item + person = Person(handle=create_id()) + name = Name(person=person, preferred=True) + surname = Surname(name=name, primary=True, order=1) + surname = Surname(name=name, + primary=True, + order=1, + name_origin_type=NameOriginType.objects.get(val=NameOriginType._DEFAULT[0])) + # combine with user data: + pf = PersonForm(request.POST, instance=person) + pf.model = person + nf = NameFormFromPerson(request.POST, instance=name) + nf.model = name + sf = SurnameForm(request.POST, instance=surname) + # check if valid: + if nf.is_valid() and pf.is_valid() and sf.is_valid(): + # name.preferred and surname.primary get set False in the above is_valid() + person = pf.save() + # Process data: + name.person = person + name = nf.save(commit=False) + # 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? + check_preferred(name, person) + 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" % person.handle) + else: + # need to edit again + if handle: + action = "edit" + else: + action = "add" + else: # error? + raise Http404(_("Requested %s does not exist.") % "person") + else: # not authenticated + # BEGIN NON-AUTHENTICATED ACCESS + try: + person = Person.objects.get(handle=handle) + except: + raise Http404(_("Requested %s does not exist.") % "person") + if person.private: + raise Http404(_("Requested %s does not exist.") % "person") + pf, nf, sf, person = get_person_forms(handle, protect=True) + # END NON-AUTHENTICATED ACCESS + context["action"] = action + context["view"] = "person" + context["tview"] = _("Person") + context["tviews"] = _("People") + context["personform"] = pf + context["nameform"] = nf + context["surnameform"] = sf + context["person"] = person + context["object"] = person + context["next"] = "/person/%s" % person.handle + diff --git a/src/webapp/grampsdb/views.py b/src/webapp/grampsdb/views.py index 78e17f049..21eb81c99 100644 --- a/src/webapp/grampsdb/views.py +++ b/src/webapp/grampsdb/views.py @@ -53,20 +53,15 @@ from django.db.models import Q # #------------------------------------------------------------------------ import webapp +from webapp.utils import _ from webapp.grampsdb.models import * -from webapp.grampsdb.forms import * +from webapp.grampsdb.view import * from webapp.dbdjango import DbDjango -from webapp.libdjango import DjangoInterface import cli.user - -dji = DjangoInterface() - import gen.proxy from Utils import create_id import const -_ = lambda text: text - # Menu: (, //, | None, Need authentication ) MENU = [ (_('Browse'), 'browse', None, False), @@ -156,310 +151,6 @@ def user_page(request, username=None): else: raise Http404(_("Requested page is not accessible.")) -def set_date(obj): - """ - Initial a date object to default. - """ - obj.calendar = 0 - obj.modifier = 0 - obj.quality = 0 - obj.text = "" - obj.sortval = 0 - obj.newyear = 0 - 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 check_order(person): - """ - Check for proper ordering 1..., and for a preferred name. - """ - order = 1 - preferred = False - for name in person.name_set.all().order_by("order"): - if name.preferred: - preferred = True - if name.order != order: - name.order = order - name.save() - order += 1 - if not preferred: - name = person.name_set.get(order=1) - name.preferred = True - name.save() - -def check_primary(surname, surnames): - """ - Check for a proper primary surname. - """ - if surname.primary: - # then all rest should not be: - for s in surnames: - if s.primary: - s.primary = False - s.save() - else: - # then one of them should be - ok = False - for s in surnames: - if s.id != surname.id: - if s.primary: - ok = True - break - else: - s.primary = False - s.save() - ok = True - break - if not ok: - name.primary = True - -def check_preferred(name, person): - """ - Check for a proper preferred name. - """ - names = [] - if person: - names = person.name_set.all() - if name.preferred: - # then all reast should not be: - for s in names: - if s.preferred and s.id != name.id: - s.preferred = False - s.save() - else: - # then one of them should be - ok = False - for s in names: - if s.id != name.id: - if s.preferred: - ok = True - break - else: - s.preferred = False - s.save() - ok = True - break - if not ok: - name.preferred = True - -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] - - if sorder == "add": - action = "add" - if request.POST.has_key("action"): - action = request.POST.get("action") - - person = Person.objects.get(handle=handle) - name = person.name_set.get(order=order) - - if action in ["view", "edit"]: - surname = name.surname_set.get(order=sorder) - if action == "edit": - surname.prefix = make_empty(True, surname.prefix, " prefix ") - elif action in ["delete"]: - surnames = name.surname_set.all().order_by("order") - if len(surnames) > 1: - neworder = 1 - for surname in surnames: - if surname.order != neworder: - surname.order = neworder - surname.save() - neworder += 1 - elif surname.order == int(sorder): - surname.delete() - else: - neworder += 1 - else: - request.user.message_set.create(message="You can't delete the only surname") - return redirect("/person/%s/name/%s" % (person.handle, name.order)) - elif action in ["add"]: - surname = Surname(name=name, primary=False, - name_origin_type=NameOriginType.objects.get(val=NameOriginType._DEFAULT[0])) - surname.prefix = make_empty(True, surname.prefix, " prefix ") - elif action == "create": - surnames = name.surname_set.all().order_by("order") - sorder = 1 - for surname in surnames: - if surname.order != sorder: - surname.order = sorder - surname.save() - sorder += 1 - surname = Surname(name=name, primary=True, - name_origin_type=NameOriginType.objects.get(val=NameOriginType._DEFAULT[0]), - order=sorder) - sf = SurnameForm(request.POST, instance=surname) - sf.model = surname - if sf.is_valid(): - surname.prefix = ssf.cleaned_data["prefix"] if sf.cleaned_data["prefix"] != " prefix " else "" - surname = sf.save(commit=False) - check_primary(surname, surnames) - return redirect("/person/%s/name/%s/surname/%s" % - (person.handle, name.order, sorder)) - action = "edit" - surname.prefix = make_empty(True, surname.prefix, " prefix ") - elif action == "save": - surname = name.surname_set.get(order=sorder) - sf = SurnameForm(request.POST, instance=surname) - sf.model = surname - if sf.is_valid(): - surname.prefix = ssf.cleaned_data["prefix"] if sf.cleaned_data["prefix"] != " prefix " else "" - surname = sf.save(commit=False) - check_primary(surname, name.surname_set.all().exclude(order=surname.order)) - surname.save() - return redirect("/person/%s/name/%s/surname/%s" % - (person.handle, name.order, sorder)) - action = "edit" - surname.prefix = make_empty(True, surname.prefix, " prefix ") - # else, edit again - else: - raise - - sf = SurnameForm(instance=surname) - sf.model = surname - - context = RequestContext(request) - context["action"] = action - context["tview"] = _("Surname") - context["handle"] = handle - context["id"] = id - context["person"] = person - context["object"] = person - context["surnameform"] = sf - context["order"] = name.order - context["sorder"] = sorder - view_template = 'view_surname_detail.html' - return render_to_response(view_template, context) - -def process_name(request, handle, order, action="view"): - if order == "add": - action = "add" - if request.POST.has_key("action"): - action = request.POST.get("action") - ### Process action: - if action == "view": - pf, nf, sf, person = get_person_forms(handle, order=order) - name = nf.model - elif action == "edit": - pf, nf, sf, person = get_person_forms(handle, order=order) - name = nf.model - elif action == "delete": - person = Person.objects.get(handle=handle) - name = person.name_set.filter(order=order) - names = person.name_set.all() - if len(names) > 1: - name.delete() - check_order(person) - else: - request.user.message_set.create(message = "Can't delete only name.") - return redirect("/person/%s" % person.handle) - elif action == "add": # add name - person = Person.objects.get(handle=handle) - name = Name(person=person, - preferred=False, - 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, - name_origin_type=NameOriginType.objects.get(val=NameOriginType._DEFAULT[0])) - sf = SurnameForm(request.POST, instance=surname) - elif action == "create": - # make new data - person = Person.objects.get(handle=handle) - name = Name(preferred=False) - next_order = max([name.order for name in person.name_set.all()]) + 1 - surname = Surname(name=name, - primary=True, - order=next_order, - name_origin_type=NameOriginType.objects.get(val=NameOriginType._DEFAULT[0])) - # combine with user data: - nf = NameForm(request.POST, instance=name) - name.id = None # FIXME: why did this get set to an existing name? Should be new. - name.preferred = False - nf.model = name - sf = SurnameForm(request.POST, instance=surname) - sf.model = 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: - name = nf.save(commit=False) - name.person = person - # Manually set any data: - name.suffix = nf.cleaned_data["suffix"] if nf.cleaned_data["suffix"] != " suffix " else "" - name.preferred = False # FIXME: why is this False? - name.order = next_order - name.save() - # Process data: - surname = sf.save(commit=False) - surname.name = name - # 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 = "add" - elif action == "save": - # look up old data: - person = Person.objects.get(handle=handle) - oldname = person.name_set.get(order=order) - oldsurname = 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=oldsurname) - 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? - check_preferred(name, person) - name.save() - # Process data: - oldsurname.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" - context = RequestContext(request) - context["action"] = action - context["tview"] = _('Name') - context["tviews"] = _('Names') - context["view"] = 'name' - context["handle"] = handle - context["id"] = id - context["person"] = person - context["object"] = person - context["nameform"] = nf - context["surnameform"] = sf - context["order"] = order - context["next"] = "/person/%s/name/%d" % (person.handle, name.order) - view_template = "view_name_detail.html" - return render_to_response(view_template, context) - def send_file(request, filename, mimetype): """ Send a file through Django without loading the whole file into @@ -861,33 +552,37 @@ def action(request, view, handle, action): context["view"] = view context["tview"] = _('Browse') if view == "event": - try: - obj = Event.objects.get(handle=handle) - except: - raise Http404(_("Requested %s does not exist.") % view) + if action not in ["add", "create"]: + try: + obj = Event.objects.get(handle=handle) + except: + raise Http404(_("Requested %s does not exist.") % view) if not check_access(request, context, obj, action): raise Http404(_("Requested %s does not exist.") % view) view_template = 'view_event_detail.html' rd = process_event(request, context, handle, action) elif view == "family": - try: - obj = Family.objects.get(handle=handle) - except: - raise Http404(_("Requested %s does not exist.") % view) + if action not in ["add", "create"]: + try: + obj = Family.objects.get(handle=handle) + except: + raise Http404(_("Requested %s does not exist.") % view) view_template = 'view_family_detail.html' rd = process_family(request, context, handle, action) elif view == "media": - try: - obj = Media.objects.get(handle=handle) - except: - raise Http404(_("Requested %s does not exist.") % view) + if action not in ["add", "create"]: + try: + obj = Media.objects.get(handle=handle) + except: + raise Http404(_("Requested %s does not exist.") % view) view_template = 'view_media_detail.html' rd = process_media(request, context, handle, action) elif view == "note": - try: - obj = Note.objects.get(handle=handle) - except: - raise Http404(_("Requested %s does not exist.") % view) + if action not in ["add", "create"]: + try: + obj = Note.objects.get(handle=handle) + except: + raise Http404(_("Requested %s does not exist.") % view) view_template = 'view_note_detail.html' rd = process_note(request, context, handle, action) elif view == "person": @@ -899,45 +594,51 @@ def action(request, view, handle, action): view_template = 'view_person_detail.html' rd = process_person(request, context, handle, action) elif view == "place": - try: - obj = Place.objects.get(handle=handle) - except: - raise Http404(_("Requested %s does not exist.") % view) + if action not in ["add", "create"]: + try: + obj = Place.objects.get(handle=handle) + except: + raise Http404(_("Requested %s does not exist.") % view) view_template = 'view_place_detail.html' rd = process_place(request, context, handle, action) elif view == "repository": - try: - obj = Repository.objects.get(handle=handle) - except: - raise Http404(_("Requested %s does not exist.") % view) + if action not in ["add", "create"]: + try: + obj = Repository.objects.get(handle=handle) + except: + raise Http404(_("Requested %s does not exist.") % view) view_template = 'view_repository_detail.html' rd = process_repository(request, context, handle, action) elif view == "citation": - try: - obj = Citation.objects.get(handle=handle) - except: - raise Http404(_("Requested %s does not exist.") % view) + if action not in ["add", "create"]: + try: + obj = Citation.objects.get(handle=handle) + except: + raise Http404(_("Requested %s does not exist.") % view) view_template = 'view_citation_detail.html' rd = process_citation(request, context, handle, action) elif view == "source": - try: - obj = Source.objects.get(handle=handle) - except: - raise Http404(_("Requested %s does not exist.") % view) + if action not in ["add", "create"]: + try: + obj = Source.objects.get(handle=handle) + except: + raise Http404(_("Requested %s does not exist.") % view) view_template = 'view_source_detail.html' rd = process_source(request, context, handle, action) elif view == "tag": - try: - obj = Tag.objects.get(handle=handle) - except: - raise Http404(_("Requested %s does not exist.") % view) + if action not in ["add", "create"]: + try: + obj = Tag.objects.get(handle=handle) + except: + raise Http404(_("Requested %s does not exist.") % view) view_template = 'view_tag_detail.html' rd = process_tag(request, context, handle, action) elif view == "report": - try: - obj = Report.objects.get(handle=handle) - except: - raise Http404(_("Requested %s does not exist.") % view) + if action not in ["add", "create"]: + try: + obj = Report.objects.get(handle=handle) + except: + raise Http404(_("Requested %s does not exist.") % view) view_template = 'view_report_detail.html' rd = process_report(request, context, handle, action) else: @@ -950,69 +651,6 @@ def action(request, view, handle, action): context["next"] = "/%s/%s" % (view, obj.handle) return render_to_response(view_template, context) -def process_event(request, context, handle, action): - """ - Process action on event. Can return a redirect. - """ - context["tview"] = _("Event") - context["tviews"] = _("Events") - -def process_family(request, context, handle, action): - """ - Process action on family. Can return a redirect. - """ - context["tview"] = _("Family") - context["tviews"] = _("Families") - -def process_media(request, context, handle, action): - """ - Process action on media. Can return a redirect. - """ - context["tview"] = _("Media") - context["tviews"] = _("Media") - -def process_note(request, context, handle, action): - """ - Process action on note. Can return a redirect. - """ - context["tview"] = _("Note") - context["tviews"] = _("Notes") - -def process_place(request, context, handle, action): - """ - Process action on place. Can return a redirect. - """ - context["tview"] = _("Place") - context["tviews"] = _("Places") - -def process_repository(request, context, handle, action): - """ - Process action on repository. Can return a redirect. - """ - context["tview"] = _("Repository") - context["tviews"] = _("Repositories") - -def process_citation(request, context, handle, action): - """ - Process action on citation. Can return a redirect. - """ - context["tview"] = _("Citation") - context["tviews"] = _("Citations") - -def process_source(request, context, handle, action): - """ - Process action on source. Can return a redirect. - """ - context["tview"] = _("Source") - context["tviews"] = _("Sources") - -def process_tag(request, context, handle, action): - """ - Process action on tag. Can return a redirect. - """ - context["tview"] = _("Tag") - context["tviews"] = _("Tags") - def process_report(request, context, handle, action): """ Process action on report. Can return a redirect. @@ -1022,161 +660,28 @@ def process_report(request, context, handle, action): context["tview"] = _("Report") context["tviews"] = _("Reports") -def process_person(request, context, handle, action): # view, edit, save - """ - Process action on person. Can return a redirect. - """ - context["tview"] = _("Person") - context["tviews"] = _("People") - if request.user.is_authenticated(): - if action in ["edit", "view"]: - pf, nf, sf, person = get_person_forms(handle, empty=False) - elif action == "add": - pf, nf, sf, person = get_person_forms(handle=None, protect=False, empty=True) - elif action == "delete": - pf, nf, sf, person = get_person_forms(handle, protect=False, empty=True) - person.delete() - return redirect("/person/") - elif action in ["save", "create"]: # could be create a new person - # look up old data, if any: - if handle: - person = Person.objects.get(handle=handle) - name = person.name_set.get(preferred=True) - surname = name.surname_set.get(primary=True) - else: # create new item - person = Person(handle=create_id()) - name = Name(person=person, preferred=True) - surname = Surname(name=name, primary=True, order=1) - surname = Surname(name=name, - primary=True, - order=1, - name_origin_type=NameOriginType.objects.get(val=NameOriginType._DEFAULT[0])) - # combine with user data: - pf = PersonForm(request.POST, instance=person) - pf.model = person - nf = NameFormFromPerson(request.POST, instance=name) - nf.model = name - sf = SurnameForm(request.POST, instance=surname) - # check if valid: - if nf.is_valid() and pf.is_valid() and sf.is_valid(): - # name.preferred and surname.primary get set False in the above is_valid() - person = pf.save() - # Process data: - name.person = person - name = nf.save(commit=False) - # 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? - check_preferred(name, person) - 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" % person.handle) - else: - # need to edit again - if handle: - action = "edit" - else: - action = "add" - else: # error? - raise Http404(_("Requested %s does not exist.") % "person") - else: # not authenticated - # BEGIN NON-AUTHENTICATED ACCESS - try: - person = Person.objects.get(handle=handle) - except: - raise Http404(_("Requested %s does not exist.") % "person") - if person.private: - raise Http404(_("Requested %s does not exist.") % "person") - pf, nf, sf, person = get_person_forms(handle, protect=True) - # END NON-AUTHENTICATED ACCESS - context["action"] = action - context["view"] = "person" - context["tview"] = _("Person") - context["tviews"] = _("People") - context["personform"] = pf - context["nameform"] = nf - context["surnameform"] = sf - context["person"] = person - context["object"] = person - context["next"] = "/person/%s" % person.handle - -def get_person_forms(handle, protect=False, empty=False, order=None): - if handle: - person = Person.objects.get(handle=handle) - else: - person = Person() - #person.gramps_id = "I0000" # FIXME: get next ID - ## get a name - name = None - if order is not None: - try: - name = person.name_set.get(order=order) - except: - pass - if name is None: - try: - name = person.name_set.get(preferred=True) - except: - name = Name(person=person, preferred=True, - 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, - name_origin_type=NameOriginType.objects.get(val=NameOriginType._DEFAULT[0]), - order=1) - - if protect and person.probably_alive: - name.sanitize() - pf = PersonForm(instance=person) - pf.model = person - name.suffix = make_empty(empty, name.suffix, " suffix ") - nf = NameForm(instance=name) - nf.model = name - 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: - return value - elif empty: - return empty_value - else: - return value - -def boolean(s): - return s.lower() in ["true", "1", "yes", "y", "t"] - def build_person_query(search, protect): if "," in search or "=" in search: query = Q() terms = ["surname", "given"] for term in [term.strip() for term in search.split(",")]: if "=" in term: - field, value = term.split("=") + field, value = [s.strip() for s in term.split("=")] else: field = terms.pop(0) value = term - if field == "surname": + if "." in field: + query &= Q(**{field.replace(".", "__"): value}) + elif field == "surname": query &= Q(surname__surname__istartswith=value) elif field == "given": query &= Q(first_name__istartswith=value) elif field == "private": query &= Q(person__private=boolean(value)) + elif field == "birth": + query &= Q(person__birth__year1=value) + elif field == "death": + query &= Q(person__death__year1=value) else: query = (Q(surname__surname__icontains=search) | Q(first_name__icontains=search) | diff --git a/src/webapp/utils.py b/src/webapp/utils.py index e4a23c14c..4b356d701 100644 --- a/src/webapp/utils.py +++ b/src/webapp/utils.py @@ -298,13 +298,11 @@ def surname_table(obj, user, action, url=None, *args): name = None if name: links = [] - count = 1 - for surname in name.surname_set.all(): - table.row(str(count), surname.surname) + for surname in name.surname_set.all().order_by("order"): + table.row(str(surname.order), surname.surname) links.append(('URL', # url is "/person/%s/name/%s/surname" - (url % args) + ("/%s" % count))) - count += 1 + (url % args) + ("/%s" % surname.order))) table.links(links) retval += table.get_html() else: @@ -715,6 +713,9 @@ def person_get_event(person, event_type=None): for event_handle in event_ref_list] return [j for i in retval for j in i] +def boolean(s): + return s.lower() in ["true", "1", "yes", "y", "t"] + register_plugins() # works after registering plugins: