Notes completed

svn: r19655
This commit is contained in:
Doug Blank
2012-05-26 03:10:55 +00:00
parent ba9c607ae9
commit c2e5e1741b
7 changed files with 103 additions and 102 deletions

View File

@@ -157,3 +157,9 @@ class EventForm(forms.ModelForm):
text = forms.CharField(label="Date",
required=False,
widget=TextInput(attrs={'size':'45'}))
class NoteForm(forms.ModelForm):
class Meta:
model = Note
exclude = ["handle"]

View File

@@ -111,6 +111,8 @@ register.filter('person_get_events', person_get_event)
def preview(text, width=40):
text = text.replace("\n", " ")
#return escape(text[:width])
if len(text) > width:
return text[:width] + "..."
return text
#preview.is_safe = True
register.filter('preview', preview)

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 Note
from webapp.grampsdb.forms import *
from webapp.libdjango import DjangoInterface
@@ -41,88 +41,54 @@ def process_note(request, context, handle, action): # view, edit, save
context["tview"] = _("Note")
context["tviews"] = _("Notes")
context["action"] = "view"
context["object"] = Note()
view_template = "view_note_detail.html"
if handle == "add":
action = "add"
if request.POST.has_key("action"):
action = request.POST.get("action")
# Handle: edit, view, add, create, save, delete
if action == "add":
note = Note()
noteform = NoteForm(instance=note)
noteform.model = note
elif action in ["view", "edit"]:
note = Note.objects.get(handle=handle)
noteform = NoteForm(instance=note)
noteform.model = note
elif action == "save":
note = Note.objects.get(handle=handle)
noteform = NoteForm(request.POST, instance=note)
noteform.model = note
if noteform.is_valid():
update_last_changed(note, request.user.username)
note = noteform.save()
dji.rebuild_cache(note)
action = "view"
else:
action = "edit"
elif action == "create":
note = Note(handle=create_id())
noteform = NoteForm(request.POST, instance=note)
noteform.model = note
if noteform.is_valid():
update_last_changed(note, request.user.username)
note = noteform.save()
dji.rebuild_cache(note)
action = "view"
else:
action = "add"
elif action == "delete":
note = Note.objects.get(handle=handle)
note.delete()
return redirect("/note/")
else:
raise Exception("Unhandled action: '%s'" % action)
context["noteform"] = noteform
context["object"] = note
context["note"] = note
context["action"] = action
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