diff --git a/src/data/templates/view_person_detail.html b/src/data/templates/view_person_detail.html
index b3009bc9b..aa70376f4 100644
--- a/src/data/templates/view_person_detail.html
+++ b/src/data/templates/view_person_detail.html
@@ -20,13 +20,14 @@
{% comment %} 5 cols {% endcomment %}
- {% if personform.errors or nameform.errors or surnameform.errors %}
+ {% if personform.errors or nameform.errors or surnameform.errors or logform.errors %}
The following fields have errors. Please correct and try again.
{{personform.errors}}
{{nameform.errors}}
{{surnameform.errors}}
+ {{logform.errors}}
{% endif %}
@@ -131,6 +132,12 @@
+{% if logform %}
+
+{% endif %}
+
{% if user.is_superuser %}
{% if action == "edit" %}
{% make_button "Cancel" "/person/%s" person.handle args %}
diff --git a/src/webapp/grampsdb/forms.py b/src/webapp/grampsdb/forms.py
index bde965fa7..bf2c53bc4 100644
--- a/src/webapp/grampsdb/forms.py
+++ b/src/webapp/grampsdb/forms.py
@@ -34,7 +34,8 @@ class PersonForm(forms.ModelForm):
class Meta:
model = Person
exclude = ["death", "birth", "handle", "birth_ref_index",
- "death_ref_index", "families", "parent_families"]
+ "death_ref_index", "families", "parent_families",
+ "cache"]
class NameForm(forms.ModelForm):
class Meta:
@@ -125,7 +126,7 @@ class SurnameForm(forms.ModelForm):
class FamilyForm(forms.ModelForm):
class Meta:
model = Family
- exclude = ["handle"]
+ exclude = ["handle", "cache"]
def __init__(self, *args, **kwargs):
super(FamilyForm, self).__init__(*args, **kwargs)
@@ -140,7 +141,7 @@ class EventForm(forms.ModelForm):
class Meta:
model = Event
exclude = ["handle", "sortval", "month1", "year1", "day1",
- "newyear", "calendar", "modifier", "quality"]
+ "newyear", "calendar", "modifier", "quality", "cache"]
def clean(self):
from webapp.utils import dp
@@ -179,7 +180,7 @@ class MediaForm(forms.ModelForm):
class Meta:
model = Media
exclude = ["handle", "sortval", "month1", "year1", "day1",
- "newyear", "calendar", "modifier", "quality"]
+ "newyear", "calendar", "modifier", "quality", "cache"]
def clean(self):
from webapp.utils import dp
@@ -216,7 +217,7 @@ class CitationForm(forms.ModelForm):
class Meta:
model = Citation
exclude = ["handle", "sortval", "month1", "year1", "day1",
- "newyear", "calendar", "modifier", "quality"]
+ "newyear", "calendar", "modifier", "quality", "cache"]
def clean(self):
from webapp.utils import dp
@@ -246,12 +247,12 @@ class CitationForm(forms.ModelForm):
class SourceForm(forms.ModelForm):
class Meta:
model = Source
- exclude = ["handle"]
+ exclude = ["handle", "cache"]
class PlaceForm(forms.ModelForm):
class Meta:
model = Place
- exclude = ["handle"]
+ exclude = ["handle", "cache"]
title = forms.CharField(label="Title",
required=False,
@@ -266,7 +267,7 @@ class PlaceForm(forms.ModelForm):
class RepositoryForm(forms.ModelForm):
class Meta:
model = Repository
- exclude = ["handle"]
+ exclude = ["handle", "cache"]
name = forms.CharField(label="Name",
required=False,
@@ -285,3 +286,13 @@ class EventRefForm(forms.ModelForm):
class Meta:
model = EventRef
+class LogForm(forms.ModelForm):
+ error_css_class = 'error'
+
+ class Meta:
+ model = Log
+ fields = ["reason"]
+
+ reason = forms.CharField(label="Reason for change",
+ widget=forms.widgets.Textarea(attrs={'rows':'2',
+ 'cols': '65'}))
diff --git a/src/webapp/grampsdb/models.py b/src/webapp/grampsdb/models.py
index c86982069..7ca5920e1 100644
--- a/src/webapp/grampsdb/models.py
+++ b/src/webapp/grampsdb/models.py
@@ -845,10 +845,10 @@ class Log(BaseRef):
cache = models.TextField(blank=True, null=True)
def __unicode__(self):
- "%s: %s on %s by %s" % (self.log_type,
- self.referenced_by,
- self.last_changed,
- self.last_changed_by)
+ return "%s: %s on %s by %s" % (self.log_type,
+ self.referenced_by,
+ self.last_changed,
+ self.last_changed_by)
class NoteRef(BaseRef):
ref_object = models.ForeignKey('Note')
diff --git a/src/webapp/grampsdb/view/person.py b/src/webapp/grampsdb/view/person.py
index d1b6f88f3..66e2b810e 100644
--- a/src/webapp/grampsdb/view/person.py
+++ b/src/webapp/grampsdb/view/person.py
@@ -22,7 +22,7 @@
""" Views for Person, Name, and Surname """
## Gramps Modules
-from webapp.utils import _, boolean, update_last_changed, build_search
+from webapp.utils import _, boolean, update_last_changed, build_search, make_log
from webapp.grampsdb.models import Person, Name, Surname
from webapp.grampsdb.forms import *
from webapp.libdjango import DjangoInterface
@@ -342,17 +342,22 @@ def process_person(request, context, handle, action, add_to=None): # view, edit,
"""
context["tview"] = _("Person")
context["tviews"] = _("People")
+ logform = None
if request.user.is_authenticated():
if action in ["edit", "view"]:
pf, nf, sf, person = get_person_forms(handle, empty=False)
+ if action == "edit":
+ logform = LogForm()
elif action == "add":
pf, nf, sf, person = get_person_forms(handle=None, protect=False, empty=True)
+ logform = LogForm()
elif action == "delete":
pf, nf, sf, person = get_person_forms(handle, protect=False, empty=True)
person.delete()
return redirect("/person/%s" % build_search(request))
elif action in ["save", "create"]: # could be create a new person
# look up old data, if any:
+ logform = LogForm(request.POST)
if handle:
person = Person.objects.get(handle=handle)
name = person.name_set.get(preferred=True)
@@ -373,7 +378,7 @@ def process_person(request, context, handle, action, add_to=None): # view, edit,
sf = SurnameForm(request.POST, instance=surname)
sf.model = surname
# check if valid:
- if nf.is_valid() and pf.is_valid() and sf.is_valid():
+ if nf.is_valid() and pf.is_valid() and sf.is_valid() and logform.is_valid():
# name.preferred and surname.primary get set False in the above is_valid()
person.probably_alive = not bool(person.death)
update_last_changed(person, request.user.username)
@@ -394,6 +399,8 @@ def process_person(request, context, handle, action, add_to=None): # view, edit,
surname.prefix = sf.cleaned_data["prefix"] if sf.cleaned_data["prefix"] != " prefix " else ""
surname.primary = True # FIXME: why is this False? Remove from form?
surname.save()
+ # FIXME: put this in correct place to get correct cache, before changes:
+ make_log(person, action, request.user.username, logform.cleaned_data["reason"], person.cache)
if add_to: # Adding a child to the family
item, handle = add_to # ("Family", handle)
model = dji.get_model(item) # what model?
@@ -430,6 +437,7 @@ def process_person(request, context, handle, action, add_to=None): # view, edit,
context["personform"] = pf
context["nameform"] = nf
context["surnameform"] = sf
+ context["logform"] = logform
context["person"] = person
context["object"] = person
context["next"] = "/person/%s" % person.handle