Updates last_changed, last_changed_by

svn: r19645
This commit is contained in:
Doug Blank 2012-05-25 15:00:39 +00:00
parent cfaee2894a
commit 47cdbffbb6
4 changed files with 25 additions and 89 deletions

View File

@ -22,7 +22,7 @@
""" Views for Person, Name, and Surname """
## Gramps Modules
from webapp.utils import _, boolean
from webapp.utils import _, boolean, update_last_changed
from webapp.grampsdb.models import Family
from webapp.grampsdb.forms import *
from webapp.libdjango import DjangoInterface
@ -62,7 +62,9 @@ def process_family(request, context, handle, action): # view, edit, save
familyform = FamilyForm(request.POST, instance=family)
familyform.model = family
if familyform.is_valid():
familyform.save()
update_last_changed(family, request.user.username)
family = familyform.save()
dji.rebuild_cache(family)
action = "view"
else:
action = "edit"
@ -72,9 +74,10 @@ def process_family(request, context, handle, action): # view, edit, save
handle=create_id())
familyform = FamilyForm(request.POST, instance=family)
familyform.model = family
familyform.handle = create_id()
if familyform.is_valid():
familyform.save()
update_last_changed(family, request.user.username)
family = familyform.save()
dji.rebuild_cache(family)
action = "view"
else:
action = "add"
@ -92,84 +95,3 @@ def process_family(request, context, handle, action): # view, edit, save
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

View File

@ -22,7 +22,7 @@
""" Views for Person, Name, and Surname """
## Gramps Modules
from webapp.utils import _, boolean
from webapp.utils import _, boolean, update_last_changed
from webapp.grampsdb.models import Person, Name, Surname
from webapp.grampsdb.forms import *
from webapp.libdjango import DjangoInterface
@ -35,7 +35,7 @@ from django.template import Context, RequestContext
dji = DjangoInterface()
## Functions
def check_order(person):
def check_order(request, person):
"""
Check for proper ordering 1..., and for a preferred name.
"""
@ -46,11 +46,13 @@ def check_order(person):
preferred = True
if name.order != order:
name.order = order
update_last_changed(name, request.user.username)
name.save()
order += 1
if not preferred:
name = person.name_set.get(order=1)
name.preferred = True
update_last_changed(name, request.user.username)
name.save()
def check_primary(surname, surnames):
@ -91,6 +93,7 @@ def check_preferred(name, person):
for s in names:
if s.preferred and s.id != name.id:
s.preferred = False
update_last_changed(s, request.user.username)
s.save()
else:
# then one of them should be
@ -102,6 +105,7 @@ def check_preferred(name, person):
break
else:
s.preferred = False
update_last_changed(s, request.user.username)
s.save()
ok = True
break
@ -218,7 +222,7 @@ def process_name(request, handle, order, action="view"):
names = person.name_set.all()
if len(names) > 1:
name.delete()
check_order(person)
check_order(request, person)
else:
request.user.message_set.create(message = "Can't delete only name.")
return redirect("/person/%s" % person.handle)
@ -258,6 +262,7 @@ def process_name(request, handle, order, action="view"):
# Process data:
name = nf.save(commit=False)
name.person = person
update_last_changed(name, request.user.username)
# 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?
@ -296,6 +301,7 @@ def process_name(request, handle, order, action="view"):
# 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?
update_last_changed(name, request.user.username)
check_preferred(name, person)
name.save()
# Process data:
@ -365,6 +371,7 @@ def process_person(request, context, handle, action): # view, edit, save
# 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()
update_last_changed(person, request.user.username)
person = pf.save()
# Process data:
name.person = person
@ -373,6 +380,7 @@ def process_person(request, context, handle, action): # view, edit, save
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)
update_last_changed(name, request.user.username)
name.save()
# Process data:
surname.name = name

View File

@ -7,9 +7,10 @@ except RuntimeError:
pass
from webapp.grampsdb.models import *
from webapp.grampsdb.forms import *
from webapp.dbdjango import DbDjango
from webapp.reports import import_file
from webapp.libdjango import DjangoInterface
from webapp.libdjango import DjangoInterface, totime, todate
db = DbDjango()
dji = DjangoInterface()

View File

@ -28,6 +28,7 @@
#------------------------------------------------------------------------
import locale
import sys
import datetime
#------------------------------------------------------------------------
#
@ -722,6 +723,10 @@ def person_get_event(person, event_type=None):
def boolean(s):
return s.lower() in ["true", "1", "yes", "y", "t"]
def update_last_changed(obj, user):
obj.last_changed = datetime.datetime.now()
obj.last_changed_by = user
register_plugins()
# works after registering plugins: