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

@ -78,7 +78,7 @@
<input type="hidden" name="action" value="create"/>
<input type="submit" value="Create"/>
{% else %}
{% make_button "Back to Families" "/event" %}
{% make_button "Back to Events" "/event" %}
{% make_button "Add Event" "/event/add" %}
{% make_button "Edit Event" "/event/%s/edit" event.handle %}
{% make_button "Delete Event" "/event/%s/delete" event.handle %}

View File

@ -17,18 +17,32 @@
<div id="summaryarea">
<table class="infolist" style="width:90%;">
<tbody>
{% if noteform.errors %}
<hr>
<p id="error">The following fields have errors. Please correct and try again.</p>
<div id="error">{{noteform.errors}}</div>
<hr>
{% endif %}
<form method="post">{% csrf_token %}
<tr>
<td class="ColumnAttribute">ID:</td>
<td class="ColumnValue" id="data"> {{note.gramps_id|escape}}</td>
<td class="ColumnAttribute">Marker:</td>
<td class="ColumnValue" id="data" colspan="4">{{note.note_marker_type|escape}}</td>
<td class="ColumnAttribute">{{noteform.gramps_id.label}}:</td>
<td class="ColumnValue" id="data"> {% render noteform.gramps_id user action %}</td>
</tr>
<tr>
<td class="ColumnAttribute">Type:</td>
<td class="ColumnValue" id="data">{{event.description|escape}}</td>
<td class="ColumnAttribute"></td>
<td class="ColumnValue" id="data">Preformatted</td>
<td class="ColumnValue" id="data">Private</td>
<td class="ColumnAttribute">{{noteform.note_type.label}}:</td>
<td class="ColumnValue" id="data">{% render noteform.note_type user action %}</td>
</tr>
<tr>
<td class="ColumnAttribute">{{noteform.text.label}}:</td>
<td class="ColumnValue" id="data">{% render noteform.text user action %}</td>
</tr>
<tr>
<td class="ColumnAttribute">{{noteform.preformatted.label}}:</td>
<td class="ColumnValue" id="data">{% render noteform.preformatted user action %}</td>
</tr>
<tr>
<td class="ColumnAttribute">{{noteform.tags.label}}:</td>
<td class="ColumnValue" id="data" colspan="4">{% render noteform.tags user action %}</td>
</tr>
</table>
@ -36,17 +50,34 @@
<div class="ui-tabs ui-widget ui-widget-content ui-corner-all" id="tabs">
<ul class="ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all">
<li class="ui-state-default ui-corner-top ui-tabs-selected ui-state-active"><a href="#tabs-note">Note</a></li>
<li class="ui-corner-top ui-state-default"><a href="#tabs-references">References</a></li>
</ul>
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom" id="tabs-note">
{{note.text}}
</div>
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tabs-references">
{{note.references.all.to_list}}
</div>
</div>
</div>
</div>
{% if user.is_superuser %}
{% if action == "edit" %}
{% make_button "Back to Note" "/note/%s" note.handle %}
<input type="hidden" name="action" value="save"/>
<input type="submit" value="Save"/>
{% else %}
{% ifequal action "add" %}
{% make_button "Cancel" "/note/" %}
<input type="hidden" name="action" value="create"/>
<input type="submit" value="Create"/>
{% else %}
{% make_button "Back to Notes" "/note" %}
{% make_button "Add Note" "/note/add" %}
{% make_button "Edit Note" "/note/%s/edit" note.handle %}
{% make_button "Delete Note" "/note/%s/delete" note.handle %}
{% endifequal %}
{% endif %}
{% else %}
{% endif %}
</form>
{% endblock %}

View File

@ -20,7 +20,7 @@
<span class="grampsid">[{{note.gramps_id}}]</span></a>
{% if user.is_authenticated %}
<td><a href="/{{view}}/{{note.handle|escape}}">{{note.note_type|escape}}</a>
<td><a href="/{{view}}/{{note.handle|escape}}">{{note.text|preview:40}}</a>
<td><a href="/{{view}}/{{note.handle|escape}}">{{note.text|preview:70}}</a>
{% else %}
<td></td>
<td></td>

View File

@ -1,10 +1,6 @@
{% extends "gramps-base.html" %}
{% load my_tags %}
{% block title %}{{sitename}}: {{tview}} detail {% endblock %}
{% block heading %}{{sitename}}: {{tview}} detail {% endblock %}
{% block content %}
{% endblock %}

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"
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)
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:
# need to edit again
if handle:
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"
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
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)