Fixed bug in clearning cache; added Log to Person edit
svn: r19844
This commit is contained in:
parent
20fd0256bf
commit
7cdc5ec0c0
@ -20,13 +20,14 @@
|
||||
<div id="summaryarea">
|
||||
<table class="infolist" style="width:90%;"> {% comment %} 5 cols {% endcomment %}
|
||||
<tbody>
|
||||
{% if personform.errors or nameform.errors or surnameform.errors %}
|
||||
{% if personform.errors or nameform.errors or surnameform.errors or logform.errors %}
|
||||
<hr>
|
||||
<p id="error">The following fields have errors. Please correct and try again.</p>
|
||||
<div id="error">
|
||||
{{personform.errors}}
|
||||
{{nameform.errors}}
|
||||
{{surnameform.errors}}
|
||||
{{logform.errors}}
|
||||
</div>
|
||||
<hr>
|
||||
{% endif %}
|
||||
@ -131,6 +132,12 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% if logform %}
|
||||
<table>
|
||||
{{logform.as_table}}
|
||||
</table>
|
||||
{% endif %}
|
||||
|
||||
{% if user.is_superuser %}
|
||||
{% if action == "edit" %}
|
||||
{% make_button "Cancel" "/person/%s" person.handle args %}
|
||||
|
@ -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'}))
|
||||
|
@ -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')
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user