Fixed bug in clearning cache; added Log to Person edit

svn: r19844
This commit is contained in:
Doug Blank
2012-06-15 02:30:38 +00:00
parent 20fd0256bf
commit 7cdc5ec0c0
4 changed files with 41 additions and 15 deletions

View File

@@ -20,13 +20,14 @@
<div id="summaryarea"> <div id="summaryarea">
<table class="infolist" style="width:90%;"> {% comment %} 5 cols {% endcomment %} <table class="infolist" style="width:90%;"> {% comment %} 5 cols {% endcomment %}
<tbody> <tbody>
{% if personform.errors or nameform.errors or surnameform.errors %} {% if personform.errors or nameform.errors or surnameform.errors or logform.errors %}
<hr> <hr>
<p id="error">The following fields have errors. Please correct and try again.</p> <p id="error">The following fields have errors. Please correct and try again.</p>
<div id="error"> <div id="error">
{{personform.errors}} {{personform.errors}}
{{nameform.errors}} {{nameform.errors}}
{{surnameform.errors}} {{surnameform.errors}}
{{logform.errors}}
</div> </div>
<hr> <hr>
{% endif %} {% endif %}
@@ -131,6 +132,12 @@
</div> </div>
</div> </div>
{% if logform %}
<table>
{{logform.as_table}}
</table>
{% endif %}
{% if user.is_superuser %} {% if user.is_superuser %}
{% if action == "edit" %} {% if action == "edit" %}
{% make_button "Cancel" "/person/%s" person.handle args %} {% make_button "Cancel" "/person/%s" person.handle args %}

View File

@@ -34,7 +34,8 @@ class PersonForm(forms.ModelForm):
class Meta: class Meta:
model = Person model = Person
exclude = ["death", "birth", "handle", "birth_ref_index", 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 NameForm(forms.ModelForm):
class Meta: class Meta:
@@ -125,7 +126,7 @@ class SurnameForm(forms.ModelForm):
class FamilyForm(forms.ModelForm): class FamilyForm(forms.ModelForm):
class Meta: class Meta:
model = Family model = Family
exclude = ["handle"] exclude = ["handle", "cache"]
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(FamilyForm, self).__init__(*args, **kwargs) super(FamilyForm, self).__init__(*args, **kwargs)
@@ -140,7 +141,7 @@ class EventForm(forms.ModelForm):
class Meta: class Meta:
model = Event model = Event
exclude = ["handle", "sortval", "month1", "year1", "day1", exclude = ["handle", "sortval", "month1", "year1", "day1",
"newyear", "calendar", "modifier", "quality"] "newyear", "calendar", "modifier", "quality", "cache"]
def clean(self): def clean(self):
from webapp.utils import dp from webapp.utils import dp
@@ -179,7 +180,7 @@ class MediaForm(forms.ModelForm):
class Meta: class Meta:
model = Media model = Media
exclude = ["handle", "sortval", "month1", "year1", "day1", exclude = ["handle", "sortval", "month1", "year1", "day1",
"newyear", "calendar", "modifier", "quality"] "newyear", "calendar", "modifier", "quality", "cache"]
def clean(self): def clean(self):
from webapp.utils import dp from webapp.utils import dp
@@ -216,7 +217,7 @@ class CitationForm(forms.ModelForm):
class Meta: class Meta:
model = Citation model = Citation
exclude = ["handle", "sortval", "month1", "year1", "day1", exclude = ["handle", "sortval", "month1", "year1", "day1",
"newyear", "calendar", "modifier", "quality"] "newyear", "calendar", "modifier", "quality", "cache"]
def clean(self): def clean(self):
from webapp.utils import dp from webapp.utils import dp
@@ -246,12 +247,12 @@ class CitationForm(forms.ModelForm):
class SourceForm(forms.ModelForm): class SourceForm(forms.ModelForm):
class Meta: class Meta:
model = Source model = Source
exclude = ["handle"] exclude = ["handle", "cache"]
class PlaceForm(forms.ModelForm): class PlaceForm(forms.ModelForm):
class Meta: class Meta:
model = Place model = Place
exclude = ["handle"] exclude = ["handle", "cache"]
title = forms.CharField(label="Title", title = forms.CharField(label="Title",
required=False, required=False,
@@ -266,7 +267,7 @@ class PlaceForm(forms.ModelForm):
class RepositoryForm(forms.ModelForm): class RepositoryForm(forms.ModelForm):
class Meta: class Meta:
model = Repository model = Repository
exclude = ["handle"] exclude = ["handle", "cache"]
name = forms.CharField(label="Name", name = forms.CharField(label="Name",
required=False, required=False,
@@ -285,3 +286,13 @@ class EventRefForm(forms.ModelForm):
class Meta: class Meta:
model = EventRef 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'}))

View File

@@ -845,7 +845,7 @@ class Log(BaseRef):
cache = models.TextField(blank=True, null=True) cache = models.TextField(blank=True, null=True)
def __unicode__(self): def __unicode__(self):
"%s: %s on %s by %s" % (self.log_type, return "%s: %s on %s by %s" % (self.log_type,
self.referenced_by, self.referenced_by,
self.last_changed, self.last_changed,
self.last_changed_by) self.last_changed_by)

View File

@@ -22,7 +22,7 @@
""" Views for Person, Name, and Surname """ """ Views for Person, Name, and Surname """
## Gramps Modules ## 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.models import Person, Name, Surname
from webapp.grampsdb.forms import * from webapp.grampsdb.forms import *
from webapp.libdjango import DjangoInterface 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["tview"] = _("Person")
context["tviews"] = _("People") context["tviews"] = _("People")
logform = None
if request.user.is_authenticated(): if request.user.is_authenticated():
if action in ["edit", "view"]: if action in ["edit", "view"]:
pf, nf, sf, person = get_person_forms(handle, empty=False) pf, nf, sf, person = get_person_forms(handle, empty=False)
if action == "edit":
logform = LogForm()
elif action == "add": elif action == "add":
pf, nf, sf, person = get_person_forms(handle=None, protect=False, empty=True) pf, nf, sf, person = get_person_forms(handle=None, protect=False, empty=True)
logform = LogForm()
elif action == "delete": elif action == "delete":
pf, nf, sf, person = get_person_forms(handle, protect=False, empty=True) pf, nf, sf, person = get_person_forms(handle, protect=False, empty=True)
person.delete() person.delete()
return redirect("/person/%s" % build_search(request)) return redirect("/person/%s" % build_search(request))
elif action in ["save", "create"]: # could be create a new person elif action in ["save", "create"]: # could be create a new person
# look up old data, if any: # look up old data, if any:
logform = LogForm(request.POST)
if handle: if handle:
person = Person.objects.get(handle=handle) person = Person.objects.get(handle=handle)
name = person.name_set.get(preferred=True) 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 = SurnameForm(request.POST, instance=surname)
sf.model = surname sf.model = surname
# check if valid: # 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() # name.preferred and surname.primary get set False in the above is_valid()
person.probably_alive = not bool(person.death) person.probably_alive = not bool(person.death)
update_last_changed(person, request.user.username) 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.prefix = sf.cleaned_data["prefix"] if sf.cleaned_data["prefix"] != " prefix " else ""
surname.primary = True # FIXME: why is this False? Remove from form? surname.primary = True # FIXME: why is this False? Remove from form?
surname.save() 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 if add_to: # Adding a child to the family
item, handle = add_to # ("Family", handle) item, handle = add_to # ("Family", handle)
model = dji.get_model(item) # what model? 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["personform"] = pf
context["nameform"] = nf context["nameform"] = nf
context["surnameform"] = sf context["surnameform"] = sf
context["logform"] = logform
context["person"] = person context["person"] = person
context["object"] = person context["object"] = person
context["next"] = "/person/%s" % person.handle context["next"] = "/person/%s" % person.handle